1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2019 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2read.h"
33 #include "dwarf-index-cache.h"
34 #include "dwarf-index-common.h"
43 #include "gdb-demangle.h"
44 #include "filenames.h" /* for DOSish file names */
47 #include "complaints.h"
48 #include "dwarf2expr.h"
49 #include "dwarf2loc.h"
50 #include "cp-support.h"
56 #include "typeprint.h"
61 #include "gdbcore.h" /* for gnutarget */
62 #include "gdb/gdb-index.h"
67 #include "namespace.h"
68 #include "gdbsupport/function-view.h"
69 #include "gdbsupport/gdb_optional.h"
70 #include "gdbsupport/underlying.h"
71 #include "gdbsupport/hash_enum.h"
72 #include "filename-seen-cache.h"
76 #include <unordered_map>
77 #include "gdbsupport/selftest.h"
78 #include "rust-lang.h"
79 #include "gdbsupport/pathstuff.h"
81 /* When == 1, print basic high level tracing messages.
82 When > 1, be more verbose.
83 This is in contrast to the low level DIE reading of dwarf_die_debug. */
84 static unsigned int dwarf_read_debug
= 0;
86 /* When non-zero, dump DIEs after they are read in. */
87 static unsigned int dwarf_die_debug
= 0;
89 /* When non-zero, dump line number entries as they are read in. */
90 static unsigned int dwarf_line_debug
= 0;
92 /* When true, cross-check physname against demangler. */
93 static bool check_physname
= false;
95 /* When true, do not reject deprecated .gdb_index sections. */
96 static bool use_deprecated_index_sections
= false;
98 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
100 /* The "aclass" indices for various kinds of computed DWARF symbols. */
102 static int dwarf2_locexpr_index
;
103 static int dwarf2_loclist_index
;
104 static int dwarf2_locexpr_block_index
;
105 static int dwarf2_loclist_block_index
;
107 /* An index into a (C++) symbol name component in a symbol name as
108 recorded in the mapped_index's symbol table. For each C++ symbol
109 in the symbol table, we record one entry for the start of each
110 component in the symbol in a table of name components, and then
111 sort the table, in order to be able to binary search symbol names,
112 ignoring leading namespaces, both completion and regular look up.
113 For example, for symbol "A::B::C", we'll have an entry that points
114 to "A::B::C", another that points to "B::C", and another for "C".
115 Note that function symbols in GDB index have no parameter
116 information, just the function/method names. You can convert a
117 name_component to a "const char *" using the
118 'mapped_index::symbol_name_at(offset_type)' method. */
120 struct name_component
122 /* Offset in the symbol name where the component starts. Stored as
123 a (32-bit) offset instead of a pointer to save memory and improve
124 locality on 64-bit architectures. */
125 offset_type name_offset
;
127 /* The symbol's index in the symbol and constant pool tables of a
132 /* Base class containing bits shared by both .gdb_index and
133 .debug_name indexes. */
135 struct mapped_index_base
137 mapped_index_base () = default;
138 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
140 /* The name_component table (a sorted vector). See name_component's
141 description above. */
142 std::vector
<name_component
> name_components
;
144 /* How NAME_COMPONENTS is sorted. */
145 enum case_sensitivity name_components_casing
;
147 /* Return the number of names in the symbol table. */
148 virtual size_t symbol_name_count () const = 0;
150 /* Get the name of the symbol at IDX in the symbol table. */
151 virtual const char *symbol_name_at (offset_type idx
) const = 0;
153 /* Return whether the name at IDX in the symbol table should be
155 virtual bool symbol_name_slot_invalid (offset_type idx
) const
160 /* Build the symbol name component sorted vector, if we haven't
162 void build_name_components ();
164 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
165 possible matches for LN_NO_PARAMS in the name component
167 std::pair
<std::vector
<name_component
>::const_iterator
,
168 std::vector
<name_component
>::const_iterator
>
169 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
170 enum language lang
) const;
172 /* Prevent deleting/destroying via a base class pointer. */
174 ~mapped_index_base() = default;
177 /* A description of the mapped index. The file format is described in
178 a comment by the code that writes the index. */
179 struct mapped_index final
: public mapped_index_base
181 /* A slot/bucket in the symbol table hash. */
182 struct symbol_table_slot
184 const offset_type name
;
185 const offset_type vec
;
188 /* Index data format version. */
191 /* The address table data. */
192 gdb::array_view
<const gdb_byte
> address_table
;
194 /* The symbol table, implemented as a hash table. */
195 gdb::array_view
<symbol_table_slot
> symbol_table
;
197 /* A pointer to the constant pool. */
198 const char *constant_pool
= nullptr;
200 bool symbol_name_slot_invalid (offset_type idx
) const override
202 const auto &bucket
= this->symbol_table
[idx
];
203 return bucket
.name
== 0 && bucket
.vec
== 0;
206 /* Convenience method to get at the name of the symbol at IDX in the
208 const char *symbol_name_at (offset_type idx
) const override
209 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
211 size_t symbol_name_count () const override
212 { return this->symbol_table
.size (); }
215 /* A description of the mapped .debug_names.
216 Uninitialized map has CU_COUNT 0. */
217 struct mapped_debug_names final
: public mapped_index_base
219 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
220 : dwarf2_per_objfile (dwarf2_per_objfile_
)
223 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
224 bfd_endian dwarf5_byte_order
;
225 bool dwarf5_is_dwarf64
;
226 bool augmentation_is_gdb
;
228 uint32_t cu_count
= 0;
229 uint32_t tu_count
, bucket_count
, name_count
;
230 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
231 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
232 const gdb_byte
*name_table_string_offs_reordered
;
233 const gdb_byte
*name_table_entry_offs_reordered
;
234 const gdb_byte
*entry_pool
;
241 /* Attribute name DW_IDX_*. */
244 /* Attribute form DW_FORM_*. */
247 /* Value if FORM is DW_FORM_implicit_const. */
248 LONGEST implicit_const
;
250 std::vector
<attr
> attr_vec
;
253 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
255 const char *namei_to_name (uint32_t namei
) const;
257 /* Implementation of the mapped_index_base virtual interface, for
258 the name_components cache. */
260 const char *symbol_name_at (offset_type idx
) const override
261 { return namei_to_name (idx
); }
263 size_t symbol_name_count () const override
264 { return this->name_count
; }
267 /* See dwarf2read.h. */
270 get_dwarf2_per_objfile (struct objfile
*objfile
)
272 return dwarf2_objfile_data_key
.get (objfile
);
275 /* Default names of the debugging sections. */
277 /* Note that if the debugging section has been compressed, it might
278 have a name like .zdebug_info. */
280 static const struct dwarf2_debug_sections dwarf2_elf_names
=
282 { ".debug_info", ".zdebug_info" },
283 { ".debug_abbrev", ".zdebug_abbrev" },
284 { ".debug_line", ".zdebug_line" },
285 { ".debug_loc", ".zdebug_loc" },
286 { ".debug_loclists", ".zdebug_loclists" },
287 { ".debug_macinfo", ".zdebug_macinfo" },
288 { ".debug_macro", ".zdebug_macro" },
289 { ".debug_str", ".zdebug_str" },
290 { ".debug_line_str", ".zdebug_line_str" },
291 { ".debug_ranges", ".zdebug_ranges" },
292 { ".debug_rnglists", ".zdebug_rnglists" },
293 { ".debug_types", ".zdebug_types" },
294 { ".debug_addr", ".zdebug_addr" },
295 { ".debug_frame", ".zdebug_frame" },
296 { ".eh_frame", NULL
},
297 { ".gdb_index", ".zgdb_index" },
298 { ".debug_names", ".zdebug_names" },
299 { ".debug_aranges", ".zdebug_aranges" },
303 /* List of DWO/DWP sections. */
305 static const struct dwop_section_names
307 struct dwarf2_section_names abbrev_dwo
;
308 struct dwarf2_section_names info_dwo
;
309 struct dwarf2_section_names line_dwo
;
310 struct dwarf2_section_names loc_dwo
;
311 struct dwarf2_section_names loclists_dwo
;
312 struct dwarf2_section_names macinfo_dwo
;
313 struct dwarf2_section_names macro_dwo
;
314 struct dwarf2_section_names str_dwo
;
315 struct dwarf2_section_names str_offsets_dwo
;
316 struct dwarf2_section_names types_dwo
;
317 struct dwarf2_section_names cu_index
;
318 struct dwarf2_section_names tu_index
;
322 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
323 { ".debug_info.dwo", ".zdebug_info.dwo" },
324 { ".debug_line.dwo", ".zdebug_line.dwo" },
325 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
326 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
327 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
328 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
329 { ".debug_str.dwo", ".zdebug_str.dwo" },
330 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
331 { ".debug_types.dwo", ".zdebug_types.dwo" },
332 { ".debug_cu_index", ".zdebug_cu_index" },
333 { ".debug_tu_index", ".zdebug_tu_index" },
336 /* local data types */
338 /* The data in a compilation unit header, after target2host
339 translation, looks like this. */
340 struct comp_unit_head
344 unsigned char addr_size
;
345 unsigned char signed_addr_p
;
346 sect_offset abbrev_sect_off
;
348 /* Size of file offsets; either 4 or 8. */
349 unsigned int offset_size
;
351 /* Size of the length field; either 4 or 12. */
352 unsigned int initial_length_size
;
354 enum dwarf_unit_type unit_type
;
356 /* Offset to the first byte of this compilation unit header in the
357 .debug_info section, for resolving relative reference dies. */
358 sect_offset sect_off
;
360 /* Offset to first die in this cu from the start of the cu.
361 This will be the first byte following the compilation unit header. */
362 cu_offset first_die_cu_offset
;
365 /* 64-bit signature of this unit. For type units, it denotes the signature of
366 the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
367 Also used in DWARF 5, to denote the dwo id when the unit type is
368 DW_UT_skeleton or DW_UT_split_compile. */
371 /* For types, offset in the type's DIE of the type defined by this TU. */
372 cu_offset type_cu_offset_in_tu
;
375 /* Type used for delaying computation of method physnames.
376 See comments for compute_delayed_physnames. */
377 struct delayed_method_info
379 /* The type to which the method is attached, i.e., its parent class. */
382 /* The index of the method in the type's function fieldlists. */
385 /* The index of the method in the fieldlist. */
388 /* The name of the DIE. */
391 /* The DIE associated with this method. */
392 struct die_info
*die
;
395 /* Internal state when decoding a particular compilation unit. */
398 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
401 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
403 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
404 Create the set of symtabs used by this TU, or if this TU is sharing
405 symtabs with another TU and the symtabs have already been created
406 then restore those symtabs in the line header.
407 We don't need the pc/line-number mapping for type units. */
408 void setup_type_unit_groups (struct die_info
*die
);
410 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
411 buildsym_compunit constructor. */
412 struct compunit_symtab
*start_symtab (const char *name
,
413 const char *comp_dir
,
416 /* Reset the builder. */
417 void reset_builder () { m_builder
.reset (); }
419 /* The header of the compilation unit. */
420 struct comp_unit_head header
{};
422 /* Base address of this compilation unit. */
423 CORE_ADDR base_address
= 0;
425 /* Non-zero if base_address has been set. */
428 /* The language we are debugging. */
429 enum language language
= language_unknown
;
430 const struct language_defn
*language_defn
= nullptr;
432 const char *producer
= nullptr;
435 /* The symtab builder for this CU. This is only non-NULL when full
436 symbols are being read. */
437 std::unique_ptr
<buildsym_compunit
> m_builder
;
440 /* The generic symbol table building routines have separate lists for
441 file scope symbols and all all other scopes (local scopes). So
442 we need to select the right one to pass to add_symbol_to_list().
443 We do it by keeping a pointer to the correct list in list_in_scope.
445 FIXME: The original dwarf code just treated the file scope as the
446 first local scope, and all other local scopes as nested local
447 scopes, and worked fine. Check to see if we really need to
448 distinguish these in buildsym.c. */
449 struct pending
**list_in_scope
= nullptr;
451 /* Hash table holding all the loaded partial DIEs
452 with partial_die->offset.SECT_OFF as hash. */
453 htab_t partial_dies
= nullptr;
455 /* Storage for things with the same lifetime as this read-in compilation
456 unit, including partial DIEs. */
457 auto_obstack comp_unit_obstack
;
459 /* When multiple dwarf2_cu structures are living in memory, this field
460 chains them all together, so that they can be released efficiently.
461 We will probably also want a generation counter so that most-recently-used
462 compilation units are cached... */
463 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
465 /* Backlink to our per_cu entry. */
466 struct dwarf2_per_cu_data
*per_cu
;
468 /* How many compilation units ago was this CU last referenced? */
471 /* A hash table of DIE cu_offset for following references with
472 die_info->offset.sect_off as hash. */
473 htab_t die_hash
= nullptr;
475 /* Full DIEs if read in. */
476 struct die_info
*dies
= nullptr;
478 /* A set of pointers to dwarf2_per_cu_data objects for compilation
479 units referenced by this one. Only set during full symbol processing;
480 partial symbol tables do not have dependencies. */
481 htab_t dependencies
= nullptr;
483 /* Header data from the line table, during full symbol processing. */
484 struct line_header
*line_header
= nullptr;
485 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
486 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
487 this is the DW_TAG_compile_unit die for this CU. We'll hold on
488 to the line header as long as this DIE is being processed. See
489 process_die_scope. */
490 die_info
*line_header_die_owner
= nullptr;
492 /* A list of methods which need to have physnames computed
493 after all type information has been read. */
494 std::vector
<delayed_method_info
> method_list
;
496 /* To be copied to symtab->call_site_htab. */
497 htab_t call_site_htab
= nullptr;
499 /* Non-NULL if this CU came from a DWO file.
500 There is an invariant here that is important to remember:
501 Except for attributes copied from the top level DIE in the "main"
502 (or "stub") file in preparation for reading the DWO file
503 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
504 Either there isn't a DWO file (in which case this is NULL and the point
505 is moot), or there is and either we're not going to read it (in which
506 case this is NULL) or there is and we are reading it (in which case this
508 struct dwo_unit
*dwo_unit
= nullptr;
510 /* The DW_AT_addr_base attribute if present, zero otherwise
511 (zero is a valid value though).
512 Note this value comes from the Fission stub CU/TU's DIE. */
513 ULONGEST addr_base
= 0;
515 /* The DW_AT_ranges_base attribute if present, zero otherwise
516 (zero is a valid value though).
517 Note this value comes from the Fission stub CU/TU's DIE.
518 Also note that the value is zero in the non-DWO case so this value can
519 be used without needing to know whether DWO files are in use or not.
520 N.B. This does not apply to DW_AT_ranges appearing in
521 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
522 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
523 DW_AT_ranges_base *would* have to be applied, and we'd have to care
524 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
525 ULONGEST ranges_base
= 0;
527 /* When reading debug info generated by older versions of rustc, we
528 have to rewrite some union types to be struct types with a
529 variant part. This rewriting must be done after the CU is fully
530 read in, because otherwise at the point of rewriting some struct
531 type might not have been fully processed. So, we keep a list of
532 all such types here and process them after expansion. */
533 std::vector
<struct type
*> rust_unions
;
535 /* Mark used when releasing cached dies. */
538 /* This CU references .debug_loc. See the symtab->locations_valid field.
539 This test is imperfect as there may exist optimized debug code not using
540 any location list and still facing inlining issues if handled as
541 unoptimized code. For a future better test see GCC PR other/32998. */
542 bool has_loclist
: 1;
544 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
545 if all the producer_is_* fields are valid. This information is cached
546 because profiling CU expansion showed excessive time spent in
547 producer_is_gxx_lt_4_6. */
548 bool checked_producer
: 1;
549 bool producer_is_gxx_lt_4_6
: 1;
550 bool producer_is_gcc_lt_4_3
: 1;
551 bool producer_is_icc
: 1;
552 bool producer_is_icc_lt_14
: 1;
553 bool producer_is_codewarrior
: 1;
555 /* When true, the file that we're processing is known to have
556 debugging info for C++ namespaces. GCC 3.3.x did not produce
557 this information, but later versions do. */
559 bool processing_has_namespace_info
: 1;
561 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
563 /* If this CU was inherited by another CU (via specification,
564 abstract_origin, etc), this is the ancestor CU. */
567 /* Get the buildsym_compunit for this CU. */
568 buildsym_compunit
*get_builder ()
570 /* If this CU has a builder associated with it, use that. */
571 if (m_builder
!= nullptr)
572 return m_builder
.get ();
574 /* Otherwise, search ancestors for a valid builder. */
575 if (ancestor
!= nullptr)
576 return ancestor
->get_builder ();
582 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
583 This includes type_unit_group and quick_file_names. */
585 struct stmt_list_hash
587 /* The DWO unit this table is from or NULL if there is none. */
588 struct dwo_unit
*dwo_unit
;
590 /* Offset in .debug_line or .debug_line.dwo. */
591 sect_offset line_sect_off
;
594 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
595 an object of this type. */
597 struct type_unit_group
599 /* dwarf2read.c's main "handle" on a TU symtab.
600 To simplify things we create an artificial CU that "includes" all the
601 type units using this stmt_list so that the rest of the code still has
602 a "per_cu" handle on the symtab.
603 This PER_CU is recognized by having no section. */
604 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
605 struct dwarf2_per_cu_data per_cu
;
607 /* The TUs that share this DW_AT_stmt_list entry.
608 This is added to while parsing type units to build partial symtabs,
609 and is deleted afterwards and not used again. */
610 std::vector
<signatured_type
*> *tus
;
612 /* The compunit symtab.
613 Type units in a group needn't all be defined in the same source file,
614 so we create an essentially anonymous symtab as the compunit symtab. */
615 struct compunit_symtab
*compunit_symtab
;
617 /* The data used to construct the hash key. */
618 struct stmt_list_hash hash
;
620 /* The number of symtabs from the line header.
621 The value here must match line_header.num_file_names. */
622 unsigned int num_symtabs
;
624 /* The symbol tables for this TU (obtained from the files listed in
626 WARNING: The order of entries here must match the order of entries
627 in the line header. After the first TU using this type_unit_group, the
628 line header for the subsequent TUs is recreated from this. This is done
629 because we need to use the same symtabs for each TU using the same
630 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
631 there's no guarantee the line header doesn't have duplicate entries. */
632 struct symtab
**symtabs
;
635 /* These sections are what may appear in a (real or virtual) DWO file. */
639 struct dwarf2_section_info abbrev
;
640 struct dwarf2_section_info line
;
641 struct dwarf2_section_info loc
;
642 struct dwarf2_section_info loclists
;
643 struct dwarf2_section_info macinfo
;
644 struct dwarf2_section_info macro
;
645 struct dwarf2_section_info str
;
646 struct dwarf2_section_info str_offsets
;
647 /* In the case of a virtual DWO file, these two are unused. */
648 struct dwarf2_section_info info
;
649 std::vector
<dwarf2_section_info
> types
;
652 /* CUs/TUs in DWP/DWO files. */
656 /* Backlink to the containing struct dwo_file. */
657 struct dwo_file
*dwo_file
;
659 /* The "id" that distinguishes this CU/TU.
660 .debug_info calls this "dwo_id", .debug_types calls this "signature".
661 Since signatures came first, we stick with it for consistency. */
664 /* The section this CU/TU lives in, in the DWO file. */
665 struct dwarf2_section_info
*section
;
667 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
668 sect_offset sect_off
;
671 /* For types, offset in the type's DIE of the type defined by this TU. */
672 cu_offset type_offset_in_tu
;
675 /* include/dwarf2.h defines the DWP section codes.
676 It defines a max value but it doesn't define a min value, which we
677 use for error checking, so provide one. */
679 enum dwp_v2_section_ids
684 /* Data for one DWO file.
686 This includes virtual DWO files (a virtual DWO file is a DWO file as it
687 appears in a DWP file). DWP files don't really have DWO files per se -
688 comdat folding of types "loses" the DWO file they came from, and from
689 a high level view DWP files appear to contain a mass of random types.
690 However, to maintain consistency with the non-DWP case we pretend DWP
691 files contain virtual DWO files, and we assign each TU with one virtual
692 DWO file (generally based on the line and abbrev section offsets -
693 a heuristic that seems to work in practice). */
697 dwo_file () = default;
698 DISABLE_COPY_AND_ASSIGN (dwo_file
);
700 /* The DW_AT_GNU_dwo_name attribute.
701 For virtual DWO files the name is constructed from the section offsets
702 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
703 from related CU+TUs. */
704 const char *dwo_name
= nullptr;
706 /* The DW_AT_comp_dir attribute. */
707 const char *comp_dir
= nullptr;
709 /* The bfd, when the file is open. Otherwise this is NULL.
710 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
711 gdb_bfd_ref_ptr dbfd
;
713 /* The sections that make up this DWO file.
714 Remember that for virtual DWO files in DWP V2, these are virtual
715 sections (for lack of a better name). */
716 struct dwo_sections sections
{};
718 /* The CUs in the file.
719 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
720 an extension to handle LLVM's Link Time Optimization output (where
721 multiple source files may be compiled into a single object/dwo pair). */
724 /* Table of TUs in the file.
725 Each element is a struct dwo_unit. */
729 /* These sections are what may appear in a DWP file. */
733 /* These are used by both DWP version 1 and 2. */
734 struct dwarf2_section_info str
;
735 struct dwarf2_section_info cu_index
;
736 struct dwarf2_section_info tu_index
;
738 /* These are only used by DWP version 2 files.
739 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
740 sections are referenced by section number, and are not recorded here.
741 In DWP version 2 there is at most one copy of all these sections, each
742 section being (effectively) comprised of the concatenation of all of the
743 individual sections that exist in the version 1 format.
744 To keep the code simple we treat each of these concatenated pieces as a
745 section itself (a virtual section?). */
746 struct dwarf2_section_info abbrev
;
747 struct dwarf2_section_info info
;
748 struct dwarf2_section_info line
;
749 struct dwarf2_section_info loc
;
750 struct dwarf2_section_info macinfo
;
751 struct dwarf2_section_info macro
;
752 struct dwarf2_section_info str_offsets
;
753 struct dwarf2_section_info types
;
756 /* These sections are what may appear in a virtual DWO file in DWP version 1.
757 A virtual DWO file is a DWO file as it appears in a DWP file. */
759 struct virtual_v1_dwo_sections
761 struct dwarf2_section_info abbrev
;
762 struct dwarf2_section_info line
;
763 struct dwarf2_section_info loc
;
764 struct dwarf2_section_info macinfo
;
765 struct dwarf2_section_info macro
;
766 struct dwarf2_section_info str_offsets
;
767 /* Each DWP hash table entry records one CU or one TU.
768 That is recorded here, and copied to dwo_unit.section. */
769 struct dwarf2_section_info info_or_types
;
772 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
773 In version 2, the sections of the DWO files are concatenated together
774 and stored in one section of that name. Thus each ELF section contains
775 several "virtual" sections. */
777 struct virtual_v2_dwo_sections
779 bfd_size_type abbrev_offset
;
780 bfd_size_type abbrev_size
;
782 bfd_size_type line_offset
;
783 bfd_size_type line_size
;
785 bfd_size_type loc_offset
;
786 bfd_size_type loc_size
;
788 bfd_size_type macinfo_offset
;
789 bfd_size_type macinfo_size
;
791 bfd_size_type macro_offset
;
792 bfd_size_type macro_size
;
794 bfd_size_type str_offsets_offset
;
795 bfd_size_type str_offsets_size
;
797 /* Each DWP hash table entry records one CU or one TU.
798 That is recorded here, and copied to dwo_unit.section. */
799 bfd_size_type info_or_types_offset
;
800 bfd_size_type info_or_types_size
;
803 /* Contents of DWP hash tables. */
805 struct dwp_hash_table
807 uint32_t version
, nr_columns
;
808 uint32_t nr_units
, nr_slots
;
809 const gdb_byte
*hash_table
, *unit_table
;
814 const gdb_byte
*indices
;
818 /* This is indexed by column number and gives the id of the section
820 #define MAX_NR_V2_DWO_SECTIONS \
821 (1 /* .debug_info or .debug_types */ \
822 + 1 /* .debug_abbrev */ \
823 + 1 /* .debug_line */ \
824 + 1 /* .debug_loc */ \
825 + 1 /* .debug_str_offsets */ \
826 + 1 /* .debug_macro or .debug_macinfo */)
827 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
828 const gdb_byte
*offsets
;
829 const gdb_byte
*sizes
;
834 /* Data for one DWP file. */
838 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
840 dbfd (std::move (abfd
))
844 /* Name of the file. */
847 /* File format version. */
851 gdb_bfd_ref_ptr dbfd
;
853 /* Section info for this file. */
854 struct dwp_sections sections
{};
856 /* Table of CUs in the file. */
857 const struct dwp_hash_table
*cus
= nullptr;
859 /* Table of TUs in the file. */
860 const struct dwp_hash_table
*tus
= nullptr;
862 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
863 htab_t loaded_cus
{};
864 htab_t loaded_tus
{};
866 /* Table to map ELF section numbers to their sections.
867 This is only needed for the DWP V1 file format. */
868 unsigned int num_sections
= 0;
869 asection
**elf_sections
= nullptr;
872 /* Struct used to pass misc. parameters to read_die_and_children, et
873 al. which are used for both .debug_info and .debug_types dies.
874 All parameters here are unchanging for the life of the call. This
875 struct exists to abstract away the constant parameters of die reading. */
877 struct die_reader_specs
879 /* The bfd of die_section. */
882 /* The CU of the DIE we are parsing. */
883 struct dwarf2_cu
*cu
;
885 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
886 struct dwo_file
*dwo_file
;
888 /* The section the die comes from.
889 This is either .debug_info or .debug_types, or the .dwo variants. */
890 struct dwarf2_section_info
*die_section
;
892 /* die_section->buffer. */
893 const gdb_byte
*buffer
;
895 /* The end of the buffer. */
896 const gdb_byte
*buffer_end
;
898 /* The value of the DW_AT_comp_dir attribute. */
899 const char *comp_dir
;
901 /* The abbreviation table to use when reading the DIEs. */
902 struct abbrev_table
*abbrev_table
;
905 /* Type of function passed to init_cutu_and_read_dies, et.al. */
906 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
907 const gdb_byte
*info_ptr
,
908 struct die_info
*comp_unit_die
,
912 /* A 1-based directory index. This is a strong typedef to prevent
913 accidentally using a directory index as a 0-based index into an
915 enum class dir_index
: unsigned int {};
917 /* Likewise, a 1-based file name index. */
918 enum class file_name_index
: unsigned int {};
922 file_entry () = default;
924 file_entry (const char *name_
, dir_index d_index_
,
925 unsigned int mod_time_
, unsigned int length_
)
928 mod_time (mod_time_
),
932 /* Return the include directory at D_INDEX stored in LH. Returns
933 NULL if D_INDEX is out of bounds. */
934 const char *include_dir (const line_header
*lh
) const;
936 /* The file name. Note this is an observing pointer. The memory is
937 owned by debug_line_buffer. */
940 /* The directory index (1-based). */
941 dir_index d_index
{};
943 unsigned int mod_time
{};
945 unsigned int length
{};
947 /* True if referenced by the Line Number Program. */
950 /* The associated symbol table, if any. */
951 struct symtab
*symtab
{};
954 /* The line number information for a compilation unit (found in the
955 .debug_line section) begins with a "statement program header",
956 which contains the following information. */
963 /* Add an entry to the include directory table. */
964 void add_include_dir (const char *include_dir
);
966 /* Add an entry to the file name table. */
967 void add_file_name (const char *name
, dir_index d_index
,
968 unsigned int mod_time
, unsigned int length
);
970 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
972 const char *include_dir_at (dir_index index
) const
974 /* Convert directory index number (1-based) to vector index
976 size_t vec_index
= to_underlying (index
) - 1;
978 if (vec_index
>= include_dirs
.size ())
980 return include_dirs
[vec_index
];
983 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
985 file_entry
*file_name_at (file_name_index index
)
987 /* Convert file name index number (1-based) to vector index
989 size_t vec_index
= to_underlying (index
) - 1;
991 if (vec_index
>= file_names
.size ())
993 return &file_names
[vec_index
];
996 /* Offset of line number information in .debug_line section. */
997 sect_offset sect_off
{};
999 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1000 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1002 unsigned int total_length
{};
1003 unsigned short version
{};
1004 unsigned int header_length
{};
1005 unsigned char minimum_instruction_length
{};
1006 unsigned char maximum_ops_per_instruction
{};
1007 unsigned char default_is_stmt
{};
1009 unsigned char line_range
{};
1010 unsigned char opcode_base
{};
1012 /* standard_opcode_lengths[i] is the number of operands for the
1013 standard opcode whose value is i. This means that
1014 standard_opcode_lengths[0] is unused, and the last meaningful
1015 element is standard_opcode_lengths[opcode_base - 1]. */
1016 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1018 /* The include_directories table. Note these are observing
1019 pointers. The memory is owned by debug_line_buffer. */
1020 std::vector
<const char *> include_dirs
;
1022 /* The file_names table. */
1023 std::vector
<file_entry
> file_names
;
1025 /* The start and end of the statement program following this
1026 header. These point into dwarf2_per_objfile->line_buffer. */
1027 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1030 typedef std::unique_ptr
<line_header
> line_header_up
;
1033 file_entry::include_dir (const line_header
*lh
) const
1035 return lh
->include_dir_at (d_index
);
1038 /* When we construct a partial symbol table entry we only
1039 need this much information. */
1040 struct partial_die_info
: public allocate_on_obstack
1042 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1044 /* Disable assign but still keep copy ctor, which is needed
1045 load_partial_dies. */
1046 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1048 /* Adjust the partial die before generating a symbol for it. This
1049 function may set the is_external flag or change the DIE's
1051 void fixup (struct dwarf2_cu
*cu
);
1053 /* Read a minimal amount of information into the minimal die
1055 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1056 const struct abbrev_info
&abbrev
,
1057 const gdb_byte
*info_ptr
);
1059 /* Offset of this DIE. */
1060 const sect_offset sect_off
;
1062 /* DWARF-2 tag for this DIE. */
1063 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1065 /* Assorted flags describing the data found in this DIE. */
1066 const unsigned int has_children
: 1;
1068 unsigned int is_external
: 1;
1069 unsigned int is_declaration
: 1;
1070 unsigned int has_type
: 1;
1071 unsigned int has_specification
: 1;
1072 unsigned int has_pc_info
: 1;
1073 unsigned int may_be_inlined
: 1;
1075 /* This DIE has been marked DW_AT_main_subprogram. */
1076 unsigned int main_subprogram
: 1;
1078 /* Flag set if the SCOPE field of this structure has been
1080 unsigned int scope_set
: 1;
1082 /* Flag set if the DIE has a byte_size attribute. */
1083 unsigned int has_byte_size
: 1;
1085 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1086 unsigned int has_const_value
: 1;
1088 /* Flag set if any of the DIE's children are template arguments. */
1089 unsigned int has_template_arguments
: 1;
1091 /* Flag set if fixup has been called on this die. */
1092 unsigned int fixup_called
: 1;
1094 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1095 unsigned int is_dwz
: 1;
1097 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1098 unsigned int spec_is_dwz
: 1;
1100 /* The name of this DIE. Normally the value of DW_AT_name, but
1101 sometimes a default name for unnamed DIEs. */
1102 const char *name
= nullptr;
1104 /* The linkage name, if present. */
1105 const char *linkage_name
= nullptr;
1107 /* The scope to prepend to our children. This is generally
1108 allocated on the comp_unit_obstack, so will disappear
1109 when this compilation unit leaves the cache. */
1110 const char *scope
= nullptr;
1112 /* Some data associated with the partial DIE. The tag determines
1113 which field is live. */
1116 /* The location description associated with this DIE, if any. */
1117 struct dwarf_block
*locdesc
;
1118 /* The offset of an import, for DW_TAG_imported_unit. */
1119 sect_offset sect_off
;
1122 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1123 CORE_ADDR lowpc
= 0;
1124 CORE_ADDR highpc
= 0;
1126 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1127 DW_AT_sibling, if any. */
1128 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1129 could return DW_AT_sibling values to its caller load_partial_dies. */
1130 const gdb_byte
*sibling
= nullptr;
1132 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1133 DW_AT_specification (or DW_AT_abstract_origin or
1134 DW_AT_extension). */
1135 sect_offset spec_offset
{};
1137 /* Pointers to this DIE's parent, first child, and next sibling,
1139 struct partial_die_info
*die_parent
= nullptr;
1140 struct partial_die_info
*die_child
= nullptr;
1141 struct partial_die_info
*die_sibling
= nullptr;
1143 friend struct partial_die_info
*
1144 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1147 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1148 partial_die_info (sect_offset sect_off
)
1149 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1153 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1155 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1160 has_specification
= 0;
1163 main_subprogram
= 0;
1166 has_const_value
= 0;
1167 has_template_arguments
= 0;
1174 /* This data structure holds the information of an abbrev. */
1177 unsigned int number
; /* number identifying abbrev */
1178 enum dwarf_tag tag
; /* dwarf tag */
1179 unsigned short has_children
; /* boolean */
1180 unsigned short num_attrs
; /* number of attributes */
1181 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1182 struct abbrev_info
*next
; /* next in chain */
1187 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1188 ENUM_BITFIELD(dwarf_form
) form
: 16;
1190 /* It is valid only if FORM is DW_FORM_implicit_const. */
1191 LONGEST implicit_const
;
1194 /* Size of abbrev_table.abbrev_hash_table. */
1195 #define ABBREV_HASH_SIZE 121
1197 /* Top level data structure to contain an abbreviation table. */
1201 explicit abbrev_table (sect_offset off
)
1205 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1206 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1209 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1211 /* Allocate space for a struct abbrev_info object in
1213 struct abbrev_info
*alloc_abbrev ();
1215 /* Add an abbreviation to the table. */
1216 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1218 /* Look up an abbrev in the table.
1219 Returns NULL if the abbrev is not found. */
1221 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1224 /* Where the abbrev table came from.
1225 This is used as a sanity check when the table is used. */
1226 const sect_offset sect_off
;
1228 /* Storage for the abbrev table. */
1229 auto_obstack abbrev_obstack
;
1233 /* Hash table of abbrevs.
1234 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1235 It could be statically allocated, but the previous code didn't so we
1237 struct abbrev_info
**m_abbrevs
;
1240 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1242 /* Attributes have a name and a value. */
1245 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1246 ENUM_BITFIELD(dwarf_form
) form
: 15;
1248 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1249 field should be in u.str (existing only for DW_STRING) but it is kept
1250 here for better struct attribute alignment. */
1251 unsigned int string_is_canonical
: 1;
1256 struct dwarf_block
*blk
;
1265 /* This data structure holds a complete die structure. */
1268 /* DWARF-2 tag for this DIE. */
1269 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1271 /* Number of attributes */
1272 unsigned char num_attrs
;
1274 /* True if we're presently building the full type name for the
1275 type derived from this DIE. */
1276 unsigned char building_fullname
: 1;
1278 /* True if this die is in process. PR 16581. */
1279 unsigned char in_process
: 1;
1282 unsigned int abbrev
;
1284 /* Offset in .debug_info or .debug_types section. */
1285 sect_offset sect_off
;
1287 /* The dies in a compilation unit form an n-ary tree. PARENT
1288 points to this die's parent; CHILD points to the first child of
1289 this node; and all the children of a given node are chained
1290 together via their SIBLING fields. */
1291 struct die_info
*child
; /* Its first child, if any. */
1292 struct die_info
*sibling
; /* Its next sibling, if any. */
1293 struct die_info
*parent
; /* Its parent, if any. */
1295 /* An array of attributes, with NUM_ATTRS elements. There may be
1296 zero, but it's not common and zero-sized arrays are not
1297 sufficiently portable C. */
1298 struct attribute attrs
[1];
1301 /* Get at parts of an attribute structure. */
1303 #define DW_STRING(attr) ((attr)->u.str)
1304 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1305 #define DW_UNSND(attr) ((attr)->u.unsnd)
1306 #define DW_BLOCK(attr) ((attr)->u.blk)
1307 #define DW_SND(attr) ((attr)->u.snd)
1308 #define DW_ADDR(attr) ((attr)->u.addr)
1309 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1311 /* Blocks are a bunch of untyped bytes. */
1316 /* Valid only if SIZE is not zero. */
1317 const gdb_byte
*data
;
1320 #ifndef ATTR_ALLOC_CHUNK
1321 #define ATTR_ALLOC_CHUNK 4
1324 /* Allocate fields for structs, unions and enums in this size. */
1325 #ifndef DW_FIELD_ALLOC_CHUNK
1326 #define DW_FIELD_ALLOC_CHUNK 4
1329 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1330 but this would require a corresponding change in unpack_field_as_long
1332 static int bits_per_byte
= 8;
1334 /* When reading a variant or variant part, we track a bit more
1335 information about the field, and store it in an object of this
1338 struct variant_field
1340 /* If we see a DW_TAG_variant, then this will be the discriminant
1342 ULONGEST discriminant_value
;
1343 /* If we see a DW_TAG_variant, then this will be set if this is the
1345 bool default_branch
;
1346 /* While reading a DW_TAG_variant_part, this will be set if this
1347 field is the discriminant. */
1348 bool is_discriminant
;
1353 int accessibility
= 0;
1355 /* Extra information to describe a variant or variant part. */
1356 struct variant_field variant
{};
1357 struct field field
{};
1362 const char *name
= nullptr;
1363 std::vector
<struct fn_field
> fnfields
;
1366 /* The routines that read and process dies for a C struct or C++ class
1367 pass lists of data member fields and lists of member function fields
1368 in an instance of a field_info structure, as defined below. */
1371 /* List of data member and baseclasses fields. */
1372 std::vector
<struct nextfield
> fields
;
1373 std::vector
<struct nextfield
> baseclasses
;
1375 /* Number of fields (including baseclasses). */
1378 /* Set if the accesibility of one of the fields is not public. */
1379 int non_public_fields
= 0;
1381 /* Member function fieldlist array, contains name of possibly overloaded
1382 member function, number of overloaded member functions and a pointer
1383 to the head of the member function field chain. */
1384 std::vector
<struct fnfieldlist
> fnfieldlists
;
1386 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1387 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1388 std::vector
<struct decl_field
> typedef_field_list
;
1390 /* Nested types defined by this class and the number of elements in this
1392 std::vector
<struct decl_field
> nested_types_list
;
1395 /* One item on the queue of compilation units to read in full symbols
1397 struct dwarf2_queue_item
1399 struct dwarf2_per_cu_data
*per_cu
;
1400 enum language pretend_language
;
1401 struct dwarf2_queue_item
*next
;
1404 /* The current queue. */
1405 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1407 /* Loaded secondary compilation units are kept in memory until they
1408 have not been referenced for the processing of this many
1409 compilation units. Set this to zero to disable caching. Cache
1410 sizes of up to at least twenty will improve startup time for
1411 typical inter-CU-reference binaries, at an obvious memory cost. */
1412 static int dwarf_max_cache_age
= 5;
1414 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1415 struct cmd_list_element
*c
, const char *value
)
1417 fprintf_filtered (file
, _("The upper bound on the age of cached "
1418 "DWARF compilation units is %s.\n"),
1422 /* local function prototypes */
1424 static const char *get_section_name (const struct dwarf2_section_info
*);
1426 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1428 static void dwarf2_find_base_address (struct die_info
*die
,
1429 struct dwarf2_cu
*cu
);
1431 static struct partial_symtab
*create_partial_symtab
1432 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1434 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1435 const gdb_byte
*info_ptr
,
1436 struct die_info
*type_unit_die
,
1437 int has_children
, void *data
);
1439 static void dwarf2_build_psymtabs_hard
1440 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1442 static void scan_partial_symbols (struct partial_die_info
*,
1443 CORE_ADDR
*, CORE_ADDR
*,
1444 int, struct dwarf2_cu
*);
1446 static void add_partial_symbol (struct partial_die_info
*,
1447 struct dwarf2_cu
*);
1449 static void add_partial_namespace (struct partial_die_info
*pdi
,
1450 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1451 int set_addrmap
, struct dwarf2_cu
*cu
);
1453 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1454 CORE_ADDR
*highpc
, int set_addrmap
,
1455 struct dwarf2_cu
*cu
);
1457 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1458 struct dwarf2_cu
*cu
);
1460 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1461 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1462 int need_pc
, struct dwarf2_cu
*cu
);
1464 static void dwarf2_read_symtab (struct partial_symtab
*,
1467 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1469 static abbrev_table_up abbrev_table_read_table
1470 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1473 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1475 static struct partial_die_info
*load_partial_dies
1476 (const struct die_reader_specs
*, const gdb_byte
*, int);
1478 /* A pair of partial_die_info and compilation unit. */
1479 struct cu_partial_die_info
1481 /* The compilation unit of the partial_die_info. */
1482 struct dwarf2_cu
*cu
;
1483 /* A partial_die_info. */
1484 struct partial_die_info
*pdi
;
1486 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1492 cu_partial_die_info () = delete;
1495 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1496 struct dwarf2_cu
*);
1498 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1499 struct attribute
*, struct attr_abbrev
*,
1502 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1504 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1506 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1508 /* Read the next three bytes (little-endian order) as an unsigned integer. */
1509 static unsigned int read_3_bytes (bfd
*, const gdb_byte
*);
1511 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1513 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1515 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1518 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1520 static LONGEST read_checked_initial_length_and_offset
1521 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1522 unsigned int *, unsigned int *);
1524 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1525 const struct comp_unit_head
*,
1528 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1530 static sect_offset read_abbrev_offset
1531 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1532 struct dwarf2_section_info
*, sect_offset
);
1534 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1536 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1538 static const char *read_indirect_string
1539 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1540 const struct comp_unit_head
*, unsigned int *);
1542 static const char *read_indirect_line_string
1543 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1544 const struct comp_unit_head
*, unsigned int *);
1546 static const char *read_indirect_string_at_offset
1547 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1548 LONGEST str_offset
);
1550 static const char *read_indirect_string_from_dwz
1551 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1553 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1555 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1559 static const char *read_str_index (const struct die_reader_specs
*reader
,
1560 ULONGEST str_index
);
1562 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1564 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1565 struct dwarf2_cu
*);
1567 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1570 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1571 struct dwarf2_cu
*cu
);
1573 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1575 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1576 struct dwarf2_cu
*cu
);
1578 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1580 static struct die_info
*die_specification (struct die_info
*die
,
1581 struct dwarf2_cu
**);
1583 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1584 struct dwarf2_cu
*cu
);
1586 static void dwarf_decode_lines (struct line_header
*, const char *,
1587 struct dwarf2_cu
*, struct partial_symtab
*,
1588 CORE_ADDR
, int decode_mapping
);
1590 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1593 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1594 struct dwarf2_cu
*, struct symbol
* = NULL
);
1596 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1597 struct dwarf2_cu
*);
1599 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1602 struct obstack
*obstack
,
1603 struct dwarf2_cu
*cu
, LONGEST
*value
,
1604 const gdb_byte
**bytes
,
1605 struct dwarf2_locexpr_baton
**baton
);
1607 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1609 static int need_gnat_info (struct dwarf2_cu
*);
1611 static struct type
*die_descriptive_type (struct die_info
*,
1612 struct dwarf2_cu
*);
1614 static void set_descriptive_type (struct type
*, struct die_info
*,
1615 struct dwarf2_cu
*);
1617 static struct type
*die_containing_type (struct die_info
*,
1618 struct dwarf2_cu
*);
1620 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1621 struct dwarf2_cu
*);
1623 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1625 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1627 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1629 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1630 const char *suffix
, int physname
,
1631 struct dwarf2_cu
*cu
);
1633 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1635 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1637 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1639 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1641 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1643 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1645 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1646 struct dwarf2_cu
*, struct partial_symtab
*);
1648 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1649 values. Keep the items ordered with increasing constraints compliance. */
1652 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1653 PC_BOUNDS_NOT_PRESENT
,
1655 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1656 were present but they do not form a valid range of PC addresses. */
1659 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1662 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1666 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1667 CORE_ADDR
*, CORE_ADDR
*,
1669 struct partial_symtab
*);
1671 static void get_scope_pc_bounds (struct die_info
*,
1672 CORE_ADDR
*, CORE_ADDR
*,
1673 struct dwarf2_cu
*);
1675 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1676 CORE_ADDR
, struct dwarf2_cu
*);
1678 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1679 struct dwarf2_cu
*);
1681 static void dwarf2_attach_fields_to_type (struct field_info
*,
1682 struct type
*, struct dwarf2_cu
*);
1684 static void dwarf2_add_member_fn (struct field_info
*,
1685 struct die_info
*, struct type
*,
1686 struct dwarf2_cu
*);
1688 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1690 struct dwarf2_cu
*);
1692 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1694 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1696 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1698 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1700 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1702 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1704 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1706 static struct type
*read_module_type (struct die_info
*die
,
1707 struct dwarf2_cu
*cu
);
1709 static const char *namespace_name (struct die_info
*die
,
1710 int *is_anonymous
, struct dwarf2_cu
*);
1712 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1714 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1716 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1717 struct dwarf2_cu
*);
1719 static struct die_info
*read_die_and_siblings_1
1720 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1723 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1724 const gdb_byte
*info_ptr
,
1725 const gdb_byte
**new_info_ptr
,
1726 struct die_info
*parent
);
1728 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1729 struct die_info
**, const gdb_byte
*,
1732 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1733 struct die_info
**, const gdb_byte
*,
1736 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1738 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1741 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1743 static const char *dwarf2_full_name (const char *name
,
1744 struct die_info
*die
,
1745 struct dwarf2_cu
*cu
);
1747 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1748 struct dwarf2_cu
*cu
);
1750 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1751 struct dwarf2_cu
**);
1753 static const char *dwarf_tag_name (unsigned int);
1755 static const char *dwarf_attr_name (unsigned int);
1757 static const char *dwarf_unit_type_name (int unit_type
);
1759 static const char *dwarf_form_name (unsigned int);
1761 static const char *dwarf_bool_name (unsigned int);
1763 static const char *dwarf_type_encoding_name (unsigned int);
1765 static struct die_info
*sibling_die (struct die_info
*);
1767 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1769 static void dump_die_for_error (struct die_info
*);
1771 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1774 /*static*/ void dump_die (struct die_info
*, int max_level
);
1776 static void store_in_ref_table (struct die_info
*,
1777 struct dwarf2_cu
*);
1779 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1781 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1783 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1784 const struct attribute
*,
1785 struct dwarf2_cu
**);
1787 static struct die_info
*follow_die_ref (struct die_info
*,
1788 const struct attribute
*,
1789 struct dwarf2_cu
**);
1791 static struct die_info
*follow_die_sig (struct die_info
*,
1792 const struct attribute
*,
1793 struct dwarf2_cu
**);
1795 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1796 struct dwarf2_cu
*);
1798 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1799 const struct attribute
*,
1800 struct dwarf2_cu
*);
1802 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1804 static void read_signatured_type (struct signatured_type
*);
1806 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1807 struct die_info
*die
, struct dwarf2_cu
*cu
,
1808 struct dynamic_prop
*prop
, struct type
*type
);
1810 /* memory allocation interface */
1812 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1814 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1816 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1818 static int attr_form_is_block (const struct attribute
*);
1820 static int attr_form_is_section_offset (const struct attribute
*);
1822 static int attr_form_is_constant (const struct attribute
*);
1824 static int attr_form_is_ref (const struct attribute
*);
1826 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1827 struct dwarf2_loclist_baton
*baton
,
1828 const struct attribute
*attr
);
1830 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1832 struct dwarf2_cu
*cu
,
1835 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1836 const gdb_byte
*info_ptr
,
1837 struct abbrev_info
*abbrev
);
1839 static hashval_t
partial_die_hash (const void *item
);
1841 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1843 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1844 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1845 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1847 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1848 struct die_info
*comp_unit_die
,
1849 enum language pretend_language
);
1851 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1853 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1855 static struct type
*set_die_type (struct die_info
*, struct type
*,
1856 struct dwarf2_cu
*);
1858 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1860 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1862 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1865 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1868 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1871 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1872 struct dwarf2_per_cu_data
*);
1874 static void dwarf2_mark (struct dwarf2_cu
*);
1876 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1878 static struct type
*get_die_type_at_offset (sect_offset
,
1879 struct dwarf2_per_cu_data
*);
1881 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1883 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1884 enum language pretend_language
);
1886 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1888 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1889 static struct type
*dwarf2_per_cu_addr_sized_int_type
1890 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1892 /* Class, the destructor of which frees all allocated queue entries. This
1893 will only have work to do if an error was thrown while processing the
1894 dwarf. If no error was thrown then the queue entries should have all
1895 been processed, and freed, as we went along. */
1897 class dwarf2_queue_guard
1900 dwarf2_queue_guard () = default;
1902 /* Free any entries remaining on the queue. There should only be
1903 entries left if we hit an error while processing the dwarf. */
1904 ~dwarf2_queue_guard ()
1906 struct dwarf2_queue_item
*item
, *last
;
1908 item
= dwarf2_queue
;
1911 /* Anything still marked queued is likely to be in an
1912 inconsistent state, so discard it. */
1913 if (item
->per_cu
->queued
)
1915 if (item
->per_cu
->cu
!= NULL
)
1916 free_one_cached_comp_unit (item
->per_cu
);
1917 item
->per_cu
->queued
= 0;
1925 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1929 /* The return type of find_file_and_directory. Note, the enclosed
1930 string pointers are only valid while this object is valid. */
1932 struct file_and_directory
1934 /* The filename. This is never NULL. */
1937 /* The compilation directory. NULL if not known. If we needed to
1938 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1939 points directly to the DW_AT_comp_dir string attribute owned by
1940 the obstack that owns the DIE. */
1941 const char *comp_dir
;
1943 /* If we needed to build a new string for comp_dir, this is what
1944 owns the storage. */
1945 std::string comp_dir_storage
;
1948 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1949 struct dwarf2_cu
*cu
);
1951 static char *file_full_name (int file
, struct line_header
*lh
,
1952 const char *comp_dir
);
1954 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1955 enum class rcuh_kind
{ COMPILE
, TYPE
};
1957 static const gdb_byte
*read_and_check_comp_unit_head
1958 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1959 struct comp_unit_head
*header
,
1960 struct dwarf2_section_info
*section
,
1961 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1962 rcuh_kind section_kind
);
1964 static void init_cutu_and_read_dies
1965 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1966 int use_existing_cu
, int keep
, bool skip_partial
,
1967 die_reader_func_ftype
*die_reader_func
, void *data
);
1969 static void init_cutu_and_read_dies_simple
1970 (struct dwarf2_per_cu_data
*this_cu
,
1971 die_reader_func_ftype
*die_reader_func
, void *data
);
1973 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1975 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1977 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1978 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1979 struct dwp_file
*dwp_file
, const char *comp_dir
,
1980 ULONGEST signature
, int is_debug_types
);
1982 static struct dwp_file
*get_dwp_file
1983 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1985 static struct dwo_unit
*lookup_dwo_comp_unit
1986 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1988 static struct dwo_unit
*lookup_dwo_type_unit
1989 (struct signatured_type
*, const char *, const char *);
1991 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1993 /* A unique pointer to a dwo_file. */
1995 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1997 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1999 static void check_producer (struct dwarf2_cu
*cu
);
2001 static void free_line_header_voidp (void *arg
);
2003 /* Various complaints about symbol reading that don't abort the process. */
2006 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2008 complaint (_("statement list doesn't fit in .debug_line section"));
2012 dwarf2_debug_line_missing_file_complaint (void)
2014 complaint (_(".debug_line section has line data without a file"));
2018 dwarf2_debug_line_missing_end_sequence_complaint (void)
2020 complaint (_(".debug_line section has line "
2021 "program sequence without an end"));
2025 dwarf2_complex_location_expr_complaint (void)
2027 complaint (_("location expression too complex"));
2031 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2034 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
2039 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2041 complaint (_("debug info runs off end of %s section"
2043 get_section_name (section
),
2044 get_section_file_name (section
));
2048 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2050 complaint (_("macro debug info contains a "
2051 "malformed macro definition:\n`%s'"),
2056 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2058 complaint (_("invalid attribute class or form for '%s' in '%s'"),
2062 /* Hash function for line_header_hash. */
2065 line_header_hash (const struct line_header
*ofs
)
2067 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2070 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2073 line_header_hash_voidp (const void *item
)
2075 const struct line_header
*ofs
= (const struct line_header
*) item
;
2077 return line_header_hash (ofs
);
2080 /* Equality function for line_header_hash. */
2083 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2085 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2086 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2088 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2089 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2094 /* Read the given attribute value as an address, taking the attribute's
2095 form into account. */
2098 attr_value_as_address (struct attribute
*attr
)
2102 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_addrx
2103 && attr
->form
!= DW_FORM_GNU_addr_index
)
2105 /* Aside from a few clearly defined exceptions, attributes that
2106 contain an address must always be in DW_FORM_addr form.
2107 Unfortunately, some compilers happen to be violating this
2108 requirement by encoding addresses using other forms, such
2109 as DW_FORM_data4 for example. For those broken compilers,
2110 we try to do our best, without any guarantee of success,
2111 to interpret the address correctly. It would also be nice
2112 to generate a complaint, but that would require us to maintain
2113 a list of legitimate cases where a non-address form is allowed,
2114 as well as update callers to pass in at least the CU's DWARF
2115 version. This is more overhead than what we're willing to
2116 expand for a pretty rare case. */
2117 addr
= DW_UNSND (attr
);
2120 addr
= DW_ADDR (attr
);
2125 /* See declaration. */
2127 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2128 const dwarf2_debug_sections
*names
,
2130 : objfile (objfile_
),
2131 can_copy (can_copy_
)
2134 names
= &dwarf2_elf_names
;
2136 bfd
*obfd
= objfile
->obfd
;
2138 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2139 locate_sections (obfd
, sec
, *names
);
2142 dwarf2_per_objfile::~dwarf2_per_objfile ()
2144 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2145 free_cached_comp_units ();
2147 if (quick_file_names_table
)
2148 htab_delete (quick_file_names_table
);
2150 if (line_header_hash
)
2151 htab_delete (line_header_hash
);
2153 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2154 per_cu
->imported_symtabs_free ();
2156 for (signatured_type
*sig_type
: all_type_units
)
2157 sig_type
->per_cu
.imported_symtabs_free ();
2159 /* Everything else should be on the objfile obstack. */
2162 /* See declaration. */
2165 dwarf2_per_objfile::free_cached_comp_units ()
2167 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2168 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2169 while (per_cu
!= NULL
)
2171 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2174 *last_chain
= next_cu
;
2179 /* A helper class that calls free_cached_comp_units on
2182 class free_cached_comp_units
2186 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2187 : m_per_objfile (per_objfile
)
2191 ~free_cached_comp_units ()
2193 m_per_objfile
->free_cached_comp_units ();
2196 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2200 dwarf2_per_objfile
*m_per_objfile
;
2203 /* Try to locate the sections we need for DWARF 2 debugging
2204 information and return true if we have enough to do something.
2205 NAMES points to the dwarf2 section names, or is NULL if the standard
2206 ELF names are used. CAN_COPY is true for formats where symbol
2207 interposition is possible and so symbol values must follow copy
2208 relocation rules. */
2211 dwarf2_has_info (struct objfile
*objfile
,
2212 const struct dwarf2_debug_sections
*names
,
2215 if (objfile
->flags
& OBJF_READNEVER
)
2218 struct dwarf2_per_objfile
*dwarf2_per_objfile
2219 = get_dwarf2_per_objfile (objfile
);
2221 if (dwarf2_per_objfile
== NULL
)
2222 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2226 return (!dwarf2_per_objfile
->info
.is_virtual
2227 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2228 && !dwarf2_per_objfile
->abbrev
.is_virtual
2229 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2232 /* Return the containing section of virtual section SECTION. */
2234 static struct dwarf2_section_info
*
2235 get_containing_section (const struct dwarf2_section_info
*section
)
2237 gdb_assert (section
->is_virtual
);
2238 return section
->s
.containing_section
;
2241 /* Return the bfd owner of SECTION. */
2244 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2246 if (section
->is_virtual
)
2248 section
= get_containing_section (section
);
2249 gdb_assert (!section
->is_virtual
);
2251 return section
->s
.section
->owner
;
2254 /* Return the bfd section of SECTION.
2255 Returns NULL if the section is not present. */
2258 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2260 if (section
->is_virtual
)
2262 section
= get_containing_section (section
);
2263 gdb_assert (!section
->is_virtual
);
2265 return section
->s
.section
;
2268 /* Return the name of SECTION. */
2271 get_section_name (const struct dwarf2_section_info
*section
)
2273 asection
*sectp
= get_section_bfd_section (section
);
2275 gdb_assert (sectp
!= NULL
);
2276 return bfd_section_name (sectp
);
2279 /* Return the name of the file SECTION is in. */
2282 get_section_file_name (const struct dwarf2_section_info
*section
)
2284 bfd
*abfd
= get_section_bfd_owner (section
);
2286 return bfd_get_filename (abfd
);
2289 /* Return the id of SECTION.
2290 Returns 0 if SECTION doesn't exist. */
2293 get_section_id (const struct dwarf2_section_info
*section
)
2295 asection
*sectp
= get_section_bfd_section (section
);
2302 /* Return the flags of SECTION.
2303 SECTION (or containing section if this is a virtual section) must exist. */
2306 get_section_flags (const struct dwarf2_section_info
*section
)
2308 asection
*sectp
= get_section_bfd_section (section
);
2310 gdb_assert (sectp
!= NULL
);
2311 return bfd_section_flags (sectp
);
2314 /* When loading sections, we look either for uncompressed section or for
2315 compressed section names. */
2318 section_is_p (const char *section_name
,
2319 const struct dwarf2_section_names
*names
)
2321 if (names
->normal
!= NULL
2322 && strcmp (section_name
, names
->normal
) == 0)
2324 if (names
->compressed
!= NULL
2325 && strcmp (section_name
, names
->compressed
) == 0)
2330 /* See declaration. */
2333 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2334 const dwarf2_debug_sections
&names
)
2336 flagword aflag
= bfd_section_flags (sectp
);
2338 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2341 else if (section_is_p (sectp
->name
, &names
.info
))
2343 this->info
.s
.section
= sectp
;
2344 this->info
.size
= bfd_section_size (sectp
);
2346 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2348 this->abbrev
.s
.section
= sectp
;
2349 this->abbrev
.size
= bfd_section_size (sectp
);
2351 else if (section_is_p (sectp
->name
, &names
.line
))
2353 this->line
.s
.section
= sectp
;
2354 this->line
.size
= bfd_section_size (sectp
);
2356 else if (section_is_p (sectp
->name
, &names
.loc
))
2358 this->loc
.s
.section
= sectp
;
2359 this->loc
.size
= bfd_section_size (sectp
);
2361 else if (section_is_p (sectp
->name
, &names
.loclists
))
2363 this->loclists
.s
.section
= sectp
;
2364 this->loclists
.size
= bfd_section_size (sectp
);
2366 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2368 this->macinfo
.s
.section
= sectp
;
2369 this->macinfo
.size
= bfd_section_size (sectp
);
2371 else if (section_is_p (sectp
->name
, &names
.macro
))
2373 this->macro
.s
.section
= sectp
;
2374 this->macro
.size
= bfd_section_size (sectp
);
2376 else if (section_is_p (sectp
->name
, &names
.str
))
2378 this->str
.s
.section
= sectp
;
2379 this->str
.size
= bfd_section_size (sectp
);
2381 else if (section_is_p (sectp
->name
, &names
.line_str
))
2383 this->line_str
.s
.section
= sectp
;
2384 this->line_str
.size
= bfd_section_size (sectp
);
2386 else if (section_is_p (sectp
->name
, &names
.addr
))
2388 this->addr
.s
.section
= sectp
;
2389 this->addr
.size
= bfd_section_size (sectp
);
2391 else if (section_is_p (sectp
->name
, &names
.frame
))
2393 this->frame
.s
.section
= sectp
;
2394 this->frame
.size
= bfd_section_size (sectp
);
2396 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2398 this->eh_frame
.s
.section
= sectp
;
2399 this->eh_frame
.size
= bfd_section_size (sectp
);
2401 else if (section_is_p (sectp
->name
, &names
.ranges
))
2403 this->ranges
.s
.section
= sectp
;
2404 this->ranges
.size
= bfd_section_size (sectp
);
2406 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2408 this->rnglists
.s
.section
= sectp
;
2409 this->rnglists
.size
= bfd_section_size (sectp
);
2411 else if (section_is_p (sectp
->name
, &names
.types
))
2413 struct dwarf2_section_info type_section
;
2415 memset (&type_section
, 0, sizeof (type_section
));
2416 type_section
.s
.section
= sectp
;
2417 type_section
.size
= bfd_section_size (sectp
);
2419 this->types
.push_back (type_section
);
2421 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2423 this->gdb_index
.s
.section
= sectp
;
2424 this->gdb_index
.size
= bfd_section_size (sectp
);
2426 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2428 this->debug_names
.s
.section
= sectp
;
2429 this->debug_names
.size
= bfd_section_size (sectp
);
2431 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2433 this->debug_aranges
.s
.section
= sectp
;
2434 this->debug_aranges
.size
= bfd_section_size (sectp
);
2437 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2438 && bfd_section_vma (sectp
) == 0)
2439 this->has_section_at_zero
= true;
2442 /* A helper function that decides whether a section is empty,
2446 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2448 if (section
->is_virtual
)
2449 return section
->size
== 0;
2450 return section
->s
.section
== NULL
|| section
->size
== 0;
2453 /* See dwarf2read.h. */
2456 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2460 gdb_byte
*buf
, *retbuf
;
2464 info
->buffer
= NULL
;
2465 info
->readin
= true;
2467 if (dwarf2_section_empty_p (info
))
2470 sectp
= get_section_bfd_section (info
);
2472 /* If this is a virtual section we need to read in the real one first. */
2473 if (info
->is_virtual
)
2475 struct dwarf2_section_info
*containing_section
=
2476 get_containing_section (info
);
2478 gdb_assert (sectp
!= NULL
);
2479 if ((sectp
->flags
& SEC_RELOC
) != 0)
2481 error (_("Dwarf Error: DWP format V2 with relocations is not"
2482 " supported in section %s [in module %s]"),
2483 get_section_name (info
), get_section_file_name (info
));
2485 dwarf2_read_section (objfile
, containing_section
);
2486 /* Other code should have already caught virtual sections that don't
2488 gdb_assert (info
->virtual_offset
+ info
->size
2489 <= containing_section
->size
);
2490 /* If the real section is empty or there was a problem reading the
2491 section we shouldn't get here. */
2492 gdb_assert (containing_section
->buffer
!= NULL
);
2493 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2497 /* If the section has relocations, we must read it ourselves.
2498 Otherwise we attach it to the BFD. */
2499 if ((sectp
->flags
& SEC_RELOC
) == 0)
2501 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2505 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2508 /* When debugging .o files, we may need to apply relocations; see
2509 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2510 We never compress sections in .o files, so we only need to
2511 try this when the section is not compressed. */
2512 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2515 info
->buffer
= retbuf
;
2519 abfd
= get_section_bfd_owner (info
);
2520 gdb_assert (abfd
!= NULL
);
2522 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2523 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2525 error (_("Dwarf Error: Can't read DWARF data"
2526 " in section %s [in module %s]"),
2527 bfd_section_name (sectp
), bfd_get_filename (abfd
));
2531 /* A helper function that returns the size of a section in a safe way.
2532 If you are positive that the section has been read before using the
2533 size, then it is safe to refer to the dwarf2_section_info object's
2534 "size" field directly. In other cases, you must call this
2535 function, because for compressed sections the size field is not set
2536 correctly until the section has been read. */
2538 static bfd_size_type
2539 dwarf2_section_size (struct objfile
*objfile
,
2540 struct dwarf2_section_info
*info
)
2543 dwarf2_read_section (objfile
, info
);
2547 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2551 dwarf2_get_section_info (struct objfile
*objfile
,
2552 enum dwarf2_section_enum sect
,
2553 asection
**sectp
, const gdb_byte
**bufp
,
2554 bfd_size_type
*sizep
)
2556 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2557 struct dwarf2_section_info
*info
;
2559 /* We may see an objfile without any DWARF, in which case we just
2570 case DWARF2_DEBUG_FRAME
:
2571 info
= &data
->frame
;
2573 case DWARF2_EH_FRAME
:
2574 info
= &data
->eh_frame
;
2577 gdb_assert_not_reached ("unexpected section");
2580 dwarf2_read_section (objfile
, info
);
2582 *sectp
= get_section_bfd_section (info
);
2583 *bufp
= info
->buffer
;
2584 *sizep
= info
->size
;
2587 /* A helper function to find the sections for a .dwz file. */
2590 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2592 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2594 /* Note that we only support the standard ELF names, because .dwz
2595 is ELF-only (at the time of writing). */
2596 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2598 dwz_file
->abbrev
.s
.section
= sectp
;
2599 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2601 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2603 dwz_file
->info
.s
.section
= sectp
;
2604 dwz_file
->info
.size
= bfd_section_size (sectp
);
2606 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2608 dwz_file
->str
.s
.section
= sectp
;
2609 dwz_file
->str
.size
= bfd_section_size (sectp
);
2611 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2613 dwz_file
->line
.s
.section
= sectp
;
2614 dwz_file
->line
.size
= bfd_section_size (sectp
);
2616 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2618 dwz_file
->macro
.s
.section
= sectp
;
2619 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2621 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2623 dwz_file
->gdb_index
.s
.section
= sectp
;
2624 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2626 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2628 dwz_file
->debug_names
.s
.section
= sectp
;
2629 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2633 /* See dwarf2read.h. */
2636 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2638 const char *filename
;
2639 bfd_size_type buildid_len_arg
;
2643 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2644 return dwarf2_per_objfile
->dwz_file
.get ();
2646 bfd_set_error (bfd_error_no_error
);
2647 gdb::unique_xmalloc_ptr
<char> data
2648 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2649 &buildid_len_arg
, &buildid
));
2652 if (bfd_get_error () == bfd_error_no_error
)
2654 error (_("could not read '.gnu_debugaltlink' section: %s"),
2655 bfd_errmsg (bfd_get_error ()));
2658 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2660 buildid_len
= (size_t) buildid_len_arg
;
2662 filename
= data
.get ();
2664 std::string abs_storage
;
2665 if (!IS_ABSOLUTE_PATH (filename
))
2667 gdb::unique_xmalloc_ptr
<char> abs
2668 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2670 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2671 filename
= abs_storage
.c_str ();
2674 /* First try the file name given in the section. If that doesn't
2675 work, try to use the build-id instead. */
2676 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2677 if (dwz_bfd
!= NULL
)
2679 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2680 dwz_bfd
.reset (nullptr);
2683 if (dwz_bfd
== NULL
)
2684 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2686 if (dwz_bfd
== NULL
)
2687 error (_("could not find '.gnu_debugaltlink' file for %s"),
2688 objfile_name (dwarf2_per_objfile
->objfile
));
2690 std::unique_ptr
<struct dwz_file
> result
2691 (new struct dwz_file (std::move (dwz_bfd
)));
2693 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2696 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2697 result
->dwz_bfd
.get ());
2698 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2699 return dwarf2_per_objfile
->dwz_file
.get ();
2702 /* DWARF quick_symbols_functions support. */
2704 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2705 unique line tables, so we maintain a separate table of all .debug_line
2706 derived entries to support the sharing.
2707 All the quick functions need is the list of file names. We discard the
2708 line_header when we're done and don't need to record it here. */
2709 struct quick_file_names
2711 /* The data used to construct the hash key. */
2712 struct stmt_list_hash hash
;
2714 /* The number of entries in file_names, real_names. */
2715 unsigned int num_file_names
;
2717 /* The file names from the line table, after being run through
2719 const char **file_names
;
2721 /* The file names from the line table after being run through
2722 gdb_realpath. These are computed lazily. */
2723 const char **real_names
;
2726 /* When using the index (and thus not using psymtabs), each CU has an
2727 object of this type. This is used to hold information needed by
2728 the various "quick" methods. */
2729 struct dwarf2_per_cu_quick_data
2731 /* The file table. This can be NULL if there was no file table
2732 or it's currently not read in.
2733 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2734 struct quick_file_names
*file_names
;
2736 /* The corresponding symbol table. This is NULL if symbols for this
2737 CU have not yet been read. */
2738 struct compunit_symtab
*compunit_symtab
;
2740 /* A temporary mark bit used when iterating over all CUs in
2741 expand_symtabs_matching. */
2742 unsigned int mark
: 1;
2744 /* True if we've tried to read the file table and found there isn't one.
2745 There will be no point in trying to read it again next time. */
2746 unsigned int no_file_data
: 1;
2749 /* Utility hash function for a stmt_list_hash. */
2752 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2756 if (stmt_list_hash
->dwo_unit
!= NULL
)
2757 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2758 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2762 /* Utility equality function for a stmt_list_hash. */
2765 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2766 const struct stmt_list_hash
*rhs
)
2768 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2770 if (lhs
->dwo_unit
!= NULL
2771 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2774 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2777 /* Hash function for a quick_file_names. */
2780 hash_file_name_entry (const void *e
)
2782 const struct quick_file_names
*file_data
2783 = (const struct quick_file_names
*) e
;
2785 return hash_stmt_list_entry (&file_data
->hash
);
2788 /* Equality function for a quick_file_names. */
2791 eq_file_name_entry (const void *a
, const void *b
)
2793 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2794 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2796 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2799 /* Delete function for a quick_file_names. */
2802 delete_file_name_entry (void *e
)
2804 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2807 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2809 xfree ((void*) file_data
->file_names
[i
]);
2810 if (file_data
->real_names
)
2811 xfree ((void*) file_data
->real_names
[i
]);
2814 /* The space for the struct itself lives on objfile_obstack,
2815 so we don't free it here. */
2818 /* Create a quick_file_names hash table. */
2821 create_quick_file_names_table (unsigned int nr_initial_entries
)
2823 return htab_create_alloc (nr_initial_entries
,
2824 hash_file_name_entry
, eq_file_name_entry
,
2825 delete_file_name_entry
, xcalloc
, xfree
);
2828 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2829 have to be created afterwards. You should call age_cached_comp_units after
2830 processing PER_CU->CU. dw2_setup must have been already called. */
2833 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2835 if (per_cu
->is_debug_types
)
2836 load_full_type_unit (per_cu
);
2838 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2840 if (per_cu
->cu
== NULL
)
2841 return; /* Dummy CU. */
2843 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2846 /* Read in the symbols for PER_CU. */
2849 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2851 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2853 /* Skip type_unit_groups, reading the type units they contain
2854 is handled elsewhere. */
2855 if (IS_TYPE_UNIT_GROUP (per_cu
))
2858 /* The destructor of dwarf2_queue_guard frees any entries left on
2859 the queue. After this point we're guaranteed to leave this function
2860 with the dwarf queue empty. */
2861 dwarf2_queue_guard q_guard
;
2863 if (dwarf2_per_objfile
->using_index
2864 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2865 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2867 queue_comp_unit (per_cu
, language_minimal
);
2868 load_cu (per_cu
, skip_partial
);
2870 /* If we just loaded a CU from a DWO, and we're working with an index
2871 that may badly handle TUs, load all the TUs in that DWO as well.
2872 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2873 if (!per_cu
->is_debug_types
2874 && per_cu
->cu
!= NULL
2875 && per_cu
->cu
->dwo_unit
!= NULL
2876 && dwarf2_per_objfile
->index_table
!= NULL
2877 && dwarf2_per_objfile
->index_table
->version
<= 7
2878 /* DWP files aren't supported yet. */
2879 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2880 queue_and_load_all_dwo_tus (per_cu
);
2883 process_queue (dwarf2_per_objfile
);
2885 /* Age the cache, releasing compilation units that have not
2886 been used recently. */
2887 age_cached_comp_units (dwarf2_per_objfile
);
2890 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2891 the objfile from which this CU came. Returns the resulting symbol
2894 static struct compunit_symtab
*
2895 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2897 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2899 gdb_assert (dwarf2_per_objfile
->using_index
);
2900 if (!per_cu
->v
.quick
->compunit_symtab
)
2902 free_cached_comp_units
freer (dwarf2_per_objfile
);
2903 scoped_restore decrementer
= increment_reading_symtab ();
2904 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2905 process_cu_includes (dwarf2_per_objfile
);
2908 return per_cu
->v
.quick
->compunit_symtab
;
2911 /* See declaration. */
2913 dwarf2_per_cu_data
*
2914 dwarf2_per_objfile::get_cutu (int index
)
2916 if (index
>= this->all_comp_units
.size ())
2918 index
-= this->all_comp_units
.size ();
2919 gdb_assert (index
< this->all_type_units
.size ());
2920 return &this->all_type_units
[index
]->per_cu
;
2923 return this->all_comp_units
[index
];
2926 /* See declaration. */
2928 dwarf2_per_cu_data
*
2929 dwarf2_per_objfile::get_cu (int index
)
2931 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2933 return this->all_comp_units
[index
];
2936 /* See declaration. */
2939 dwarf2_per_objfile::get_tu (int index
)
2941 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2943 return this->all_type_units
[index
];
2946 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2947 objfile_obstack, and constructed with the specified field
2950 static dwarf2_per_cu_data
*
2951 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2952 struct dwarf2_section_info
*section
,
2954 sect_offset sect_off
, ULONGEST length
)
2956 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2957 dwarf2_per_cu_data
*the_cu
2958 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2959 struct dwarf2_per_cu_data
);
2960 the_cu
->sect_off
= sect_off
;
2961 the_cu
->length
= length
;
2962 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2963 the_cu
->section
= section
;
2964 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2965 struct dwarf2_per_cu_quick_data
);
2966 the_cu
->is_dwz
= is_dwz
;
2970 /* A helper for create_cus_from_index that handles a given list of
2974 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2975 const gdb_byte
*cu_list
, offset_type n_elements
,
2976 struct dwarf2_section_info
*section
,
2979 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2981 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2983 sect_offset sect_off
2984 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2985 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2988 dwarf2_per_cu_data
*per_cu
2989 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2991 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2995 /* Read the CU list from the mapped index, and use it to create all
2996 the CU objects for this objfile. */
2999 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3000 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3001 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3003 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3004 dwarf2_per_objfile
->all_comp_units
.reserve
3005 ((cu_list_elements
+ dwz_elements
) / 2);
3007 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3008 &dwarf2_per_objfile
->info
, 0);
3010 if (dwz_elements
== 0)
3013 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3014 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3018 /* Create the signatured type hash table from the index. */
3021 create_signatured_type_table_from_index
3022 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3023 struct dwarf2_section_info
*section
,
3024 const gdb_byte
*bytes
,
3025 offset_type elements
)
3027 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3029 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3030 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3032 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3034 for (offset_type i
= 0; i
< elements
; i
+= 3)
3036 struct signatured_type
*sig_type
;
3039 cu_offset type_offset_in_tu
;
3041 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3042 sect_offset sect_off
3043 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3045 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3047 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3050 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3051 struct signatured_type
);
3052 sig_type
->signature
= signature
;
3053 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3054 sig_type
->per_cu
.is_debug_types
= 1;
3055 sig_type
->per_cu
.section
= section
;
3056 sig_type
->per_cu
.sect_off
= sect_off
;
3057 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3058 sig_type
->per_cu
.v
.quick
3059 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3060 struct dwarf2_per_cu_quick_data
);
3062 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3065 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3068 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3071 /* Create the signatured type hash table from .debug_names. */
3074 create_signatured_type_table_from_debug_names
3075 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3076 const mapped_debug_names
&map
,
3077 struct dwarf2_section_info
*section
,
3078 struct dwarf2_section_info
*abbrev_section
)
3080 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3082 dwarf2_read_section (objfile
, section
);
3083 dwarf2_read_section (objfile
, abbrev_section
);
3085 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3086 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3088 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3090 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3092 struct signatured_type
*sig_type
;
3095 sect_offset sect_off
3096 = (sect_offset
) (extract_unsigned_integer
3097 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3099 map
.dwarf5_byte_order
));
3101 comp_unit_head cu_header
;
3102 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3104 section
->buffer
+ to_underlying (sect_off
),
3107 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3108 struct signatured_type
);
3109 sig_type
->signature
= cu_header
.signature
;
3110 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3111 sig_type
->per_cu
.is_debug_types
= 1;
3112 sig_type
->per_cu
.section
= section
;
3113 sig_type
->per_cu
.sect_off
= sect_off
;
3114 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3115 sig_type
->per_cu
.v
.quick
3116 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3117 struct dwarf2_per_cu_quick_data
);
3119 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3122 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3125 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3128 /* Read the address map data from the mapped index, and use it to
3129 populate the objfile's psymtabs_addrmap. */
3132 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3133 struct mapped_index
*index
)
3135 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3136 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3137 const gdb_byte
*iter
, *end
;
3138 struct addrmap
*mutable_map
;
3141 auto_obstack temp_obstack
;
3143 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3145 iter
= index
->address_table
.data ();
3146 end
= iter
+ index
->address_table
.size ();
3148 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3152 ULONGEST hi
, lo
, cu_index
;
3153 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3155 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3157 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3162 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
3163 hex_string (lo
), hex_string (hi
));
3167 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3169 complaint (_(".gdb_index address table has invalid CU number %u"),
3170 (unsigned) cu_index
);
3174 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
3175 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
3176 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3177 dwarf2_per_objfile
->get_cu (cu_index
));
3180 objfile
->partial_symtabs
->psymtabs_addrmap
3181 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3184 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3185 populate the objfile's psymtabs_addrmap. */
3188 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3189 struct dwarf2_section_info
*section
)
3191 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3192 bfd
*abfd
= objfile
->obfd
;
3193 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3194 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3195 SECT_OFF_TEXT (objfile
));
3197 auto_obstack temp_obstack
;
3198 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3200 std::unordered_map
<sect_offset
,
3201 dwarf2_per_cu_data
*,
3202 gdb::hash_enum
<sect_offset
>>
3203 debug_info_offset_to_per_cu
;
3204 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3206 const auto insertpair
3207 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3208 if (!insertpair
.second
)
3210 warning (_("Section .debug_aranges in %s has duplicate "
3211 "debug_info_offset %s, ignoring .debug_aranges."),
3212 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3217 dwarf2_read_section (objfile
, section
);
3219 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3221 const gdb_byte
*addr
= section
->buffer
;
3223 while (addr
< section
->buffer
+ section
->size
)
3225 const gdb_byte
*const entry_addr
= addr
;
3226 unsigned int bytes_read
;
3228 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3232 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3233 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3234 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3235 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3237 warning (_("Section .debug_aranges in %s entry at offset %s "
3238 "length %s exceeds section length %s, "
3239 "ignoring .debug_aranges."),
3240 objfile_name (objfile
),
3241 plongest (entry_addr
- section
->buffer
),
3242 plongest (bytes_read
+ entry_length
),
3243 pulongest (section
->size
));
3247 /* The version number. */
3248 const uint16_t version
= read_2_bytes (abfd
, addr
);
3252 warning (_("Section .debug_aranges in %s entry at offset %s "
3253 "has unsupported version %d, ignoring .debug_aranges."),
3254 objfile_name (objfile
),
3255 plongest (entry_addr
- section
->buffer
), version
);
3259 const uint64_t debug_info_offset
3260 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3261 addr
+= offset_size
;
3262 const auto per_cu_it
3263 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3264 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3266 warning (_("Section .debug_aranges in %s entry at offset %s "
3267 "debug_info_offset %s does not exists, "
3268 "ignoring .debug_aranges."),
3269 objfile_name (objfile
),
3270 plongest (entry_addr
- section
->buffer
),
3271 pulongest (debug_info_offset
));
3274 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3276 const uint8_t address_size
= *addr
++;
3277 if (address_size
< 1 || address_size
> 8)
3279 warning (_("Section .debug_aranges in %s entry at offset %s "
3280 "address_size %u is invalid, ignoring .debug_aranges."),
3281 objfile_name (objfile
),
3282 plongest (entry_addr
- section
->buffer
), address_size
);
3286 const uint8_t segment_selector_size
= *addr
++;
3287 if (segment_selector_size
!= 0)
3289 warning (_("Section .debug_aranges in %s entry at offset %s "
3290 "segment_selector_size %u is not supported, "
3291 "ignoring .debug_aranges."),
3292 objfile_name (objfile
),
3293 plongest (entry_addr
- section
->buffer
),
3294 segment_selector_size
);
3298 /* Must pad to an alignment boundary that is twice the address
3299 size. It is undocumented by the DWARF standard but GCC does
3301 for (size_t padding
= ((-(addr
- section
->buffer
))
3302 & (2 * address_size
- 1));
3303 padding
> 0; padding
--)
3306 warning (_("Section .debug_aranges in %s entry at offset %s "
3307 "padding is not zero, ignoring .debug_aranges."),
3308 objfile_name (objfile
),
3309 plongest (entry_addr
- section
->buffer
));
3315 if (addr
+ 2 * address_size
> entry_end
)
3317 warning (_("Section .debug_aranges in %s entry at offset %s "
3318 "address list is not properly terminated, "
3319 "ignoring .debug_aranges."),
3320 objfile_name (objfile
),
3321 plongest (entry_addr
- section
->buffer
));
3324 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3326 addr
+= address_size
;
3327 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3329 addr
+= address_size
;
3330 if (start
== 0 && length
== 0)
3332 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3334 /* Symbol was eliminated due to a COMDAT group. */
3337 ULONGEST end
= start
+ length
;
3338 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3340 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3342 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3346 objfile
->partial_symtabs
->psymtabs_addrmap
3347 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3350 /* Find a slot in the mapped index INDEX for the object named NAME.
3351 If NAME is found, set *VEC_OUT to point to the CU vector in the
3352 constant pool and return true. If NAME cannot be found, return
3356 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3357 offset_type
**vec_out
)
3360 offset_type slot
, step
;
3361 int (*cmp
) (const char *, const char *);
3363 gdb::unique_xmalloc_ptr
<char> without_params
;
3364 if (current_language
->la_language
== language_cplus
3365 || current_language
->la_language
== language_fortran
3366 || current_language
->la_language
== language_d
)
3368 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3371 if (strchr (name
, '(') != NULL
)
3373 without_params
= cp_remove_params (name
);
3375 if (without_params
!= NULL
)
3376 name
= without_params
.get ();
3380 /* Index version 4 did not support case insensitive searches. But the
3381 indices for case insensitive languages are built in lowercase, therefore
3382 simulate our NAME being searched is also lowercased. */
3383 hash
= mapped_index_string_hash ((index
->version
== 4
3384 && case_sensitivity
== case_sensitive_off
3385 ? 5 : index
->version
),
3388 slot
= hash
& (index
->symbol_table
.size () - 1);
3389 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3390 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3396 const auto &bucket
= index
->symbol_table
[slot
];
3397 if (bucket
.name
== 0 && bucket
.vec
== 0)
3400 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3401 if (!cmp (name
, str
))
3403 *vec_out
= (offset_type
*) (index
->constant_pool
3404 + MAYBE_SWAP (bucket
.vec
));
3408 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3412 /* A helper function that reads the .gdb_index from BUFFER and fills
3413 in MAP. FILENAME is the name of the file containing the data;
3414 it is used for error reporting. DEPRECATED_OK is true if it is
3415 ok to use deprecated sections.
3417 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3418 out parameters that are filled in with information about the CU and
3419 TU lists in the section.
3421 Returns true if all went well, false otherwise. */
3424 read_gdb_index_from_buffer (struct objfile
*objfile
,
3425 const char *filename
,
3427 gdb::array_view
<const gdb_byte
> buffer
,
3428 struct mapped_index
*map
,
3429 const gdb_byte
**cu_list
,
3430 offset_type
*cu_list_elements
,
3431 const gdb_byte
**types_list
,
3432 offset_type
*types_list_elements
)
3434 const gdb_byte
*addr
= &buffer
[0];
3436 /* Version check. */
3437 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3438 /* Versions earlier than 3 emitted every copy of a psymbol. This
3439 causes the index to behave very poorly for certain requests. Version 3
3440 contained incomplete addrmap. So, it seems better to just ignore such
3444 static int warning_printed
= 0;
3445 if (!warning_printed
)
3447 warning (_("Skipping obsolete .gdb_index section in %s."),
3449 warning_printed
= 1;
3453 /* Index version 4 uses a different hash function than index version
3456 Versions earlier than 6 did not emit psymbols for inlined
3457 functions. Using these files will cause GDB not to be able to
3458 set breakpoints on inlined functions by name, so we ignore these
3459 indices unless the user has done
3460 "set use-deprecated-index-sections on". */
3461 if (version
< 6 && !deprecated_ok
)
3463 static int warning_printed
= 0;
3464 if (!warning_printed
)
3467 Skipping deprecated .gdb_index section in %s.\n\
3468 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3469 to use the section anyway."),
3471 warning_printed
= 1;
3475 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3476 of the TU (for symbols coming from TUs),
3477 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3478 Plus gold-generated indices can have duplicate entries for global symbols,
3479 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3480 These are just performance bugs, and we can't distinguish gdb-generated
3481 indices from gold-generated ones, so issue no warning here. */
3483 /* Indexes with higher version than the one supported by GDB may be no
3484 longer backward compatible. */
3488 map
->version
= version
;
3490 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3493 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3494 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3498 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3499 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3500 - MAYBE_SWAP (metadata
[i
]))
3504 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3505 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3507 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3510 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3511 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3513 = gdb::array_view
<mapped_index::symbol_table_slot
>
3514 ((mapped_index::symbol_table_slot
*) symbol_table
,
3515 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3518 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3523 /* Callback types for dwarf2_read_gdb_index. */
3525 typedef gdb::function_view
3526 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3527 get_gdb_index_contents_ftype
;
3528 typedef gdb::function_view
3529 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3530 get_gdb_index_contents_dwz_ftype
;
3532 /* Read .gdb_index. If everything went ok, initialize the "quick"
3533 elements of all the CUs and return 1. Otherwise, return 0. */
3536 dwarf2_read_gdb_index
3537 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3538 get_gdb_index_contents_ftype get_gdb_index_contents
,
3539 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3541 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3542 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3543 struct dwz_file
*dwz
;
3544 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3546 gdb::array_view
<const gdb_byte
> main_index_contents
3547 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3549 if (main_index_contents
.empty ())
3552 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3553 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3554 use_deprecated_index_sections
,
3555 main_index_contents
, map
.get (), &cu_list
,
3556 &cu_list_elements
, &types_list
,
3557 &types_list_elements
))
3560 /* Don't use the index if it's empty. */
3561 if (map
->symbol_table
.empty ())
3564 /* If there is a .dwz file, read it so we can get its CU list as
3566 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3569 struct mapped_index dwz_map
;
3570 const gdb_byte
*dwz_types_ignore
;
3571 offset_type dwz_types_elements_ignore
;
3573 gdb::array_view
<const gdb_byte
> dwz_index_content
3574 = get_gdb_index_contents_dwz (objfile
, dwz
);
3576 if (dwz_index_content
.empty ())
3579 if (!read_gdb_index_from_buffer (objfile
,
3580 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3581 1, dwz_index_content
, &dwz_map
,
3582 &dwz_list
, &dwz_list_elements
,
3584 &dwz_types_elements_ignore
))
3586 warning (_("could not read '.gdb_index' section from %s; skipping"),
3587 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3592 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3593 dwz_list
, dwz_list_elements
);
3595 if (types_list_elements
)
3597 /* We can only handle a single .debug_types when we have an
3599 if (dwarf2_per_objfile
->types
.size () != 1)
3602 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3604 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3605 types_list
, types_list_elements
);
3608 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3610 dwarf2_per_objfile
->index_table
= std::move (map
);
3611 dwarf2_per_objfile
->using_index
= 1;
3612 dwarf2_per_objfile
->quick_file_names_table
=
3613 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3618 /* die_reader_func for dw2_get_file_names. */
3621 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3622 const gdb_byte
*info_ptr
,
3623 struct die_info
*comp_unit_die
,
3627 struct dwarf2_cu
*cu
= reader
->cu
;
3628 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3629 struct dwarf2_per_objfile
*dwarf2_per_objfile
3630 = cu
->per_cu
->dwarf2_per_objfile
;
3631 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3632 struct dwarf2_per_cu_data
*lh_cu
;
3633 struct attribute
*attr
;
3636 struct quick_file_names
*qfn
;
3638 gdb_assert (! this_cu
->is_debug_types
);
3640 /* Our callers never want to match partial units -- instead they
3641 will match the enclosing full CU. */
3642 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3644 this_cu
->v
.quick
->no_file_data
= 1;
3652 sect_offset line_offset
{};
3654 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3657 struct quick_file_names find_entry
;
3659 line_offset
= (sect_offset
) DW_UNSND (attr
);
3661 /* We may have already read in this line header (TU line header sharing).
3662 If we have we're done. */
3663 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3664 find_entry
.hash
.line_sect_off
= line_offset
;
3665 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3666 &find_entry
, INSERT
);
3669 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3673 lh
= dwarf_decode_line_header (line_offset
, cu
);
3677 lh_cu
->v
.quick
->no_file_data
= 1;
3681 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3682 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3683 qfn
->hash
.line_sect_off
= line_offset
;
3684 gdb_assert (slot
!= NULL
);
3687 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3690 if (strcmp (fnd
.name
, "<unknown>") != 0)
3693 qfn
->num_file_names
= offset
+ lh
->file_names
.size ();
3695 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3697 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3698 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3699 qfn
->file_names
[i
+ offset
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3700 qfn
->real_names
= NULL
;
3702 lh_cu
->v
.quick
->file_names
= qfn
;
3705 /* A helper for the "quick" functions which attempts to read the line
3706 table for THIS_CU. */
3708 static struct quick_file_names
*
3709 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3711 /* This should never be called for TUs. */
3712 gdb_assert (! this_cu
->is_debug_types
);
3713 /* Nor type unit groups. */
3714 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3716 if (this_cu
->v
.quick
->file_names
!= NULL
)
3717 return this_cu
->v
.quick
->file_names
;
3718 /* If we know there is no line data, no point in looking again. */
3719 if (this_cu
->v
.quick
->no_file_data
)
3722 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3724 if (this_cu
->v
.quick
->no_file_data
)
3726 return this_cu
->v
.quick
->file_names
;
3729 /* A helper for the "quick" functions which computes and caches the
3730 real path for a given file name from the line table. */
3733 dw2_get_real_path (struct objfile
*objfile
,
3734 struct quick_file_names
*qfn
, int index
)
3736 if (qfn
->real_names
== NULL
)
3737 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3738 qfn
->num_file_names
, const char *);
3740 if (qfn
->real_names
[index
] == NULL
)
3741 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3743 return qfn
->real_names
[index
];
3746 static struct symtab
*
3747 dw2_find_last_source_symtab (struct objfile
*objfile
)
3749 struct dwarf2_per_objfile
*dwarf2_per_objfile
3750 = get_dwarf2_per_objfile (objfile
);
3751 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3752 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3757 return compunit_primary_filetab (cust
);
3760 /* Traversal function for dw2_forget_cached_source_info. */
3763 dw2_free_cached_file_names (void **slot
, void *info
)
3765 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3767 if (file_data
->real_names
)
3771 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3773 xfree ((void*) file_data
->real_names
[i
]);
3774 file_data
->real_names
[i
] = NULL
;
3782 dw2_forget_cached_source_info (struct objfile
*objfile
)
3784 struct dwarf2_per_objfile
*dwarf2_per_objfile
3785 = get_dwarf2_per_objfile (objfile
);
3787 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3788 dw2_free_cached_file_names
, NULL
);
3791 /* Helper function for dw2_map_symtabs_matching_filename that expands
3792 the symtabs and calls the iterator. */
3795 dw2_map_expand_apply (struct objfile
*objfile
,
3796 struct dwarf2_per_cu_data
*per_cu
,
3797 const char *name
, const char *real_path
,
3798 gdb::function_view
<bool (symtab
*)> callback
)
3800 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3802 /* Don't visit already-expanded CUs. */
3803 if (per_cu
->v
.quick
->compunit_symtab
)
3806 /* This may expand more than one symtab, and we want to iterate over
3808 dw2_instantiate_symtab (per_cu
, false);
3810 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3811 last_made
, callback
);
3814 /* Implementation of the map_symtabs_matching_filename method. */
3817 dw2_map_symtabs_matching_filename
3818 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3819 gdb::function_view
<bool (symtab
*)> callback
)
3821 const char *name_basename
= lbasename (name
);
3822 struct dwarf2_per_objfile
*dwarf2_per_objfile
3823 = get_dwarf2_per_objfile (objfile
);
3825 /* The rule is CUs specify all the files, including those used by
3826 any TU, so there's no need to scan TUs here. */
3828 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3830 /* We only need to look at symtabs not already expanded. */
3831 if (per_cu
->v
.quick
->compunit_symtab
)
3834 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3835 if (file_data
== NULL
)
3838 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3840 const char *this_name
= file_data
->file_names
[j
];
3841 const char *this_real_name
;
3843 if (compare_filenames_for_search (this_name
, name
))
3845 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3851 /* Before we invoke realpath, which can get expensive when many
3852 files are involved, do a quick comparison of the basenames. */
3853 if (! basenames_may_differ
3854 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3857 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3858 if (compare_filenames_for_search (this_real_name
, name
))
3860 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3866 if (real_path
!= NULL
)
3868 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3869 gdb_assert (IS_ABSOLUTE_PATH (name
));
3870 if (this_real_name
!= NULL
3871 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3873 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3885 /* Struct used to manage iterating over all CUs looking for a symbol. */
3887 struct dw2_symtab_iterator
3889 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3890 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3891 /* If set, only look for symbols that match that block. Valid values are
3892 GLOBAL_BLOCK and STATIC_BLOCK. */
3893 gdb::optional
<block_enum
> block_index
;
3894 /* The kind of symbol we're looking for. */
3896 /* The list of CUs from the index entry of the symbol,
3897 or NULL if not found. */
3899 /* The next element in VEC to look at. */
3901 /* The number of elements in VEC, or zero if there is no match. */
3903 /* Have we seen a global version of the symbol?
3904 If so we can ignore all further global instances.
3905 This is to work around gold/15646, inefficient gold-generated
3910 /* Initialize the index symtab iterator ITER. */
3913 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3914 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3915 gdb::optional
<block_enum
> block_index
,
3919 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3920 iter
->block_index
= block_index
;
3921 iter
->domain
= domain
;
3923 iter
->global_seen
= 0;
3925 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3927 /* index is NULL if OBJF_READNOW. */
3928 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3929 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3937 /* Return the next matching CU or NULL if there are no more. */
3939 static struct dwarf2_per_cu_data
*
3940 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3942 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3944 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3946 offset_type cu_index_and_attrs
=
3947 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3948 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3949 gdb_index_symbol_kind symbol_kind
=
3950 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3951 /* Only check the symbol attributes if they're present.
3952 Indices prior to version 7 don't record them,
3953 and indices >= 7 may elide them for certain symbols
3954 (gold does this). */
3956 (dwarf2_per_objfile
->index_table
->version
>= 7
3957 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3959 /* Don't crash on bad data. */
3960 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3961 + dwarf2_per_objfile
->all_type_units
.size ()))
3963 complaint (_(".gdb_index entry has bad CU index"
3965 objfile_name (dwarf2_per_objfile
->objfile
));
3969 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3971 /* Skip if already read in. */
3972 if (per_cu
->v
.quick
->compunit_symtab
)
3975 /* Check static vs global. */
3978 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3980 if (iter
->block_index
.has_value ())
3982 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3984 if (is_static
!= want_static
)
3988 /* Work around gold/15646. */
3989 if (!is_static
&& iter
->global_seen
)
3992 iter
->global_seen
= 1;
3995 /* Only check the symbol's kind if it has one. */
3998 switch (iter
->domain
)
4001 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4002 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4003 /* Some types are also in VAR_DOMAIN. */
4004 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4008 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4012 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4027 static struct compunit_symtab
*
4028 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
4029 const char *name
, domain_enum domain
)
4031 struct compunit_symtab
*stab_best
= NULL
;
4032 struct dwarf2_per_objfile
*dwarf2_per_objfile
4033 = get_dwarf2_per_objfile (objfile
);
4035 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4037 struct dw2_symtab_iterator iter
;
4038 struct dwarf2_per_cu_data
*per_cu
;
4040 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
4042 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4044 struct symbol
*sym
, *with_opaque
= NULL
;
4045 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4046 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4047 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4049 sym
= block_find_symbol (block
, name
, domain
,
4050 block_find_non_opaque_type_preferred
,
4053 /* Some caution must be observed with overloaded functions
4054 and methods, since the index will not contain any overload
4055 information (but NAME might contain it). */
4058 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4060 if (with_opaque
!= NULL
4061 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4064 /* Keep looking through other CUs. */
4071 dw2_print_stats (struct objfile
*objfile
)
4073 struct dwarf2_per_objfile
*dwarf2_per_objfile
4074 = get_dwarf2_per_objfile (objfile
);
4075 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4076 + dwarf2_per_objfile
->all_type_units
.size ());
4079 for (int i
= 0; i
< total
; ++i
)
4081 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4083 if (!per_cu
->v
.quick
->compunit_symtab
)
4086 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4087 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4090 /* This dumps minimal information about the index.
4091 It is called via "mt print objfiles".
4092 One use is to verify .gdb_index has been loaded by the
4093 gdb.dwarf2/gdb-index.exp testcase. */
4096 dw2_dump (struct objfile
*objfile
)
4098 struct dwarf2_per_objfile
*dwarf2_per_objfile
4099 = get_dwarf2_per_objfile (objfile
);
4101 gdb_assert (dwarf2_per_objfile
->using_index
);
4102 printf_filtered (".gdb_index:");
4103 if (dwarf2_per_objfile
->index_table
!= NULL
)
4105 printf_filtered (" version %d\n",
4106 dwarf2_per_objfile
->index_table
->version
);
4109 printf_filtered (" faked for \"readnow\"\n");
4110 printf_filtered ("\n");
4114 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4115 const char *func_name
)
4117 struct dwarf2_per_objfile
*dwarf2_per_objfile
4118 = get_dwarf2_per_objfile (objfile
);
4120 struct dw2_symtab_iterator iter
;
4121 struct dwarf2_per_cu_data
*per_cu
;
4123 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
4125 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4126 dw2_instantiate_symtab (per_cu
, false);
4131 dw2_expand_all_symtabs (struct objfile
*objfile
)
4133 struct dwarf2_per_objfile
*dwarf2_per_objfile
4134 = get_dwarf2_per_objfile (objfile
);
4135 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4136 + dwarf2_per_objfile
->all_type_units
.size ());
4138 for (int i
= 0; i
< total_units
; ++i
)
4140 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4142 /* We don't want to directly expand a partial CU, because if we
4143 read it with the wrong language, then assertion failures can
4144 be triggered later on. See PR symtab/23010. So, tell
4145 dw2_instantiate_symtab to skip partial CUs -- any important
4146 partial CU will be read via DW_TAG_imported_unit anyway. */
4147 dw2_instantiate_symtab (per_cu
, true);
4152 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4153 const char *fullname
)
4155 struct dwarf2_per_objfile
*dwarf2_per_objfile
4156 = get_dwarf2_per_objfile (objfile
);
4158 /* We don't need to consider type units here.
4159 This is only called for examining code, e.g. expand_line_sal.
4160 There can be an order of magnitude (or more) more type units
4161 than comp units, and we avoid them if we can. */
4163 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4165 /* We only need to look at symtabs not already expanded. */
4166 if (per_cu
->v
.quick
->compunit_symtab
)
4169 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4170 if (file_data
== NULL
)
4173 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4175 const char *this_fullname
= file_data
->file_names
[j
];
4177 if (filename_cmp (this_fullname
, fullname
) == 0)
4179 dw2_instantiate_symtab (per_cu
, false);
4187 dw2_map_matching_symbols
4188 (struct objfile
*objfile
,
4189 const lookup_name_info
&name
, domain_enum domain
,
4191 gdb::function_view
<symbol_found_callback_ftype
> callback
,
4192 symbol_compare_ftype
*ordered_compare
)
4194 /* Currently unimplemented; used for Ada. The function can be called if the
4195 current language is Ada for a non-Ada objfile using GNU index. As Ada
4196 does not look for non-Ada symbols this function should just return. */
4199 /* Starting from a search name, return the string that finds the upper
4200 bound of all strings that start with SEARCH_NAME in a sorted name
4201 list. Returns the empty string to indicate that the upper bound is
4202 the end of the list. */
4205 make_sort_after_prefix_name (const char *search_name
)
4207 /* When looking to complete "func", we find the upper bound of all
4208 symbols that start with "func" by looking for where we'd insert
4209 the closest string that would follow "func" in lexicographical
4210 order. Usually, that's "func"-with-last-character-incremented,
4211 i.e. "fund". Mind non-ASCII characters, though. Usually those
4212 will be UTF-8 multi-byte sequences, but we can't be certain.
4213 Especially mind the 0xff character, which is a valid character in
4214 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4215 rule out compilers allowing it in identifiers. Note that
4216 conveniently, strcmp/strcasecmp are specified to compare
4217 characters interpreted as unsigned char. So what we do is treat
4218 the whole string as a base 256 number composed of a sequence of
4219 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4220 to 0, and carries 1 to the following more-significant position.
4221 If the very first character in SEARCH_NAME ends up incremented
4222 and carries/overflows, then the upper bound is the end of the
4223 list. The string after the empty string is also the empty
4226 Some examples of this operation:
4228 SEARCH_NAME => "+1" RESULT
4232 "\xff" "a" "\xff" => "\xff" "b"
4237 Then, with these symbols for example:
4243 completing "func" looks for symbols between "func" and
4244 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4245 which finds "func" and "func1", but not "fund".
4249 funcÿ (Latin1 'ÿ' [0xff])
4253 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4254 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4258 ÿÿ (Latin1 'ÿ' [0xff])
4261 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4262 the end of the list.
4264 std::string after
= search_name
;
4265 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4267 if (!after
.empty ())
4268 after
.back () = (unsigned char) after
.back () + 1;
4272 /* See declaration. */
4274 std::pair
<std::vector
<name_component
>::const_iterator
,
4275 std::vector
<name_component
>::const_iterator
>
4276 mapped_index_base::find_name_components_bounds
4277 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
4280 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4282 const char *lang_name
4283 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4285 /* Comparison function object for lower_bound that matches against a
4286 given symbol name. */
4287 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4290 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4291 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4292 return name_cmp (elem_name
, name
) < 0;
4295 /* Comparison function object for upper_bound that matches against a
4296 given symbol name. */
4297 auto lookup_compare_upper
= [&] (const char *name
,
4298 const name_component
&elem
)
4300 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4301 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4302 return name_cmp (name
, elem_name
) < 0;
4305 auto begin
= this->name_components
.begin ();
4306 auto end
= this->name_components
.end ();
4308 /* Find the lower bound. */
4311 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4314 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4317 /* Find the upper bound. */
4320 if (lookup_name_without_params
.completion_mode ())
4322 /* In completion mode, we want UPPER to point past all
4323 symbols names that have the same prefix. I.e., with
4324 these symbols, and completing "func":
4326 function << lower bound
4328 other_function << upper bound
4330 We find the upper bound by looking for the insertion
4331 point of "func"-with-last-character-incremented,
4333 std::string after
= make_sort_after_prefix_name (lang_name
);
4336 return std::lower_bound (lower
, end
, after
.c_str (),
4337 lookup_compare_lower
);
4340 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4343 return {lower
, upper
};
4346 /* See declaration. */
4349 mapped_index_base::build_name_components ()
4351 if (!this->name_components
.empty ())
4354 this->name_components_casing
= case_sensitivity
;
4356 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4358 /* The code below only knows how to break apart components of C++
4359 symbol names (and other languages that use '::' as
4360 namespace/module separator) and Ada symbol names. */
4361 auto count
= this->symbol_name_count ();
4362 for (offset_type idx
= 0; idx
< count
; idx
++)
4364 if (this->symbol_name_slot_invalid (idx
))
4367 const char *name
= this->symbol_name_at (idx
);
4369 /* Add each name component to the name component table. */
4370 unsigned int previous_len
= 0;
4372 if (strstr (name
, "::") != nullptr)
4374 for (unsigned int current_len
= cp_find_first_component (name
);
4375 name
[current_len
] != '\0';
4376 current_len
+= cp_find_first_component (name
+ current_len
))
4378 gdb_assert (name
[current_len
] == ':');
4379 this->name_components
.push_back ({previous_len
, idx
});
4380 /* Skip the '::'. */
4382 previous_len
= current_len
;
4387 /* Handle the Ada encoded (aka mangled) form here. */
4388 for (const char *iter
= strstr (name
, "__");
4390 iter
= strstr (iter
, "__"))
4392 this->name_components
.push_back ({previous_len
, idx
});
4394 previous_len
= iter
- name
;
4398 this->name_components
.push_back ({previous_len
, idx
});
4401 /* Sort name_components elements by name. */
4402 auto name_comp_compare
= [&] (const name_component
&left
,
4403 const name_component
&right
)
4405 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4406 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4408 const char *left_name
= left_qualified
+ left
.name_offset
;
4409 const char *right_name
= right_qualified
+ right
.name_offset
;
4411 return name_cmp (left_name
, right_name
) < 0;
4414 std::sort (this->name_components
.begin (),
4415 this->name_components
.end (),
4419 /* Helper for dw2_expand_symtabs_matching that works with a
4420 mapped_index_base instead of the containing objfile. This is split
4421 to a separate function in order to be able to unit test the
4422 name_components matching using a mock mapped_index_base. For each
4423 symbol name that matches, calls MATCH_CALLBACK, passing it the
4424 symbol's index in the mapped_index_base symbol table. */
4427 dw2_expand_symtabs_matching_symbol
4428 (mapped_index_base
&index
,
4429 const lookup_name_info
&lookup_name_in
,
4430 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4431 enum search_domain kind
,
4432 gdb::function_view
<bool (offset_type
)> match_callback
)
4434 lookup_name_info lookup_name_without_params
4435 = lookup_name_in
.make_ignore_params ();
4437 /* Build the symbol name component sorted vector, if we haven't
4439 index
.build_name_components ();
4441 /* The same symbol may appear more than once in the range though.
4442 E.g., if we're looking for symbols that complete "w", and we have
4443 a symbol named "w1::w2", we'll find the two name components for
4444 that same symbol in the range. To be sure we only call the
4445 callback once per symbol, we first collect the symbol name
4446 indexes that matched in a temporary vector and ignore
4448 std::vector
<offset_type
> matches
;
4450 struct name_and_matcher
4452 symbol_name_matcher_ftype
*matcher
;
4453 const std::string
&name
;
4455 bool operator== (const name_and_matcher
&other
) const
4457 return matcher
== other
.matcher
&& name
== other
.name
;
4461 /* A vector holding all the different symbol name matchers, for all
4463 std::vector
<name_and_matcher
> matchers
;
4465 for (int i
= 0; i
< nr_languages
; i
++)
4467 enum language lang_e
= (enum language
) i
;
4469 const language_defn
*lang
= language_def (lang_e
);
4470 symbol_name_matcher_ftype
*name_matcher
4471 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4473 name_and_matcher key
{
4475 lookup_name_without_params
.language_lookup_name (lang_e
)
4478 /* Don't insert the same comparison routine more than once.
4479 Note that we do this linear walk. This is not a problem in
4480 practice because the number of supported languages is
4482 if (std::find (matchers
.begin (), matchers
.end (), key
)
4485 matchers
.push_back (std::move (key
));
4488 = index
.find_name_components_bounds (lookup_name_without_params
,
4491 /* Now for each symbol name in range, check to see if we have a name
4492 match, and if so, call the MATCH_CALLBACK callback. */
4494 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4496 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4498 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4499 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4502 matches
.push_back (bounds
.first
->idx
);
4506 std::sort (matches
.begin (), matches
.end ());
4508 /* Finally call the callback, once per match. */
4510 for (offset_type idx
: matches
)
4514 if (!match_callback (idx
))
4520 /* Above we use a type wider than idx's for 'prev', since 0 and
4521 (offset_type)-1 are both possible values. */
4522 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4527 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4529 /* A mock .gdb_index/.debug_names-like name index table, enough to
4530 exercise dw2_expand_symtabs_matching_symbol, which works with the
4531 mapped_index_base interface. Builds an index from the symbol list
4532 passed as parameter to the constructor. */
4533 class mock_mapped_index
: public mapped_index_base
4536 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4537 : m_symbol_table (symbols
)
4540 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4542 /* Return the number of names in the symbol table. */
4543 size_t symbol_name_count () const override
4545 return m_symbol_table
.size ();
4548 /* Get the name of the symbol at IDX in the symbol table. */
4549 const char *symbol_name_at (offset_type idx
) const override
4551 return m_symbol_table
[idx
];
4555 gdb::array_view
<const char *> m_symbol_table
;
4558 /* Convenience function that converts a NULL pointer to a "<null>"
4559 string, to pass to print routines. */
4562 string_or_null (const char *str
)
4564 return str
!= NULL
? str
: "<null>";
4567 /* Check if a lookup_name_info built from
4568 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4569 index. EXPECTED_LIST is the list of expected matches, in expected
4570 matching order. If no match expected, then an empty list is
4571 specified. Returns true on success. On failure prints a warning
4572 indicating the file:line that failed, and returns false. */
4575 check_match (const char *file
, int line
,
4576 mock_mapped_index
&mock_index
,
4577 const char *name
, symbol_name_match_type match_type
,
4578 bool completion_mode
,
4579 std::initializer_list
<const char *> expected_list
)
4581 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4583 bool matched
= true;
4585 auto mismatch
= [&] (const char *expected_str
,
4588 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4589 "expected=\"%s\", got=\"%s\"\n"),
4591 (match_type
== symbol_name_match_type::FULL
4593 name
, string_or_null (expected_str
), string_or_null (got
));
4597 auto expected_it
= expected_list
.begin ();
4598 auto expected_end
= expected_list
.end ();
4600 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4602 [&] (offset_type idx
)
4604 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4605 const char *expected_str
4606 = expected_it
== expected_end
? NULL
: *expected_it
++;
4608 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4609 mismatch (expected_str
, matched_name
);
4613 const char *expected_str
4614 = expected_it
== expected_end
? NULL
: *expected_it
++;
4615 if (expected_str
!= NULL
)
4616 mismatch (expected_str
, NULL
);
4621 /* The symbols added to the mock mapped_index for testing (in
4623 static const char *test_symbols
[] = {
4632 "ns2::tmpl<int>::foo2",
4633 "(anonymous namespace)::A::B::C",
4635 /* These are used to check that the increment-last-char in the
4636 matching algorithm for completion doesn't match "t1_fund" when
4637 completing "t1_func". */
4643 /* A UTF-8 name with multi-byte sequences to make sure that
4644 cp-name-parser understands this as a single identifier ("função"
4645 is "function" in PT). */
4648 /* \377 (0xff) is Latin1 'ÿ'. */
4651 /* \377 (0xff) is Latin1 'ÿ'. */
4655 /* A name with all sorts of complications. Starts with "z" to make
4656 it easier for the completion tests below. */
4657 #define Z_SYM_NAME \
4658 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4659 "::tuple<(anonymous namespace)::ui*, " \
4660 "std::default_delete<(anonymous namespace)::ui>, void>"
4665 /* Returns true if the mapped_index_base::find_name_component_bounds
4666 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4667 in completion mode. */
4670 check_find_bounds_finds (mapped_index_base
&index
,
4671 const char *search_name
,
4672 gdb::array_view
<const char *> expected_syms
)
4674 lookup_name_info
lookup_name (search_name
,
4675 symbol_name_match_type::FULL
, true);
4677 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4680 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4681 if (distance
!= expected_syms
.size ())
4684 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4686 auto nc_elem
= bounds
.first
+ exp_elem
;
4687 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4688 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4695 /* Test the lower-level mapped_index::find_name_component_bounds
4699 test_mapped_index_find_name_component_bounds ()
4701 mock_mapped_index
mock_index (test_symbols
);
4703 mock_index
.build_name_components ();
4705 /* Test the lower-level mapped_index::find_name_component_bounds
4706 method in completion mode. */
4708 static const char *expected_syms
[] = {
4713 SELF_CHECK (check_find_bounds_finds (mock_index
,
4714 "t1_func", expected_syms
));
4717 /* Check that the increment-last-char in the name matching algorithm
4718 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4720 static const char *expected_syms1
[] = {
4724 SELF_CHECK (check_find_bounds_finds (mock_index
,
4725 "\377", expected_syms1
));
4727 static const char *expected_syms2
[] = {
4730 SELF_CHECK (check_find_bounds_finds (mock_index
,
4731 "\377\377", expected_syms2
));
4735 /* Test dw2_expand_symtabs_matching_symbol. */
4738 test_dw2_expand_symtabs_matching_symbol ()
4740 mock_mapped_index
mock_index (test_symbols
);
4742 /* We let all tests run until the end even if some fails, for debug
4744 bool any_mismatch
= false;
4746 /* Create the expected symbols list (an initializer_list). Needed
4747 because lists have commas, and we need to pass them to CHECK,
4748 which is a macro. */
4749 #define EXPECT(...) { __VA_ARGS__ }
4751 /* Wrapper for check_match that passes down the current
4752 __FILE__/__LINE__. */
4753 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4754 any_mismatch |= !check_match (__FILE__, __LINE__, \
4756 NAME, MATCH_TYPE, COMPLETION_MODE, \
4759 /* Identity checks. */
4760 for (const char *sym
: test_symbols
)
4762 /* Should be able to match all existing symbols. */
4763 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4766 /* Should be able to match all existing symbols with
4768 std::string with_params
= std::string (sym
) + "(int)";
4769 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4772 /* Should be able to match all existing symbols with
4773 parameters and qualifiers. */
4774 with_params
= std::string (sym
) + " ( int ) const";
4775 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4778 /* This should really find sym, but cp-name-parser.y doesn't
4779 know about lvalue/rvalue qualifiers yet. */
4780 with_params
= std::string (sym
) + " ( int ) &&";
4781 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4785 /* Check that the name matching algorithm for completion doesn't get
4786 confused with Latin1 'ÿ' / 0xff. */
4788 static const char str
[] = "\377";
4789 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4790 EXPECT ("\377", "\377\377123"));
4793 /* Check that the increment-last-char in the matching algorithm for
4794 completion doesn't match "t1_fund" when completing "t1_func". */
4796 static const char str
[] = "t1_func";
4797 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4798 EXPECT ("t1_func", "t1_func1"));
4801 /* Check that completion mode works at each prefix of the expected
4804 static const char str
[] = "function(int)";
4805 size_t len
= strlen (str
);
4808 for (size_t i
= 1; i
< len
; i
++)
4810 lookup
.assign (str
, i
);
4811 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4812 EXPECT ("function"));
4816 /* While "w" is a prefix of both components, the match function
4817 should still only be called once. */
4819 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4821 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4825 /* Same, with a "complicated" symbol. */
4827 static const char str
[] = Z_SYM_NAME
;
4828 size_t len
= strlen (str
);
4831 for (size_t i
= 1; i
< len
; i
++)
4833 lookup
.assign (str
, i
);
4834 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4835 EXPECT (Z_SYM_NAME
));
4839 /* In FULL mode, an incomplete symbol doesn't match. */
4841 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4845 /* A complete symbol with parameters matches any overload, since the
4846 index has no overload info. */
4848 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4849 EXPECT ("std::zfunction", "std::zfunction2"));
4850 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4851 EXPECT ("std::zfunction", "std::zfunction2"));
4852 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4853 EXPECT ("std::zfunction", "std::zfunction2"));
4856 /* Check that whitespace is ignored appropriately. A symbol with a
4857 template argument list. */
4859 static const char expected
[] = "ns::foo<int>";
4860 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4862 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4866 /* Check that whitespace is ignored appropriately. A symbol with a
4867 template argument list that includes a pointer. */
4869 static const char expected
[] = "ns::foo<char*>";
4870 /* Try both completion and non-completion modes. */
4871 static const bool completion_mode
[2] = {false, true};
4872 for (size_t i
= 0; i
< 2; i
++)
4874 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4875 completion_mode
[i
], EXPECT (expected
));
4876 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4877 completion_mode
[i
], EXPECT (expected
));
4879 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4880 completion_mode
[i
], EXPECT (expected
));
4881 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4882 completion_mode
[i
], EXPECT (expected
));
4887 /* Check method qualifiers are ignored. */
4888 static const char expected
[] = "ns::foo<char*>";
4889 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4890 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4891 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4892 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4893 CHECK_MATCH ("foo < char * > ( int ) const",
4894 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4895 CHECK_MATCH ("foo < char * > ( int ) &&",
4896 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4899 /* Test lookup names that don't match anything. */
4901 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4904 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4908 /* Some wild matching tests, exercising "(anonymous namespace)",
4909 which should not be confused with a parameter list. */
4911 static const char *syms
[] = {
4915 "A :: B :: C ( int )",
4920 for (const char *s
: syms
)
4922 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4923 EXPECT ("(anonymous namespace)::A::B::C"));
4928 static const char expected
[] = "ns2::tmpl<int>::foo2";
4929 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4931 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4935 SELF_CHECK (!any_mismatch
);
4944 test_mapped_index_find_name_component_bounds ();
4945 test_dw2_expand_symtabs_matching_symbol ();
4948 }} // namespace selftests::dw2_expand_symtabs_matching
4950 #endif /* GDB_SELF_TEST */
4952 /* If FILE_MATCHER is NULL or if PER_CU has
4953 dwarf2_per_cu_quick_data::MARK set (see
4954 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4955 EXPANSION_NOTIFY on it. */
4958 dw2_expand_symtabs_matching_one
4959 (struct dwarf2_per_cu_data
*per_cu
,
4960 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4961 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4963 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4965 bool symtab_was_null
4966 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4968 dw2_instantiate_symtab (per_cu
, false);
4970 if (expansion_notify
!= NULL
4972 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4973 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4977 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4978 matched, to expand corresponding CUs that were marked. IDX is the
4979 index of the symbol name that matched. */
4982 dw2_expand_marked_cus
4983 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4984 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4985 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4988 offset_type
*vec
, vec_len
, vec_idx
;
4989 bool global_seen
= false;
4990 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4992 vec
= (offset_type
*) (index
.constant_pool
4993 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4994 vec_len
= MAYBE_SWAP (vec
[0]);
4995 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4997 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4998 /* This value is only valid for index versions >= 7. */
4999 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5000 gdb_index_symbol_kind symbol_kind
=
5001 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5002 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5003 /* Only check the symbol attributes if they're present.
5004 Indices prior to version 7 don't record them,
5005 and indices >= 7 may elide them for certain symbols
5006 (gold does this). */
5009 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5011 /* Work around gold/15646. */
5014 if (!is_static
&& global_seen
)
5020 /* Only check the symbol's kind if it has one. */
5025 case VARIABLES_DOMAIN
:
5026 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5029 case FUNCTIONS_DOMAIN
:
5030 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5034 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5042 /* Don't crash on bad data. */
5043 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5044 + dwarf2_per_objfile
->all_type_units
.size ()))
5046 complaint (_(".gdb_index entry has bad CU index"
5048 objfile_name (dwarf2_per_objfile
->objfile
));
5052 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5053 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5058 /* If FILE_MATCHER is non-NULL, set all the
5059 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5060 that match FILE_MATCHER. */
5063 dw_expand_symtabs_matching_file_matcher
5064 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5065 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5067 if (file_matcher
== NULL
)
5070 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5072 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5074 NULL
, xcalloc
, xfree
));
5075 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5077 NULL
, xcalloc
, xfree
));
5079 /* The rule is CUs specify all the files, including those used by
5080 any TU, so there's no need to scan TUs here. */
5082 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5086 per_cu
->v
.quick
->mark
= 0;
5088 /* We only need to look at symtabs not already expanded. */
5089 if (per_cu
->v
.quick
->compunit_symtab
)
5092 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5093 if (file_data
== NULL
)
5096 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5098 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5100 per_cu
->v
.quick
->mark
= 1;
5104 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5106 const char *this_real_name
;
5108 if (file_matcher (file_data
->file_names
[j
], false))
5110 per_cu
->v
.quick
->mark
= 1;
5114 /* Before we invoke realpath, which can get expensive when many
5115 files are involved, do a quick comparison of the basenames. */
5116 if (!basenames_may_differ
5117 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5121 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5122 if (file_matcher (this_real_name
, false))
5124 per_cu
->v
.quick
->mark
= 1;
5129 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5130 ? visited_found
.get ()
5131 : visited_not_found
.get (),
5138 dw2_expand_symtabs_matching
5139 (struct objfile
*objfile
,
5140 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5141 const lookup_name_info
&lookup_name
,
5142 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5143 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5144 enum search_domain kind
)
5146 struct dwarf2_per_objfile
*dwarf2_per_objfile
5147 = get_dwarf2_per_objfile (objfile
);
5149 /* index_table is NULL if OBJF_READNOW. */
5150 if (!dwarf2_per_objfile
->index_table
)
5153 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5155 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5157 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5159 kind
, [&] (offset_type idx
)
5161 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5162 expansion_notify
, kind
);
5167 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5170 static struct compunit_symtab
*
5171 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5176 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5177 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5180 if (cust
->includes
== NULL
)
5183 for (i
= 0; cust
->includes
[i
]; ++i
)
5185 struct compunit_symtab
*s
= cust
->includes
[i
];
5187 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5195 static struct compunit_symtab
*
5196 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5197 struct bound_minimal_symbol msymbol
,
5199 struct obj_section
*section
,
5202 struct dwarf2_per_cu_data
*data
;
5203 struct compunit_symtab
*result
;
5205 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5208 CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
5209 SECT_OFF_TEXT (objfile
));
5210 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5211 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5215 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5216 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5217 paddress (get_objfile_arch (objfile
), pc
));
5220 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5223 gdb_assert (result
!= NULL
);
5228 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5229 void *data
, int need_fullname
)
5231 struct dwarf2_per_objfile
*dwarf2_per_objfile
5232 = get_dwarf2_per_objfile (objfile
);
5234 if (!dwarf2_per_objfile
->filenames_cache
)
5236 dwarf2_per_objfile
->filenames_cache
.emplace ();
5238 htab_up
visited (htab_create_alloc (10,
5239 htab_hash_pointer
, htab_eq_pointer
,
5240 NULL
, xcalloc
, xfree
));
5242 /* The rule is CUs specify all the files, including those used
5243 by any TU, so there's no need to scan TUs here. We can
5244 ignore file names coming from already-expanded CUs. */
5246 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5248 if (per_cu
->v
.quick
->compunit_symtab
)
5250 void **slot
= htab_find_slot (visited
.get (),
5251 per_cu
->v
.quick
->file_names
,
5254 *slot
= per_cu
->v
.quick
->file_names
;
5258 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5260 /* We only need to look at symtabs not already expanded. */
5261 if (per_cu
->v
.quick
->compunit_symtab
)
5264 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5265 if (file_data
== NULL
)
5268 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5271 /* Already visited. */
5276 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5278 const char *filename
= file_data
->file_names
[j
];
5279 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5284 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5286 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5289 this_real_name
= gdb_realpath (filename
);
5290 (*fun
) (filename
, this_real_name
.get (), data
);
5295 dw2_has_symbols (struct objfile
*objfile
)
5300 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5303 dw2_find_last_source_symtab
,
5304 dw2_forget_cached_source_info
,
5305 dw2_map_symtabs_matching_filename
,
5309 dw2_expand_symtabs_for_function
,
5310 dw2_expand_all_symtabs
,
5311 dw2_expand_symtabs_with_fullname
,
5312 dw2_map_matching_symbols
,
5313 dw2_expand_symtabs_matching
,
5314 dw2_find_pc_sect_compunit_symtab
,
5316 dw2_map_symbol_filenames
5319 /* DWARF-5 debug_names reader. */
5321 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5322 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5324 /* A helper function that reads the .debug_names section in SECTION
5325 and fills in MAP. FILENAME is the name of the file containing the
5326 section; it is used for error reporting.
5328 Returns true if all went well, false otherwise. */
5331 read_debug_names_from_section (struct objfile
*objfile
,
5332 const char *filename
,
5333 struct dwarf2_section_info
*section
,
5334 mapped_debug_names
&map
)
5336 if (dwarf2_section_empty_p (section
))
5339 /* Older elfutils strip versions could keep the section in the main
5340 executable while splitting it for the separate debug info file. */
5341 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5344 dwarf2_read_section (objfile
, section
);
5346 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5348 const gdb_byte
*addr
= section
->buffer
;
5350 bfd
*const abfd
= get_section_bfd_owner (section
);
5352 unsigned int bytes_read
;
5353 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5356 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5357 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5358 if (bytes_read
+ length
!= section
->size
)
5360 /* There may be multiple per-CU indices. */
5361 warning (_("Section .debug_names in %s length %s does not match "
5362 "section length %s, ignoring .debug_names."),
5363 filename
, plongest (bytes_read
+ length
),
5364 pulongest (section
->size
));
5368 /* The version number. */
5369 uint16_t version
= read_2_bytes (abfd
, addr
);
5373 warning (_("Section .debug_names in %s has unsupported version %d, "
5374 "ignoring .debug_names."),
5380 uint16_t padding
= read_2_bytes (abfd
, addr
);
5384 warning (_("Section .debug_names in %s has unsupported padding %d, "
5385 "ignoring .debug_names."),
5390 /* comp_unit_count - The number of CUs in the CU list. */
5391 map
.cu_count
= read_4_bytes (abfd
, addr
);
5394 /* local_type_unit_count - The number of TUs in the local TU
5396 map
.tu_count
= read_4_bytes (abfd
, addr
);
5399 /* foreign_type_unit_count - The number of TUs in the foreign TU
5401 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5403 if (foreign_tu_count
!= 0)
5405 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5406 "ignoring .debug_names."),
5407 filename
, static_cast<unsigned long> (foreign_tu_count
));
5411 /* bucket_count - The number of hash buckets in the hash lookup
5413 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5416 /* name_count - The number of unique names in the index. */
5417 map
.name_count
= read_4_bytes (abfd
, addr
);
5420 /* abbrev_table_size - The size in bytes of the abbreviations
5422 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5425 /* augmentation_string_size - The size in bytes of the augmentation
5426 string. This value is rounded up to a multiple of 4. */
5427 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5429 map
.augmentation_is_gdb
= ((augmentation_string_size
5430 == sizeof (dwarf5_augmentation
))
5431 && memcmp (addr
, dwarf5_augmentation
,
5432 sizeof (dwarf5_augmentation
)) == 0);
5433 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5434 addr
+= augmentation_string_size
;
5437 map
.cu_table_reordered
= addr
;
5438 addr
+= map
.cu_count
* map
.offset_size
;
5440 /* List of Local TUs */
5441 map
.tu_table_reordered
= addr
;
5442 addr
+= map
.tu_count
* map
.offset_size
;
5444 /* Hash Lookup Table */
5445 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5446 addr
+= map
.bucket_count
* 4;
5447 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5448 addr
+= map
.name_count
* 4;
5451 map
.name_table_string_offs_reordered
= addr
;
5452 addr
+= map
.name_count
* map
.offset_size
;
5453 map
.name_table_entry_offs_reordered
= addr
;
5454 addr
+= map
.name_count
* map
.offset_size
;
5456 const gdb_byte
*abbrev_table_start
= addr
;
5459 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5464 const auto insertpair
5465 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5466 if (!insertpair
.second
)
5468 warning (_("Section .debug_names in %s has duplicate index %s, "
5469 "ignoring .debug_names."),
5470 filename
, pulongest (index_num
));
5473 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5474 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5479 mapped_debug_names::index_val::attr attr
;
5480 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5482 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5484 if (attr
.form
== DW_FORM_implicit_const
)
5486 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5490 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5492 indexval
.attr_vec
.push_back (std::move (attr
));
5495 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5497 warning (_("Section .debug_names in %s has abbreviation_table "
5498 "of size %s vs. written as %u, ignoring .debug_names."),
5499 filename
, plongest (addr
- abbrev_table_start
),
5503 map
.entry_pool
= addr
;
5508 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5512 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5513 const mapped_debug_names
&map
,
5514 dwarf2_section_info
§ion
,
5517 sect_offset sect_off_prev
;
5518 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5520 sect_offset sect_off_next
;
5521 if (i
< map
.cu_count
)
5524 = (sect_offset
) (extract_unsigned_integer
5525 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5527 map
.dwarf5_byte_order
));
5530 sect_off_next
= (sect_offset
) section
.size
;
5533 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5534 dwarf2_per_cu_data
*per_cu
5535 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5536 sect_off_prev
, length
);
5537 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5539 sect_off_prev
= sect_off_next
;
5543 /* Read the CU list from the mapped index, and use it to create all
5544 the CU objects for this dwarf2_per_objfile. */
5547 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5548 const mapped_debug_names
&map
,
5549 const mapped_debug_names
&dwz_map
)
5551 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5552 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5554 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5555 dwarf2_per_objfile
->info
,
5556 false /* is_dwz */);
5558 if (dwz_map
.cu_count
== 0)
5561 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5562 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5566 /* Read .debug_names. If everything went ok, initialize the "quick"
5567 elements of all the CUs and return true. Otherwise, return false. */
5570 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5572 std::unique_ptr
<mapped_debug_names
> map
5573 (new mapped_debug_names (dwarf2_per_objfile
));
5574 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5575 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5577 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5578 &dwarf2_per_objfile
->debug_names
,
5582 /* Don't use the index if it's empty. */
5583 if (map
->name_count
== 0)
5586 /* If there is a .dwz file, read it so we can get its CU list as
5588 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5591 if (!read_debug_names_from_section (objfile
,
5592 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5593 &dwz
->debug_names
, dwz_map
))
5595 warning (_("could not read '.debug_names' section from %s; skipping"),
5596 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5601 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5603 if (map
->tu_count
!= 0)
5605 /* We can only handle a single .debug_types when we have an
5607 if (dwarf2_per_objfile
->types
.size () != 1)
5610 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5612 create_signatured_type_table_from_debug_names
5613 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5616 create_addrmap_from_aranges (dwarf2_per_objfile
,
5617 &dwarf2_per_objfile
->debug_aranges
);
5619 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5620 dwarf2_per_objfile
->using_index
= 1;
5621 dwarf2_per_objfile
->quick_file_names_table
=
5622 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5627 /* Type used to manage iterating over all CUs looking for a symbol for
5630 class dw2_debug_names_iterator
5633 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5634 gdb::optional
<block_enum
> block_index
,
5637 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5638 m_addr (find_vec_in_debug_names (map
, name
))
5641 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5642 search_domain search
, uint32_t namei
)
5645 m_addr (find_vec_in_debug_names (map
, namei
))
5648 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5649 block_enum block_index
, domain_enum domain
,
5651 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5652 m_addr (find_vec_in_debug_names (map
, namei
))
5655 /* Return the next matching CU or NULL if there are no more. */
5656 dwarf2_per_cu_data
*next ();
5659 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5661 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5664 /* The internalized form of .debug_names. */
5665 const mapped_debug_names
&m_map
;
5667 /* If set, only look for symbols that match that block. Valid values are
5668 GLOBAL_BLOCK and STATIC_BLOCK. */
5669 const gdb::optional
<block_enum
> m_block_index
;
5671 /* The kind of symbol we're looking for. */
5672 const domain_enum m_domain
= UNDEF_DOMAIN
;
5673 const search_domain m_search
= ALL_DOMAIN
;
5675 /* The list of CUs from the index entry of the symbol, or NULL if
5677 const gdb_byte
*m_addr
;
5681 mapped_debug_names::namei_to_name (uint32_t namei
) const
5683 const ULONGEST namei_string_offs
5684 = extract_unsigned_integer ((name_table_string_offs_reordered
5685 + namei
* offset_size
),
5688 return read_indirect_string_at_offset
5689 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5692 /* Find a slot in .debug_names for the object named NAME. If NAME is
5693 found, return pointer to its pool data. If NAME cannot be found,
5697 dw2_debug_names_iterator::find_vec_in_debug_names
5698 (const mapped_debug_names
&map
, const char *name
)
5700 int (*cmp
) (const char *, const char *);
5702 gdb::unique_xmalloc_ptr
<char> without_params
;
5703 if (current_language
->la_language
== language_cplus
5704 || current_language
->la_language
== language_fortran
5705 || current_language
->la_language
== language_d
)
5707 /* NAME is already canonical. Drop any qualifiers as
5708 .debug_names does not contain any. */
5710 if (strchr (name
, '(') != NULL
)
5712 without_params
= cp_remove_params (name
);
5713 if (without_params
!= NULL
)
5714 name
= without_params
.get ();
5718 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5720 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5722 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5723 (map
.bucket_table_reordered
5724 + (full_hash
% map
.bucket_count
)), 4,
5725 map
.dwarf5_byte_order
);
5729 if (namei
>= map
.name_count
)
5731 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5733 namei
, map
.name_count
,
5734 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5740 const uint32_t namei_full_hash
5741 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5742 (map
.hash_table_reordered
+ namei
), 4,
5743 map
.dwarf5_byte_order
);
5744 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5747 if (full_hash
== namei_full_hash
)
5749 const char *const namei_string
= map
.namei_to_name (namei
);
5751 #if 0 /* An expensive sanity check. */
5752 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5754 complaint (_("Wrong .debug_names hash for string at index %u "
5756 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5761 if (cmp (namei_string
, name
) == 0)
5763 const ULONGEST namei_entry_offs
5764 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5765 + namei
* map
.offset_size
),
5766 map
.offset_size
, map
.dwarf5_byte_order
);
5767 return map
.entry_pool
+ namei_entry_offs
;
5772 if (namei
>= map
.name_count
)
5778 dw2_debug_names_iterator::find_vec_in_debug_names
5779 (const mapped_debug_names
&map
, uint32_t namei
)
5781 if (namei
>= map
.name_count
)
5783 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5785 namei
, map
.name_count
,
5786 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5790 const ULONGEST namei_entry_offs
5791 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5792 + namei
* map
.offset_size
),
5793 map
.offset_size
, map
.dwarf5_byte_order
);
5794 return map
.entry_pool
+ namei_entry_offs
;
5797 /* See dw2_debug_names_iterator. */
5799 dwarf2_per_cu_data
*
5800 dw2_debug_names_iterator::next ()
5805 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5806 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5807 bfd
*const abfd
= objfile
->obfd
;
5811 unsigned int bytes_read
;
5812 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5813 m_addr
+= bytes_read
;
5817 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5818 if (indexval_it
== m_map
.abbrev_map
.cend ())
5820 complaint (_("Wrong .debug_names undefined abbrev code %s "
5822 pulongest (abbrev
), objfile_name (objfile
));
5825 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5826 enum class symbol_linkage
{
5830 } symbol_linkage_
= symbol_linkage::unknown
;
5831 dwarf2_per_cu_data
*per_cu
= NULL
;
5832 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5837 case DW_FORM_implicit_const
:
5838 ull
= attr
.implicit_const
;
5840 case DW_FORM_flag_present
:
5844 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5845 m_addr
+= bytes_read
;
5848 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5849 dwarf_form_name (attr
.form
),
5850 objfile_name (objfile
));
5853 switch (attr
.dw_idx
)
5855 case DW_IDX_compile_unit
:
5856 /* Don't crash on bad data. */
5857 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5859 complaint (_(".debug_names entry has bad CU index %s"
5862 objfile_name (dwarf2_per_objfile
->objfile
));
5865 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5867 case DW_IDX_type_unit
:
5868 /* Don't crash on bad data. */
5869 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5871 complaint (_(".debug_names entry has bad TU index %s"
5874 objfile_name (dwarf2_per_objfile
->objfile
));
5877 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5879 case DW_IDX_GNU_internal
:
5880 if (!m_map
.augmentation_is_gdb
)
5882 symbol_linkage_
= symbol_linkage::static_
;
5884 case DW_IDX_GNU_external
:
5885 if (!m_map
.augmentation_is_gdb
)
5887 symbol_linkage_
= symbol_linkage::extern_
;
5892 /* Skip if already read in. */
5893 if (per_cu
->v
.quick
->compunit_symtab
)
5896 /* Check static vs global. */
5897 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5899 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5900 const bool symbol_is_static
=
5901 symbol_linkage_
== symbol_linkage::static_
;
5902 if (want_static
!= symbol_is_static
)
5906 /* Match dw2_symtab_iter_next, symbol_kind
5907 and debug_names::psymbol_tag. */
5911 switch (indexval
.dwarf_tag
)
5913 case DW_TAG_variable
:
5914 case DW_TAG_subprogram
:
5915 /* Some types are also in VAR_DOMAIN. */
5916 case DW_TAG_typedef
:
5917 case DW_TAG_structure_type
:
5924 switch (indexval
.dwarf_tag
)
5926 case DW_TAG_typedef
:
5927 case DW_TAG_structure_type
:
5934 switch (indexval
.dwarf_tag
)
5937 case DW_TAG_variable
:
5947 /* Match dw2_expand_symtabs_matching, symbol_kind and
5948 debug_names::psymbol_tag. */
5951 case VARIABLES_DOMAIN
:
5952 switch (indexval
.dwarf_tag
)
5954 case DW_TAG_variable
:
5960 case FUNCTIONS_DOMAIN
:
5961 switch (indexval
.dwarf_tag
)
5963 case DW_TAG_subprogram
:
5970 switch (indexval
.dwarf_tag
)
5972 case DW_TAG_typedef
:
5973 case DW_TAG_structure_type
:
5986 static struct compunit_symtab
*
5987 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5988 const char *name
, domain_enum domain
)
5990 struct dwarf2_per_objfile
*dwarf2_per_objfile
5991 = get_dwarf2_per_objfile (objfile
);
5993 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5996 /* index is NULL if OBJF_READNOW. */
5999 const auto &map
= *mapp
;
6001 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
6003 struct compunit_symtab
*stab_best
= NULL
;
6004 struct dwarf2_per_cu_data
*per_cu
;
6005 while ((per_cu
= iter
.next ()) != NULL
)
6007 struct symbol
*sym
, *with_opaque
= NULL
;
6008 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6009 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6010 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6012 sym
= block_find_symbol (block
, name
, domain
,
6013 block_find_non_opaque_type_preferred
,
6016 /* Some caution must be observed with overloaded functions and
6017 methods, since the index will not contain any overload
6018 information (but NAME might contain it). */
6021 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6023 if (with_opaque
!= NULL
6024 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6027 /* Keep looking through other CUs. */
6033 /* This dumps minimal information about .debug_names. It is called
6034 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6035 uses this to verify that .debug_names has been loaded. */
6038 dw2_debug_names_dump (struct objfile
*objfile
)
6040 struct dwarf2_per_objfile
*dwarf2_per_objfile
6041 = get_dwarf2_per_objfile (objfile
);
6043 gdb_assert (dwarf2_per_objfile
->using_index
);
6044 printf_filtered (".debug_names:");
6045 if (dwarf2_per_objfile
->debug_names_table
)
6046 printf_filtered (" exists\n");
6048 printf_filtered (" faked for \"readnow\"\n");
6049 printf_filtered ("\n");
6053 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6054 const char *func_name
)
6056 struct dwarf2_per_objfile
*dwarf2_per_objfile
6057 = get_dwarf2_per_objfile (objfile
);
6059 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6060 if (dwarf2_per_objfile
->debug_names_table
)
6062 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6064 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
6066 struct dwarf2_per_cu_data
*per_cu
;
6067 while ((per_cu
= iter
.next ()) != NULL
)
6068 dw2_instantiate_symtab (per_cu
, false);
6073 dw2_debug_names_map_matching_symbols
6074 (struct objfile
*objfile
,
6075 const lookup_name_info
&name
, domain_enum domain
,
6077 gdb::function_view
<symbol_found_callback_ftype
> callback
,
6078 symbol_compare_ftype
*ordered_compare
)
6080 struct dwarf2_per_objfile
*dwarf2_per_objfile
6081 = get_dwarf2_per_objfile (objfile
);
6083 /* debug_names_table is NULL if OBJF_READNOW. */
6084 if (!dwarf2_per_objfile
->debug_names_table
)
6087 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6088 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
6090 const char *match_name
= name
.ada ().lookup_name ().c_str ();
6091 auto matcher
= [&] (const char *symname
)
6093 if (ordered_compare
== nullptr)
6095 return ordered_compare (symname
, match_name
) == 0;
6098 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
6099 [&] (offset_type namei
)
6101 /* The name was matched, now expand corresponding CUs that were
6103 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
6105 struct dwarf2_per_cu_data
*per_cu
;
6106 while ((per_cu
= iter
.next ()) != NULL
)
6107 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
6111 /* It's a shame we couldn't do this inside the
6112 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
6113 that have already been expanded. Instead, this loop matches what
6114 the psymtab code does. */
6115 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
6117 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
6118 if (cust
!= nullptr)
6120 const struct block
*block
6121 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
6122 if (!iterate_over_symbols_terminated (block
, name
,
6130 dw2_debug_names_expand_symtabs_matching
6131 (struct objfile
*objfile
,
6132 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6133 const lookup_name_info
&lookup_name
,
6134 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6135 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6136 enum search_domain kind
)
6138 struct dwarf2_per_objfile
*dwarf2_per_objfile
6139 = get_dwarf2_per_objfile (objfile
);
6141 /* debug_names_table is NULL if OBJF_READNOW. */
6142 if (!dwarf2_per_objfile
->debug_names_table
)
6145 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6147 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6149 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6151 kind
, [&] (offset_type namei
)
6153 /* The name was matched, now expand corresponding CUs that were
6155 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6157 struct dwarf2_per_cu_data
*per_cu
;
6158 while ((per_cu
= iter
.next ()) != NULL
)
6159 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6165 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6168 dw2_find_last_source_symtab
,
6169 dw2_forget_cached_source_info
,
6170 dw2_map_symtabs_matching_filename
,
6171 dw2_debug_names_lookup_symbol
,
6173 dw2_debug_names_dump
,
6174 dw2_debug_names_expand_symtabs_for_function
,
6175 dw2_expand_all_symtabs
,
6176 dw2_expand_symtabs_with_fullname
,
6177 dw2_debug_names_map_matching_symbols
,
6178 dw2_debug_names_expand_symtabs_matching
,
6179 dw2_find_pc_sect_compunit_symtab
,
6181 dw2_map_symbol_filenames
6184 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6185 to either a dwarf2_per_objfile or dwz_file object. */
6187 template <typename T
>
6188 static gdb::array_view
<const gdb_byte
>
6189 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6191 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6193 if (dwarf2_section_empty_p (section
))
6196 /* Older elfutils strip versions could keep the section in the main
6197 executable while splitting it for the separate debug info file. */
6198 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
6201 dwarf2_read_section (obj
, section
);
6203 /* dwarf2_section_info::size is a bfd_size_type, while
6204 gdb::array_view works with size_t. On 32-bit hosts, with
6205 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6206 is 32-bit. So we need an explicit narrowing conversion here.
6207 This is fine, because it's impossible to allocate or mmap an
6208 array/buffer larger than what size_t can represent. */
6209 return gdb::make_array_view (section
->buffer
, section
->size
);
6212 /* Lookup the index cache for the contents of the index associated to
6215 static gdb::array_view
<const gdb_byte
>
6216 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6218 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6219 if (build_id
== nullptr)
6222 return global_index_cache
.lookup_gdb_index (build_id
,
6223 &dwarf2_obj
->index_cache_res
);
6226 /* Same as the above, but for DWZ. */
6228 static gdb::array_view
<const gdb_byte
>
6229 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6231 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6232 if (build_id
== nullptr)
6235 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6238 /* See symfile.h. */
6241 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6243 struct dwarf2_per_objfile
*dwarf2_per_objfile
6244 = get_dwarf2_per_objfile (objfile
);
6246 /* If we're about to read full symbols, don't bother with the
6247 indices. In this case we also don't care if some other debug
6248 format is making psymtabs, because they are all about to be
6250 if ((objfile
->flags
& OBJF_READNOW
))
6252 dwarf2_per_objfile
->using_index
= 1;
6253 create_all_comp_units (dwarf2_per_objfile
);
6254 create_all_type_units (dwarf2_per_objfile
);
6255 dwarf2_per_objfile
->quick_file_names_table
6256 = create_quick_file_names_table
6257 (dwarf2_per_objfile
->all_comp_units
.size ());
6259 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6260 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6262 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6264 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6265 struct dwarf2_per_cu_quick_data
);
6268 /* Return 1 so that gdb sees the "quick" functions. However,
6269 these functions will be no-ops because we will have expanded
6271 *index_kind
= dw_index_kind::GDB_INDEX
;
6275 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6277 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6281 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6282 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6283 get_gdb_index_contents_from_section
<dwz_file
>))
6285 *index_kind
= dw_index_kind::GDB_INDEX
;
6289 /* ... otherwise, try to find the index in the index cache. */
6290 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6291 get_gdb_index_contents_from_cache
,
6292 get_gdb_index_contents_from_cache_dwz
))
6294 global_index_cache
.hit ();
6295 *index_kind
= dw_index_kind::GDB_INDEX
;
6299 global_index_cache
.miss ();
6305 /* Build a partial symbol table. */
6308 dwarf2_build_psymtabs (struct objfile
*objfile
)
6310 struct dwarf2_per_objfile
*dwarf2_per_objfile
6311 = get_dwarf2_per_objfile (objfile
);
6313 init_psymbol_list (objfile
, 1024);
6317 /* This isn't really ideal: all the data we allocate on the
6318 objfile's obstack is still uselessly kept around. However,
6319 freeing it seems unsafe. */
6320 psymtab_discarder
psymtabs (objfile
);
6321 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6324 /* (maybe) store an index in the cache. */
6325 global_index_cache
.store (dwarf2_per_objfile
);
6327 catch (const gdb_exception_error
&except
)
6329 exception_print (gdb_stderr
, except
);
6333 /* Return the total length of the CU described by HEADER. */
6336 get_cu_length (const struct comp_unit_head
*header
)
6338 return header
->initial_length_size
+ header
->length
;
6341 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6344 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6346 sect_offset bottom
= cu_header
->sect_off
;
6347 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6349 return sect_off
>= bottom
&& sect_off
< top
;
6352 /* Find the base address of the compilation unit for range lists and
6353 location lists. It will normally be specified by DW_AT_low_pc.
6354 In DWARF-3 draft 4, the base address could be overridden by
6355 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6356 compilation units with discontinuous ranges. */
6359 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6361 struct attribute
*attr
;
6364 cu
->base_address
= 0;
6366 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6369 cu
->base_address
= attr_value_as_address (attr
);
6374 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6377 cu
->base_address
= attr_value_as_address (attr
);
6383 /* Read in the comp unit header information from the debug_info at info_ptr.
6384 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6385 NOTE: This leaves members offset, first_die_offset to be filled in
6388 static const gdb_byte
*
6389 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6390 const gdb_byte
*info_ptr
,
6391 struct dwarf2_section_info
*section
,
6392 rcuh_kind section_kind
)
6395 unsigned int bytes_read
;
6396 const char *filename
= get_section_file_name (section
);
6397 bfd
*abfd
= get_section_bfd_owner (section
);
6399 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6400 cu_header
->initial_length_size
= bytes_read
;
6401 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6402 info_ptr
+= bytes_read
;
6403 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6404 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6405 error (_("Dwarf Error: wrong version in compilation unit header "
6406 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6407 cu_header
->version
, filename
);
6409 if (cu_header
->version
< 5)
6410 switch (section_kind
)
6412 case rcuh_kind::COMPILE
:
6413 cu_header
->unit_type
= DW_UT_compile
;
6415 case rcuh_kind::TYPE
:
6416 cu_header
->unit_type
= DW_UT_type
;
6419 internal_error (__FILE__
, __LINE__
,
6420 _("read_comp_unit_head: invalid section_kind"));
6424 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6425 (read_1_byte (abfd
, info_ptr
));
6427 switch (cu_header
->unit_type
)
6431 case DW_UT_skeleton
:
6432 case DW_UT_split_compile
:
6433 if (section_kind
!= rcuh_kind::COMPILE
)
6434 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6435 "(is %s, should be %s) [in module %s]"),
6436 dwarf_unit_type_name (cu_header
->unit_type
),
6437 dwarf_unit_type_name (DW_UT_type
), filename
);
6440 case DW_UT_split_type
:
6441 section_kind
= rcuh_kind::TYPE
;
6444 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6445 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6446 "[in module %s]"), cu_header
->unit_type
,
6447 dwarf_unit_type_name (DW_UT_compile
),
6448 dwarf_unit_type_name (DW_UT_skeleton
),
6449 dwarf_unit_type_name (DW_UT_split_compile
),
6450 dwarf_unit_type_name (DW_UT_type
),
6451 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6454 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6457 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6460 info_ptr
+= bytes_read
;
6461 if (cu_header
->version
< 5)
6463 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6466 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6467 if (signed_addr
< 0)
6468 internal_error (__FILE__
, __LINE__
,
6469 _("read_comp_unit_head: dwarf from non elf file"));
6470 cu_header
->signed_addr_p
= signed_addr
;
6472 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6473 || cu_header
->unit_type
== DW_UT_skeleton
6474 || cu_header
->unit_type
== DW_UT_split_compile
;
6476 if (header_has_signature
)
6478 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6482 if (section_kind
== rcuh_kind::TYPE
)
6484 LONGEST type_offset
;
6485 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6486 info_ptr
+= bytes_read
;
6487 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6488 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6489 error (_("Dwarf Error: Too big type_offset in compilation unit "
6490 "header (is %s) [in module %s]"), plongest (type_offset
),
6497 /* Helper function that returns the proper abbrev section for
6500 static struct dwarf2_section_info
*
6501 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6503 struct dwarf2_section_info
*abbrev
;
6504 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6506 if (this_cu
->is_dwz
)
6507 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6509 abbrev
= &dwarf2_per_objfile
->abbrev
;
6514 /* Subroutine of read_and_check_comp_unit_head and
6515 read_and_check_type_unit_head to simplify them.
6516 Perform various error checking on the header. */
6519 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6520 struct comp_unit_head
*header
,
6521 struct dwarf2_section_info
*section
,
6522 struct dwarf2_section_info
*abbrev_section
)
6524 const char *filename
= get_section_file_name (section
);
6526 if (to_underlying (header
->abbrev_sect_off
)
6527 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6528 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6529 "(offset %s + 6) [in module %s]"),
6530 sect_offset_str (header
->abbrev_sect_off
),
6531 sect_offset_str (header
->sect_off
),
6534 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6535 avoid potential 32-bit overflow. */
6536 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6538 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6539 "(offset %s + 0) [in module %s]"),
6540 header
->length
, sect_offset_str (header
->sect_off
),
6544 /* Read in a CU/TU header and perform some basic error checking.
6545 The contents of the header are stored in HEADER.
6546 The result is a pointer to the start of the first DIE. */
6548 static const gdb_byte
*
6549 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6550 struct comp_unit_head
*header
,
6551 struct dwarf2_section_info
*section
,
6552 struct dwarf2_section_info
*abbrev_section
,
6553 const gdb_byte
*info_ptr
,
6554 rcuh_kind section_kind
)
6556 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6558 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6560 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6562 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6564 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6570 /* Fetch the abbreviation table offset from a comp or type unit header. */
6573 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6574 struct dwarf2_section_info
*section
,
6575 sect_offset sect_off
)
6577 bfd
*abfd
= get_section_bfd_owner (section
);
6578 const gdb_byte
*info_ptr
;
6579 unsigned int initial_length_size
, offset_size
;
6582 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6583 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6584 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6585 offset_size
= initial_length_size
== 4 ? 4 : 8;
6586 info_ptr
+= initial_length_size
;
6588 version
= read_2_bytes (abfd
, info_ptr
);
6592 /* Skip unit type and address size. */
6596 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6599 /* Allocate a new partial symtab for file named NAME and mark this new
6600 partial symtab as being an include of PST. */
6603 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6604 struct objfile
*objfile
)
6606 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6608 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6610 /* It shares objfile->objfile_obstack. */
6611 subpst
->dirname
= pst
->dirname
;
6614 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6615 subpst
->dependencies
[0] = pst
;
6616 subpst
->number_of_dependencies
= 1;
6618 subpst
->read_symtab
= pst
->read_symtab
;
6620 /* No private part is necessary for include psymtabs. This property
6621 can be used to differentiate between such include psymtabs and
6622 the regular ones. */
6623 subpst
->read_symtab_private
= NULL
;
6626 /* Read the Line Number Program data and extract the list of files
6627 included by the source file represented by PST. Build an include
6628 partial symtab for each of these included files. */
6631 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6632 struct die_info
*die
,
6633 struct partial_symtab
*pst
)
6636 struct attribute
*attr
;
6638 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6640 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6642 return; /* No linetable, so no includes. */
6644 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6645 that we pass in the raw text_low here; that is ok because we're
6646 only decoding the line table to make include partial symtabs, and
6647 so the addresses aren't really used. */
6648 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6649 pst
->raw_text_low (), 1);
6653 hash_signatured_type (const void *item
)
6655 const struct signatured_type
*sig_type
6656 = (const struct signatured_type
*) item
;
6658 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6659 return sig_type
->signature
;
6663 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6665 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6666 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6668 return lhs
->signature
== rhs
->signature
;
6671 /* Allocate a hash table for signatured types. */
6674 allocate_signatured_type_table (struct objfile
*objfile
)
6676 return htab_create_alloc_ex (41,
6677 hash_signatured_type
,
6680 &objfile
->objfile_obstack
,
6681 hashtab_obstack_allocate
,
6682 dummy_obstack_deallocate
);
6685 /* A helper function to add a signatured type CU to a table. */
6688 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6690 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6691 std::vector
<signatured_type
*> *all_type_units
6692 = (std::vector
<signatured_type
*> *) datum
;
6694 all_type_units
->push_back (sigt
);
6699 /* A helper for create_debug_types_hash_table. Read types from SECTION
6700 and fill them into TYPES_HTAB. It will process only type units,
6701 therefore DW_UT_type. */
6704 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6705 struct dwo_file
*dwo_file
,
6706 dwarf2_section_info
*section
, htab_t
&types_htab
,
6707 rcuh_kind section_kind
)
6709 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6710 struct dwarf2_section_info
*abbrev_section
;
6712 const gdb_byte
*info_ptr
, *end_ptr
;
6714 abbrev_section
= (dwo_file
!= NULL
6715 ? &dwo_file
->sections
.abbrev
6716 : &dwarf2_per_objfile
->abbrev
);
6718 if (dwarf_read_debug
)
6719 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6720 get_section_name (section
),
6721 get_section_file_name (abbrev_section
));
6723 dwarf2_read_section (objfile
, section
);
6724 info_ptr
= section
->buffer
;
6726 if (info_ptr
== NULL
)
6729 /* We can't set abfd until now because the section may be empty or
6730 not present, in which case the bfd is unknown. */
6731 abfd
= get_section_bfd_owner (section
);
6733 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6734 because we don't need to read any dies: the signature is in the
6737 end_ptr
= info_ptr
+ section
->size
;
6738 while (info_ptr
< end_ptr
)
6740 struct signatured_type
*sig_type
;
6741 struct dwo_unit
*dwo_tu
;
6743 const gdb_byte
*ptr
= info_ptr
;
6744 struct comp_unit_head header
;
6745 unsigned int length
;
6747 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6749 /* Initialize it due to a false compiler warning. */
6750 header
.signature
= -1;
6751 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6753 /* We need to read the type's signature in order to build the hash
6754 table, but we don't need anything else just yet. */
6756 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6757 abbrev_section
, ptr
, section_kind
);
6759 length
= get_cu_length (&header
);
6761 /* Skip dummy type units. */
6762 if (ptr
>= info_ptr
+ length
6763 || peek_abbrev_code (abfd
, ptr
) == 0
6764 || header
.unit_type
!= DW_UT_type
)
6770 if (types_htab
== NULL
)
6773 types_htab
= allocate_dwo_unit_table (objfile
);
6775 types_htab
= allocate_signatured_type_table (objfile
);
6781 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6783 dwo_tu
->dwo_file
= dwo_file
;
6784 dwo_tu
->signature
= header
.signature
;
6785 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6786 dwo_tu
->section
= section
;
6787 dwo_tu
->sect_off
= sect_off
;
6788 dwo_tu
->length
= length
;
6792 /* N.B.: type_offset is not usable if this type uses a DWO file.
6793 The real type_offset is in the DWO file. */
6795 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6796 struct signatured_type
);
6797 sig_type
->signature
= header
.signature
;
6798 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6799 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6800 sig_type
->per_cu
.is_debug_types
= 1;
6801 sig_type
->per_cu
.section
= section
;
6802 sig_type
->per_cu
.sect_off
= sect_off
;
6803 sig_type
->per_cu
.length
= length
;
6806 slot
= htab_find_slot (types_htab
,
6807 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6809 gdb_assert (slot
!= NULL
);
6812 sect_offset dup_sect_off
;
6816 const struct dwo_unit
*dup_tu
6817 = (const struct dwo_unit
*) *slot
;
6819 dup_sect_off
= dup_tu
->sect_off
;
6823 const struct signatured_type
*dup_tu
6824 = (const struct signatured_type
*) *slot
;
6826 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6829 complaint (_("debug type entry at offset %s is duplicate to"
6830 " the entry at offset %s, signature %s"),
6831 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6832 hex_string (header
.signature
));
6834 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6836 if (dwarf_read_debug
> 1)
6837 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6838 sect_offset_str (sect_off
),
6839 hex_string (header
.signature
));
6845 /* Create the hash table of all entries in the .debug_types
6846 (or .debug_types.dwo) section(s).
6847 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6848 otherwise it is NULL.
6850 The result is a pointer to the hash table or NULL if there are no types.
6852 Note: This function processes DWO files only, not DWP files. */
6855 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6856 struct dwo_file
*dwo_file
,
6857 gdb::array_view
<dwarf2_section_info
> type_sections
,
6860 for (dwarf2_section_info
§ion
: type_sections
)
6861 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6862 types_htab
, rcuh_kind::TYPE
);
6865 /* Create the hash table of all entries in the .debug_types section,
6866 and initialize all_type_units.
6867 The result is zero if there is an error (e.g. missing .debug_types section),
6868 otherwise non-zero. */
6871 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6873 htab_t types_htab
= NULL
;
6875 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6876 &dwarf2_per_objfile
->info
, types_htab
,
6877 rcuh_kind::COMPILE
);
6878 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6879 dwarf2_per_objfile
->types
, types_htab
);
6880 if (types_htab
== NULL
)
6882 dwarf2_per_objfile
->signatured_types
= NULL
;
6886 dwarf2_per_objfile
->signatured_types
= types_htab
;
6888 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6889 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6891 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6892 &dwarf2_per_objfile
->all_type_units
);
6897 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6898 If SLOT is non-NULL, it is the entry to use in the hash table.
6899 Otherwise we find one. */
6901 static struct signatured_type
*
6902 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6905 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6907 if (dwarf2_per_objfile
->all_type_units
.size ()
6908 == dwarf2_per_objfile
->all_type_units
.capacity ())
6909 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6911 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6912 struct signatured_type
);
6914 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6915 sig_type
->signature
= sig
;
6916 sig_type
->per_cu
.is_debug_types
= 1;
6917 if (dwarf2_per_objfile
->using_index
)
6919 sig_type
->per_cu
.v
.quick
=
6920 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6921 struct dwarf2_per_cu_quick_data
);
6926 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6929 gdb_assert (*slot
== NULL
);
6931 /* The rest of sig_type must be filled in by the caller. */
6935 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6936 Fill in SIG_ENTRY with DWO_ENTRY. */
6939 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6940 struct signatured_type
*sig_entry
,
6941 struct dwo_unit
*dwo_entry
)
6943 /* Make sure we're not clobbering something we don't expect to. */
6944 gdb_assert (! sig_entry
->per_cu
.queued
);
6945 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6946 if (dwarf2_per_objfile
->using_index
)
6948 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6949 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6952 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6953 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6954 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6955 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6956 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6958 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6959 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6960 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6961 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6962 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6963 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6964 sig_entry
->dwo_unit
= dwo_entry
;
6967 /* Subroutine of lookup_signatured_type.
6968 If we haven't read the TU yet, create the signatured_type data structure
6969 for a TU to be read in directly from a DWO file, bypassing the stub.
6970 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6971 using .gdb_index, then when reading a CU we want to stay in the DWO file
6972 containing that CU. Otherwise we could end up reading several other DWO
6973 files (due to comdat folding) to process the transitive closure of all the
6974 mentioned TUs, and that can be slow. The current DWO file will have every
6975 type signature that it needs.
6976 We only do this for .gdb_index because in the psymtab case we already have
6977 to read all the DWOs to build the type unit groups. */
6979 static struct signatured_type
*
6980 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6982 struct dwarf2_per_objfile
*dwarf2_per_objfile
6983 = cu
->per_cu
->dwarf2_per_objfile
;
6984 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6985 struct dwo_file
*dwo_file
;
6986 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6987 struct signatured_type find_sig_entry
, *sig_entry
;
6990 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6992 /* If TU skeletons have been removed then we may not have read in any
6994 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6996 dwarf2_per_objfile
->signatured_types
6997 = allocate_signatured_type_table (objfile
);
7000 /* We only ever need to read in one copy of a signatured type.
7001 Use the global signatured_types array to do our own comdat-folding
7002 of types. If this is the first time we're reading this TU, and
7003 the TU has an entry in .gdb_index, replace the recorded data from
7004 .gdb_index with this TU. */
7006 find_sig_entry
.signature
= sig
;
7007 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7008 &find_sig_entry
, INSERT
);
7009 sig_entry
= (struct signatured_type
*) *slot
;
7011 /* We can get here with the TU already read, *or* in the process of being
7012 read. Don't reassign the global entry to point to this DWO if that's
7013 the case. Also note that if the TU is already being read, it may not
7014 have come from a DWO, the program may be a mix of Fission-compiled
7015 code and non-Fission-compiled code. */
7017 /* Have we already tried to read this TU?
7018 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7019 needn't exist in the global table yet). */
7020 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7023 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7024 dwo_unit of the TU itself. */
7025 dwo_file
= cu
->dwo_unit
->dwo_file
;
7027 /* Ok, this is the first time we're reading this TU. */
7028 if (dwo_file
->tus
== NULL
)
7030 find_dwo_entry
.signature
= sig
;
7031 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7032 if (dwo_entry
== NULL
)
7035 /* If the global table doesn't have an entry for this TU, add one. */
7036 if (sig_entry
== NULL
)
7037 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7039 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7040 sig_entry
->per_cu
.tu_read
= 1;
7044 /* Subroutine of lookup_signatured_type.
7045 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7046 then try the DWP file. If the TU stub (skeleton) has been removed then
7047 it won't be in .gdb_index. */
7049 static struct signatured_type
*
7050 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7052 struct dwarf2_per_objfile
*dwarf2_per_objfile
7053 = cu
->per_cu
->dwarf2_per_objfile
;
7054 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7055 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7056 struct dwo_unit
*dwo_entry
;
7057 struct signatured_type find_sig_entry
, *sig_entry
;
7060 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7061 gdb_assert (dwp_file
!= NULL
);
7063 /* If TU skeletons have been removed then we may not have read in any
7065 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7067 dwarf2_per_objfile
->signatured_types
7068 = allocate_signatured_type_table (objfile
);
7071 find_sig_entry
.signature
= sig
;
7072 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7073 &find_sig_entry
, INSERT
);
7074 sig_entry
= (struct signatured_type
*) *slot
;
7076 /* Have we already tried to read this TU?
7077 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7078 needn't exist in the global table yet). */
7079 if (sig_entry
!= NULL
)
7082 if (dwp_file
->tus
== NULL
)
7084 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7085 sig
, 1 /* is_debug_types */);
7086 if (dwo_entry
== NULL
)
7089 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7090 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7095 /* Lookup a signature based type for DW_FORM_ref_sig8.
7096 Returns NULL if signature SIG is not present in the table.
7097 It is up to the caller to complain about this. */
7099 static struct signatured_type
*
7100 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7102 struct dwarf2_per_objfile
*dwarf2_per_objfile
7103 = cu
->per_cu
->dwarf2_per_objfile
;
7106 && dwarf2_per_objfile
->using_index
)
7108 /* We're in a DWO/DWP file, and we're using .gdb_index.
7109 These cases require special processing. */
7110 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7111 return lookup_dwo_signatured_type (cu
, sig
);
7113 return lookup_dwp_signatured_type (cu
, sig
);
7117 struct signatured_type find_entry
, *entry
;
7119 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7121 find_entry
.signature
= sig
;
7122 entry
= ((struct signatured_type
*)
7123 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7128 /* Low level DIE reading support. */
7130 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7133 init_cu_die_reader (struct die_reader_specs
*reader
,
7134 struct dwarf2_cu
*cu
,
7135 struct dwarf2_section_info
*section
,
7136 struct dwo_file
*dwo_file
,
7137 struct abbrev_table
*abbrev_table
)
7139 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7140 reader
->abfd
= get_section_bfd_owner (section
);
7142 reader
->dwo_file
= dwo_file
;
7143 reader
->die_section
= section
;
7144 reader
->buffer
= section
->buffer
;
7145 reader
->buffer_end
= section
->buffer
+ section
->size
;
7146 reader
->comp_dir
= NULL
;
7147 reader
->abbrev_table
= abbrev_table
;
7150 /* Subroutine of init_cutu_and_read_dies to simplify it.
7151 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7152 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7155 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7156 from it to the DIE in the DWO. If NULL we are skipping the stub.
7157 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7158 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7159 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7160 STUB_COMP_DIR may be non-NULL.
7161 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7162 are filled in with the info of the DIE from the DWO file.
7163 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7164 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7165 kept around for at least as long as *RESULT_READER.
7167 The result is non-zero if a valid (non-dummy) DIE was found. */
7170 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7171 struct dwo_unit
*dwo_unit
,
7172 struct die_info
*stub_comp_unit_die
,
7173 const char *stub_comp_dir
,
7174 struct die_reader_specs
*result_reader
,
7175 const gdb_byte
**result_info_ptr
,
7176 struct die_info
**result_comp_unit_die
,
7177 int *result_has_children
,
7178 abbrev_table_up
*result_dwo_abbrev_table
)
7180 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7181 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7182 struct dwarf2_cu
*cu
= this_cu
->cu
;
7184 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7185 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7186 int i
,num_extra_attrs
;
7187 struct dwarf2_section_info
*dwo_abbrev_section
;
7188 struct attribute
*attr
;
7189 struct die_info
*comp_unit_die
;
7191 /* At most one of these may be provided. */
7192 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7194 /* These attributes aren't processed until later:
7195 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7196 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7197 referenced later. However, these attributes are found in the stub
7198 which we won't have later. In order to not impose this complication
7199 on the rest of the code, we read them here and copy them to the
7208 if (stub_comp_unit_die
!= NULL
)
7210 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7212 if (! this_cu
->is_debug_types
)
7213 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7214 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7215 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7216 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7217 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7219 /* There should be a DW_AT_addr_base attribute here (if needed).
7220 We need the value before we can process DW_FORM_GNU_addr_index
7221 or DW_FORM_addrx. */
7223 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7225 cu
->addr_base
= DW_UNSND (attr
);
7227 /* There should be a DW_AT_ranges_base attribute here (if needed).
7228 We need the value before we can process DW_AT_ranges. */
7229 cu
->ranges_base
= 0;
7230 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7232 cu
->ranges_base
= DW_UNSND (attr
);
7234 else if (stub_comp_dir
!= NULL
)
7236 /* Reconstruct the comp_dir attribute to simplify the code below. */
7237 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7238 comp_dir
->name
= DW_AT_comp_dir
;
7239 comp_dir
->form
= DW_FORM_string
;
7240 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7241 DW_STRING (comp_dir
) = stub_comp_dir
;
7244 /* Set up for reading the DWO CU/TU. */
7245 cu
->dwo_unit
= dwo_unit
;
7246 dwarf2_section_info
*section
= dwo_unit
->section
;
7247 dwarf2_read_section (objfile
, section
);
7248 abfd
= get_section_bfd_owner (section
);
7249 begin_info_ptr
= info_ptr
= (section
->buffer
7250 + to_underlying (dwo_unit
->sect_off
));
7251 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7253 if (this_cu
->is_debug_types
)
7255 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7257 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7258 &cu
->header
, section
,
7260 info_ptr
, rcuh_kind::TYPE
);
7261 /* This is not an assert because it can be caused by bad debug info. */
7262 if (sig_type
->signature
!= cu
->header
.signature
)
7264 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7265 " TU at offset %s [in module %s]"),
7266 hex_string (sig_type
->signature
),
7267 hex_string (cu
->header
.signature
),
7268 sect_offset_str (dwo_unit
->sect_off
),
7269 bfd_get_filename (abfd
));
7271 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7272 /* For DWOs coming from DWP files, we don't know the CU length
7273 nor the type's offset in the TU until now. */
7274 dwo_unit
->length
= get_cu_length (&cu
->header
);
7275 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7277 /* Establish the type offset that can be used to lookup the type.
7278 For DWO files, we don't know it until now. */
7279 sig_type
->type_offset_in_section
7280 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7284 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7285 &cu
->header
, section
,
7287 info_ptr
, rcuh_kind::COMPILE
);
7288 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7289 /* For DWOs coming from DWP files, we don't know the CU length
7291 dwo_unit
->length
= get_cu_length (&cu
->header
);
7294 *result_dwo_abbrev_table
7295 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7296 cu
->header
.abbrev_sect_off
);
7297 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7298 result_dwo_abbrev_table
->get ());
7300 /* Read in the die, but leave space to copy over the attributes
7301 from the stub. This has the benefit of simplifying the rest of
7302 the code - all the work to maintain the illusion of a single
7303 DW_TAG_{compile,type}_unit DIE is done here. */
7304 num_extra_attrs
= ((stmt_list
!= NULL
)
7308 + (comp_dir
!= NULL
));
7309 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7310 result_has_children
, num_extra_attrs
);
7312 /* Copy over the attributes from the stub to the DIE we just read in. */
7313 comp_unit_die
= *result_comp_unit_die
;
7314 i
= comp_unit_die
->num_attrs
;
7315 if (stmt_list
!= NULL
)
7316 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7318 comp_unit_die
->attrs
[i
++] = *low_pc
;
7319 if (high_pc
!= NULL
)
7320 comp_unit_die
->attrs
[i
++] = *high_pc
;
7322 comp_unit_die
->attrs
[i
++] = *ranges
;
7323 if (comp_dir
!= NULL
)
7324 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7325 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7327 if (dwarf_die_debug
)
7329 fprintf_unfiltered (gdb_stdlog
,
7330 "Read die from %s@0x%x of %s:\n",
7331 get_section_name (section
),
7332 (unsigned) (begin_info_ptr
- section
->buffer
),
7333 bfd_get_filename (abfd
));
7334 dump_die (comp_unit_die
, dwarf_die_debug
);
7337 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7338 TUs by skipping the stub and going directly to the entry in the DWO file.
7339 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7340 to get it via circuitous means. Blech. */
7341 if (comp_dir
!= NULL
)
7342 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7344 /* Skip dummy compilation units. */
7345 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7346 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7349 *result_info_ptr
= info_ptr
;
7353 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7354 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7355 signature is part of the header. */
7356 static gdb::optional
<ULONGEST
>
7357 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7359 if (cu
->header
.version
>= 5)
7360 return cu
->header
.signature
;
7361 struct attribute
*attr
;
7362 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7363 if (attr
== nullptr)
7364 return gdb::optional
<ULONGEST
> ();
7365 return DW_UNSND (attr
);
7368 /* Subroutine of init_cutu_and_read_dies to simplify it.
7369 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7370 Returns NULL if the specified DWO unit cannot be found. */
7372 static struct dwo_unit
*
7373 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7374 struct die_info
*comp_unit_die
)
7376 struct dwarf2_cu
*cu
= this_cu
->cu
;
7377 struct dwo_unit
*dwo_unit
;
7378 const char *comp_dir
, *dwo_name
;
7380 gdb_assert (cu
!= NULL
);
7382 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7383 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7384 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7386 if (this_cu
->is_debug_types
)
7388 struct signatured_type
*sig_type
;
7390 /* Since this_cu is the first member of struct signatured_type,
7391 we can go from a pointer to one to a pointer to the other. */
7392 sig_type
= (struct signatured_type
*) this_cu
;
7393 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7397 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7398 if (!signature
.has_value ())
7399 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7401 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7402 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7409 /* Subroutine of init_cutu_and_read_dies to simplify it.
7410 See it for a description of the parameters.
7411 Read a TU directly from a DWO file, bypassing the stub. */
7414 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7415 int use_existing_cu
, int keep
,
7416 die_reader_func_ftype
*die_reader_func
,
7419 std::unique_ptr
<dwarf2_cu
> new_cu
;
7420 struct signatured_type
*sig_type
;
7421 struct die_reader_specs reader
;
7422 const gdb_byte
*info_ptr
;
7423 struct die_info
*comp_unit_die
;
7425 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7427 /* Verify we can do the following downcast, and that we have the
7429 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7430 sig_type
= (struct signatured_type
*) this_cu
;
7431 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7433 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7435 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7436 /* There's no need to do the rereading_dwo_cu handling that
7437 init_cutu_and_read_dies does since we don't read the stub. */
7441 /* If !use_existing_cu, this_cu->cu must be NULL. */
7442 gdb_assert (this_cu
->cu
== NULL
);
7443 new_cu
.reset (new dwarf2_cu (this_cu
));
7446 /* A future optimization, if needed, would be to use an existing
7447 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7448 could share abbrev tables. */
7450 /* The abbreviation table used by READER, this must live at least as long as
7452 abbrev_table_up dwo_abbrev_table
;
7454 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7455 NULL
/* stub_comp_unit_die */,
7456 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7458 &comp_unit_die
, &has_children
,
7459 &dwo_abbrev_table
) == 0)
7465 /* All the "real" work is done here. */
7466 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7468 /* This duplicates the code in init_cutu_and_read_dies,
7469 but the alternative is making the latter more complex.
7470 This function is only for the special case of using DWO files directly:
7471 no point in overly complicating the general case just to handle this. */
7472 if (new_cu
!= NULL
&& keep
)
7474 /* Link this CU into read_in_chain. */
7475 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7476 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7477 /* The chain owns it now. */
7482 /* Initialize a CU (or TU) and read its DIEs.
7483 If the CU defers to a DWO file, read the DWO file as well.
7485 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7486 Otherwise the table specified in the comp unit header is read in and used.
7487 This is an optimization for when we already have the abbrev table.
7489 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7490 Otherwise, a new CU is allocated with xmalloc.
7492 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7493 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7495 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7496 linker) then DIE_READER_FUNC will not get called. */
7499 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7500 struct abbrev_table
*abbrev_table
,
7501 int use_existing_cu
, int keep
,
7503 die_reader_func_ftype
*die_reader_func
,
7506 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7507 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7508 struct dwarf2_section_info
*section
= this_cu
->section
;
7509 bfd
*abfd
= get_section_bfd_owner (section
);
7510 struct dwarf2_cu
*cu
;
7511 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7512 struct die_reader_specs reader
;
7513 struct die_info
*comp_unit_die
;
7515 struct signatured_type
*sig_type
= NULL
;
7516 struct dwarf2_section_info
*abbrev_section
;
7517 /* Non-zero if CU currently points to a DWO file and we need to
7518 reread it. When this happens we need to reread the skeleton die
7519 before we can reread the DWO file (this only applies to CUs, not TUs). */
7520 int rereading_dwo_cu
= 0;
7522 if (dwarf_die_debug
)
7523 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7524 this_cu
->is_debug_types
? "type" : "comp",
7525 sect_offset_str (this_cu
->sect_off
));
7527 if (use_existing_cu
)
7530 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7531 file (instead of going through the stub), short-circuit all of this. */
7532 if (this_cu
->reading_dwo_directly
)
7534 /* Narrow down the scope of possibilities to have to understand. */
7535 gdb_assert (this_cu
->is_debug_types
);
7536 gdb_assert (abbrev_table
== NULL
);
7537 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7538 die_reader_func
, data
);
7542 /* This is cheap if the section is already read in. */
7543 dwarf2_read_section (objfile
, section
);
7545 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7547 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7549 std::unique_ptr
<dwarf2_cu
> new_cu
;
7550 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7553 /* If this CU is from a DWO file we need to start over, we need to
7554 refetch the attributes from the skeleton CU.
7555 This could be optimized by retrieving those attributes from when we
7556 were here the first time: the previous comp_unit_die was stored in
7557 comp_unit_obstack. But there's no data yet that we need this
7559 if (cu
->dwo_unit
!= NULL
)
7560 rereading_dwo_cu
= 1;
7564 /* If !use_existing_cu, this_cu->cu must be NULL. */
7565 gdb_assert (this_cu
->cu
== NULL
);
7566 new_cu
.reset (new dwarf2_cu (this_cu
));
7570 /* Get the header. */
7571 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7573 /* We already have the header, there's no need to read it in again. */
7574 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7578 if (this_cu
->is_debug_types
)
7580 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7581 &cu
->header
, section
,
7582 abbrev_section
, info_ptr
,
7585 /* Since per_cu is the first member of struct signatured_type,
7586 we can go from a pointer to one to a pointer to the other. */
7587 sig_type
= (struct signatured_type
*) this_cu
;
7588 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7589 gdb_assert (sig_type
->type_offset_in_tu
7590 == cu
->header
.type_cu_offset_in_tu
);
7591 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7593 /* LENGTH has not been set yet for type units if we're
7594 using .gdb_index. */
7595 this_cu
->length
= get_cu_length (&cu
->header
);
7597 /* Establish the type offset that can be used to lookup the type. */
7598 sig_type
->type_offset_in_section
=
7599 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7601 this_cu
->dwarf_version
= cu
->header
.version
;
7605 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7606 &cu
->header
, section
,
7609 rcuh_kind::COMPILE
);
7611 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7612 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7613 this_cu
->dwarf_version
= cu
->header
.version
;
7617 /* Skip dummy compilation units. */
7618 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7619 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7622 /* If we don't have them yet, read the abbrevs for this compilation unit.
7623 And if we need to read them now, make sure they're freed when we're
7624 done (own the table through ABBREV_TABLE_HOLDER). */
7625 abbrev_table_up abbrev_table_holder
;
7626 if (abbrev_table
!= NULL
)
7627 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7631 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7632 cu
->header
.abbrev_sect_off
);
7633 abbrev_table
= abbrev_table_holder
.get ();
7636 /* Read the top level CU/TU die. */
7637 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7638 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7640 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7643 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7644 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7645 table from the DWO file and pass the ownership over to us. It will be
7646 referenced from READER, so we must make sure to free it after we're done
7649 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7650 DWO CU, that this test will fail (the attribute will not be present). */
7651 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7652 abbrev_table_up dwo_abbrev_table
;
7653 if (dwo_name
!= nullptr)
7655 struct dwo_unit
*dwo_unit
;
7656 struct die_info
*dwo_comp_unit_die
;
7660 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7661 " has children (offset %s) [in module %s]"),
7662 sect_offset_str (this_cu
->sect_off
),
7663 bfd_get_filename (abfd
));
7665 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7666 if (dwo_unit
!= NULL
)
7668 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7669 comp_unit_die
, NULL
,
7671 &dwo_comp_unit_die
, &has_children
,
7672 &dwo_abbrev_table
) == 0)
7677 comp_unit_die
= dwo_comp_unit_die
;
7681 /* Yikes, we couldn't find the rest of the DIE, we only have
7682 the stub. A complaint has already been logged. There's
7683 not much more we can do except pass on the stub DIE to
7684 die_reader_func. We don't want to throw an error on bad
7689 /* All of the above is setup for this call. Yikes. */
7690 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7692 /* Done, clean up. */
7693 if (new_cu
!= NULL
&& keep
)
7695 /* Link this CU into read_in_chain. */
7696 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7697 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7698 /* The chain owns it now. */
7703 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7704 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7705 to have already done the lookup to find the DWO file).
7707 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7708 THIS_CU->is_debug_types, but nothing else.
7710 We fill in THIS_CU->length.
7712 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7713 linker) then DIE_READER_FUNC will not get called.
7715 THIS_CU->cu is always freed when done.
7716 This is done in order to not leave THIS_CU->cu in a state where we have
7717 to care whether it refers to the "main" CU or the DWO CU. */
7720 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7721 struct dwo_file
*dwo_file
,
7722 die_reader_func_ftype
*die_reader_func
,
7725 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7726 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7727 struct dwarf2_section_info
*section
= this_cu
->section
;
7728 bfd
*abfd
= get_section_bfd_owner (section
);
7729 struct dwarf2_section_info
*abbrev_section
;
7730 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7731 struct die_reader_specs reader
;
7732 struct die_info
*comp_unit_die
;
7735 if (dwarf_die_debug
)
7736 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7737 this_cu
->is_debug_types
? "type" : "comp",
7738 sect_offset_str (this_cu
->sect_off
));
7740 gdb_assert (this_cu
->cu
== NULL
);
7742 abbrev_section
= (dwo_file
!= NULL
7743 ? &dwo_file
->sections
.abbrev
7744 : get_abbrev_section_for_cu (this_cu
));
7746 /* This is cheap if the section is already read in. */
7747 dwarf2_read_section (objfile
, section
);
7749 struct dwarf2_cu
cu (this_cu
);
7751 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7752 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7753 &cu
.header
, section
,
7754 abbrev_section
, info_ptr
,
7755 (this_cu
->is_debug_types
7757 : rcuh_kind::COMPILE
));
7759 this_cu
->length
= get_cu_length (&cu
.header
);
7761 /* Skip dummy compilation units. */
7762 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7763 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7766 abbrev_table_up abbrev_table
7767 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7768 cu
.header
.abbrev_sect_off
);
7770 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7771 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7773 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7776 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
7777 does not lookup the specified DWO file.
7778 This cannot be used to read DWO files.
7780 THIS_CU->cu is always freed when done.
7781 This is done in order to not leave THIS_CU->cu in a state where we have
7782 to care whether it refers to the "main" CU or the DWO CU.
7783 We can revisit this if the data shows there's a performance issue. */
7786 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7787 die_reader_func_ftype
*die_reader_func
,
7790 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
7793 /* Type Unit Groups.
7795 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7796 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7797 so that all types coming from the same compilation (.o file) are grouped
7798 together. A future step could be to put the types in the same symtab as
7799 the CU the types ultimately came from. */
7802 hash_type_unit_group (const void *item
)
7804 const struct type_unit_group
*tu_group
7805 = (const struct type_unit_group
*) item
;
7807 return hash_stmt_list_entry (&tu_group
->hash
);
7811 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7813 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7814 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7816 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7819 /* Allocate a hash table for type unit groups. */
7822 allocate_type_unit_groups_table (struct objfile
*objfile
)
7824 return htab_create_alloc_ex (3,
7825 hash_type_unit_group
,
7828 &objfile
->objfile_obstack
,
7829 hashtab_obstack_allocate
,
7830 dummy_obstack_deallocate
);
7833 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7834 partial symtabs. We combine several TUs per psymtab to not let the size
7835 of any one psymtab grow too big. */
7836 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7837 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7839 /* Helper routine for get_type_unit_group.
7840 Create the type_unit_group object used to hold one or more TUs. */
7842 static struct type_unit_group
*
7843 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7845 struct dwarf2_per_objfile
*dwarf2_per_objfile
7846 = cu
->per_cu
->dwarf2_per_objfile
;
7847 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7848 struct dwarf2_per_cu_data
*per_cu
;
7849 struct type_unit_group
*tu_group
;
7851 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7852 struct type_unit_group
);
7853 per_cu
= &tu_group
->per_cu
;
7854 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7856 if (dwarf2_per_objfile
->using_index
)
7858 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7859 struct dwarf2_per_cu_quick_data
);
7863 unsigned int line_offset
= to_underlying (line_offset_struct
);
7864 struct partial_symtab
*pst
;
7867 /* Give the symtab a useful name for debug purposes. */
7868 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7869 name
= string_printf ("<type_units_%d>",
7870 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7872 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7874 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7878 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7879 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7884 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7885 STMT_LIST is a DW_AT_stmt_list attribute. */
7887 static struct type_unit_group
*
7888 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7890 struct dwarf2_per_objfile
*dwarf2_per_objfile
7891 = cu
->per_cu
->dwarf2_per_objfile
;
7892 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7893 struct type_unit_group
*tu_group
;
7895 unsigned int line_offset
;
7896 struct type_unit_group type_unit_group_for_lookup
;
7898 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7900 dwarf2_per_objfile
->type_unit_groups
=
7901 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7904 /* Do we need to create a new group, or can we use an existing one? */
7908 line_offset
= DW_UNSND (stmt_list
);
7909 ++tu_stats
->nr_symtab_sharers
;
7913 /* Ugh, no stmt_list. Rare, but we have to handle it.
7914 We can do various things here like create one group per TU or
7915 spread them over multiple groups to split up the expansion work.
7916 To avoid worst case scenarios (too many groups or too large groups)
7917 we, umm, group them in bunches. */
7918 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7919 | (tu_stats
->nr_stmt_less_type_units
7920 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7921 ++tu_stats
->nr_stmt_less_type_units
;
7924 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7925 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7926 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7927 &type_unit_group_for_lookup
, INSERT
);
7930 tu_group
= (struct type_unit_group
*) *slot
;
7931 gdb_assert (tu_group
!= NULL
);
7935 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7936 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7938 ++tu_stats
->nr_symtabs
;
7944 /* Partial symbol tables. */
7946 /* Create a psymtab named NAME and assign it to PER_CU.
7948 The caller must fill in the following details:
7949 dirname, textlow, texthigh. */
7951 static struct partial_symtab
*
7952 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7954 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7955 struct partial_symtab
*pst
;
7957 pst
= start_psymtab_common (objfile
, name
, 0);
7959 pst
->psymtabs_addrmap_supported
= 1;
7961 /* This is the glue that links PST into GDB's symbol API. */
7962 pst
->read_symtab_private
= per_cu
;
7963 pst
->read_symtab
= dwarf2_read_symtab
;
7964 per_cu
->v
.psymtab
= pst
;
7969 /* The DATA object passed to process_psymtab_comp_unit_reader has this
7972 struct process_psymtab_comp_unit_data
7974 /* True if we are reading a DW_TAG_partial_unit. */
7976 int want_partial_unit
;
7978 /* The "pretend" language that is used if the CU doesn't declare a
7981 enum language pretend_language
;
7984 /* die_reader_func for process_psymtab_comp_unit. */
7987 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7988 const gdb_byte
*info_ptr
,
7989 struct die_info
*comp_unit_die
,
7993 struct dwarf2_cu
*cu
= reader
->cu
;
7994 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7995 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7996 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7998 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7999 struct partial_symtab
*pst
;
8000 enum pc_bounds_kind cu_bounds_kind
;
8001 const char *filename
;
8002 struct process_psymtab_comp_unit_data
*info
8003 = (struct process_psymtab_comp_unit_data
*) data
;
8005 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
8008 gdb_assert (! per_cu
->is_debug_types
);
8010 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
8012 /* Allocate a new partial symbol table structure. */
8013 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8014 if (filename
== NULL
)
8017 pst
= create_partial_symtab (per_cu
, filename
);
8019 /* This must be done before calling dwarf2_build_include_psymtabs. */
8020 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8022 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8024 dwarf2_find_base_address (comp_unit_die
, cu
);
8026 /* Possibly set the default values of LOWPC and HIGHPC from
8028 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8029 &best_highpc
, cu
, pst
);
8030 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8033 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
8036 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
8038 /* Store the contiguous range if it is not empty; it can be
8039 empty for CUs with no code. */
8040 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8044 /* Check if comp unit has_children.
8045 If so, read the rest of the partial symbols from this comp unit.
8046 If not, there's no more debug_info for this comp unit. */
8049 struct partial_die_info
*first_die
;
8050 CORE_ADDR lowpc
, highpc
;
8052 lowpc
= ((CORE_ADDR
) -1);
8053 highpc
= ((CORE_ADDR
) 0);
8055 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8057 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8058 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8060 /* If we didn't find a lowpc, set it to highpc to avoid
8061 complaints from `maint check'. */
8062 if (lowpc
== ((CORE_ADDR
) -1))
8065 /* If the compilation unit didn't have an explicit address range,
8066 then use the information extracted from its child dies. */
8067 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8070 best_highpc
= highpc
;
8073 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
8074 best_lowpc
+ baseaddr
)
8076 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
8077 best_highpc
+ baseaddr
)
8080 end_psymtab_common (objfile
, pst
);
8082 if (!cu
->per_cu
->imported_symtabs_empty ())
8085 int len
= cu
->per_cu
->imported_symtabs_size ();
8087 /* Fill in 'dependencies' here; we fill in 'users' in a
8089 pst
->number_of_dependencies
= len
;
8091 = objfile
->partial_symtabs
->allocate_dependencies (len
);
8092 for (i
= 0; i
< len
; ++i
)
8094 pst
->dependencies
[i
]
8095 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
8098 cu
->per_cu
->imported_symtabs_free ();
8101 /* Get the list of files included in the current compilation unit,
8102 and build a psymtab for each of them. */
8103 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8105 if (dwarf_read_debug
)
8106 fprintf_unfiltered (gdb_stdlog
,
8107 "Psymtab for %s unit @%s: %s - %s"
8108 ", %d global, %d static syms\n",
8109 per_cu
->is_debug_types
? "type" : "comp",
8110 sect_offset_str (per_cu
->sect_off
),
8111 paddress (gdbarch
, pst
->text_low (objfile
)),
8112 paddress (gdbarch
, pst
->text_high (objfile
)),
8113 pst
->n_global_syms
, pst
->n_static_syms
);
8116 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8117 Process compilation unit THIS_CU for a psymtab. */
8120 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8121 int want_partial_unit
,
8122 enum language pretend_language
)
8124 /* If this compilation unit was already read in, free the
8125 cached copy in order to read it in again. This is
8126 necessary because we skipped some symbols when we first
8127 read in the compilation unit (see load_partial_dies).
8128 This problem could be avoided, but the benefit is unclear. */
8129 if (this_cu
->cu
!= NULL
)
8130 free_one_cached_comp_unit (this_cu
);
8132 if (this_cu
->is_debug_types
)
8133 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8134 build_type_psymtabs_reader
, NULL
);
8137 process_psymtab_comp_unit_data info
;
8138 info
.want_partial_unit
= want_partial_unit
;
8139 info
.pretend_language
= pretend_language
;
8140 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8141 process_psymtab_comp_unit_reader
, &info
);
8144 /* Age out any secondary CUs. */
8145 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8148 /* Reader function for build_type_psymtabs. */
8151 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8152 const gdb_byte
*info_ptr
,
8153 struct die_info
*type_unit_die
,
8157 struct dwarf2_per_objfile
*dwarf2_per_objfile
8158 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8159 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8160 struct dwarf2_cu
*cu
= reader
->cu
;
8161 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8162 struct signatured_type
*sig_type
;
8163 struct type_unit_group
*tu_group
;
8164 struct attribute
*attr
;
8165 struct partial_die_info
*first_die
;
8166 CORE_ADDR lowpc
, highpc
;
8167 struct partial_symtab
*pst
;
8169 gdb_assert (data
== NULL
);
8170 gdb_assert (per_cu
->is_debug_types
);
8171 sig_type
= (struct signatured_type
*) per_cu
;
8176 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8177 tu_group
= get_type_unit_group (cu
, attr
);
8179 if (tu_group
->tus
== nullptr)
8180 tu_group
->tus
= new std::vector
<signatured_type
*>;
8181 tu_group
->tus
->push_back (sig_type
);
8183 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8184 pst
= create_partial_symtab (per_cu
, "");
8187 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8189 lowpc
= (CORE_ADDR
) -1;
8190 highpc
= (CORE_ADDR
) 0;
8191 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8193 end_psymtab_common (objfile
, pst
);
8196 /* Struct used to sort TUs by their abbreviation table offset. */
8198 struct tu_abbrev_offset
8200 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8201 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8204 signatured_type
*sig_type
;
8205 sect_offset abbrev_offset
;
8208 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8211 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8212 const struct tu_abbrev_offset
&b
)
8214 return a
.abbrev_offset
< b
.abbrev_offset
;
8217 /* Efficiently read all the type units.
8218 This does the bulk of the work for build_type_psymtabs.
8220 The efficiency is because we sort TUs by the abbrev table they use and
8221 only read each abbrev table once. In one program there are 200K TUs
8222 sharing 8K abbrev tables.
8224 The main purpose of this function is to support building the
8225 dwarf2_per_objfile->type_unit_groups table.
8226 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8227 can collapse the search space by grouping them by stmt_list.
8228 The savings can be significant, in the same program from above the 200K TUs
8229 share 8K stmt_list tables.
8231 FUNC is expected to call get_type_unit_group, which will create the
8232 struct type_unit_group if necessary and add it to
8233 dwarf2_per_objfile->type_unit_groups. */
8236 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8238 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8239 abbrev_table_up abbrev_table
;
8240 sect_offset abbrev_offset
;
8242 /* It's up to the caller to not call us multiple times. */
8243 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8245 if (dwarf2_per_objfile
->all_type_units
.empty ())
8248 /* TUs typically share abbrev tables, and there can be way more TUs than
8249 abbrev tables. Sort by abbrev table to reduce the number of times we
8250 read each abbrev table in.
8251 Alternatives are to punt or to maintain a cache of abbrev tables.
8252 This is simpler and efficient enough for now.
8254 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8255 symtab to use). Typically TUs with the same abbrev offset have the same
8256 stmt_list value too so in practice this should work well.
8258 The basic algorithm here is:
8260 sort TUs by abbrev table
8261 for each TU with same abbrev table:
8262 read abbrev table if first user
8263 read TU top level DIE
8264 [IWBN if DWO skeletons had DW_AT_stmt_list]
8267 if (dwarf_read_debug
)
8268 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8270 /* Sort in a separate table to maintain the order of all_type_units
8271 for .gdb_index: TU indices directly index all_type_units. */
8272 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8273 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8275 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8276 sorted_by_abbrev
.emplace_back
8277 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8278 sig_type
->per_cu
.section
,
8279 sig_type
->per_cu
.sect_off
));
8281 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8282 sort_tu_by_abbrev_offset
);
8284 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8286 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8288 /* Switch to the next abbrev table if necessary. */
8289 if (abbrev_table
== NULL
8290 || tu
.abbrev_offset
!= abbrev_offset
)
8292 abbrev_offset
= tu
.abbrev_offset
;
8294 abbrev_table_read_table (dwarf2_per_objfile
,
8295 &dwarf2_per_objfile
->abbrev
,
8297 ++tu_stats
->nr_uniq_abbrev_tables
;
8300 init_cutu_and_read_dies (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8301 0, 0, false, build_type_psymtabs_reader
, NULL
);
8305 /* Print collected type unit statistics. */
8308 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8310 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8312 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8313 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8314 dwarf2_per_objfile
->all_type_units
.size ());
8315 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8316 tu_stats
->nr_uniq_abbrev_tables
);
8317 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8318 tu_stats
->nr_symtabs
);
8319 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8320 tu_stats
->nr_symtab_sharers
);
8321 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8322 tu_stats
->nr_stmt_less_type_units
);
8323 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8324 tu_stats
->nr_all_type_units_reallocs
);
8327 /* Traversal function for build_type_psymtabs. */
8330 build_type_psymtab_dependencies (void **slot
, void *info
)
8332 struct dwarf2_per_objfile
*dwarf2_per_objfile
8333 = (struct dwarf2_per_objfile
*) info
;
8334 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8335 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8336 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8337 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8338 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8341 gdb_assert (len
> 0);
8342 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8344 pst
->number_of_dependencies
= len
;
8345 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8346 for (i
= 0; i
< len
; ++i
)
8348 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8349 gdb_assert (iter
->per_cu
.is_debug_types
);
8350 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8351 iter
->type_unit_group
= tu_group
;
8354 delete tu_group
->tus
;
8355 tu_group
->tus
= nullptr;
8360 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8361 Build partial symbol tables for the .debug_types comp-units. */
8364 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8366 if (! create_all_type_units (dwarf2_per_objfile
))
8369 build_type_psymtabs_1 (dwarf2_per_objfile
);
8372 /* Traversal function for process_skeletonless_type_unit.
8373 Read a TU in a DWO file and build partial symbols for it. */
8376 process_skeletonless_type_unit (void **slot
, void *info
)
8378 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8379 struct dwarf2_per_objfile
*dwarf2_per_objfile
8380 = (struct dwarf2_per_objfile
*) info
;
8381 struct signatured_type find_entry
, *entry
;
8383 /* If this TU doesn't exist in the global table, add it and read it in. */
8385 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8387 dwarf2_per_objfile
->signatured_types
8388 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8391 find_entry
.signature
= dwo_unit
->signature
;
8392 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8394 /* If we've already seen this type there's nothing to do. What's happening
8395 is we're doing our own version of comdat-folding here. */
8399 /* This does the job that create_all_type_units would have done for
8401 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8402 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8405 /* This does the job that build_type_psymtabs_1 would have done. */
8406 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0, false,
8407 build_type_psymtabs_reader
, NULL
);
8412 /* Traversal function for process_skeletonless_type_units. */
8415 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8417 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8419 if (dwo_file
->tus
!= NULL
)
8421 htab_traverse_noresize (dwo_file
->tus
,
8422 process_skeletonless_type_unit
, info
);
8428 /* Scan all TUs of DWO files, verifying we've processed them.
8429 This is needed in case a TU was emitted without its skeleton.
8430 Note: This can't be done until we know what all the DWO files are. */
8433 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8435 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8436 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8437 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8439 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8440 process_dwo_file_for_skeletonless_type_units
,
8441 dwarf2_per_objfile
);
8445 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8448 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8450 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8452 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8457 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8459 /* Set the 'user' field only if it is not already set. */
8460 if (pst
->dependencies
[j
]->user
== NULL
)
8461 pst
->dependencies
[j
]->user
= pst
;
8466 /* Build the partial symbol table by doing a quick pass through the
8467 .debug_info and .debug_abbrev sections. */
8470 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8472 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8474 if (dwarf_read_debug
)
8476 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8477 objfile_name (objfile
));
8480 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8482 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8484 /* Any cached compilation units will be linked by the per-objfile
8485 read_in_chain. Make sure to free them when we're done. */
8486 free_cached_comp_units
freer (dwarf2_per_objfile
);
8488 build_type_psymtabs (dwarf2_per_objfile
);
8490 create_all_comp_units (dwarf2_per_objfile
);
8492 /* Create a temporary address map on a temporary obstack. We later
8493 copy this to the final obstack. */
8494 auto_obstack temp_obstack
;
8496 scoped_restore save_psymtabs_addrmap
8497 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8498 addrmap_create_mutable (&temp_obstack
));
8500 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8501 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8503 /* This has to wait until we read the CUs, we need the list of DWOs. */
8504 process_skeletonless_type_units (dwarf2_per_objfile
);
8506 /* Now that all TUs have been processed we can fill in the dependencies. */
8507 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8509 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8510 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8513 if (dwarf_read_debug
)
8514 print_tu_stats (dwarf2_per_objfile
);
8516 set_partial_user (dwarf2_per_objfile
);
8518 objfile
->partial_symtabs
->psymtabs_addrmap
8519 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8520 objfile
->partial_symtabs
->obstack ());
8521 /* At this point we want to keep the address map. */
8522 save_psymtabs_addrmap
.release ();
8524 if (dwarf_read_debug
)
8525 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8526 objfile_name (objfile
));
8529 /* die_reader_func for load_partial_comp_unit. */
8532 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8533 const gdb_byte
*info_ptr
,
8534 struct die_info
*comp_unit_die
,
8538 struct dwarf2_cu
*cu
= reader
->cu
;
8540 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8542 /* Check if comp unit has_children.
8543 If so, read the rest of the partial symbols from this comp unit.
8544 If not, there's no more debug_info for this comp unit. */
8546 load_partial_dies (reader
, info_ptr
, 0);
8549 /* Load the partial DIEs for a secondary CU into memory.
8550 This is also used when rereading a primary CU with load_all_dies. */
8553 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8555 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, false,
8556 load_partial_comp_unit_reader
, NULL
);
8560 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8561 struct dwarf2_section_info
*section
,
8562 struct dwarf2_section_info
*abbrev_section
,
8563 unsigned int is_dwz
)
8565 const gdb_byte
*info_ptr
;
8566 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8568 if (dwarf_read_debug
)
8569 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8570 get_section_name (section
),
8571 get_section_file_name (section
));
8573 dwarf2_read_section (objfile
, section
);
8575 info_ptr
= section
->buffer
;
8577 while (info_ptr
< section
->buffer
+ section
->size
)
8579 struct dwarf2_per_cu_data
*this_cu
;
8581 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8583 comp_unit_head cu_header
;
8584 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8585 abbrev_section
, info_ptr
,
8586 rcuh_kind::COMPILE
);
8588 /* Save the compilation unit for later lookup. */
8589 if (cu_header
.unit_type
!= DW_UT_type
)
8591 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8592 struct dwarf2_per_cu_data
);
8593 memset (this_cu
, 0, sizeof (*this_cu
));
8597 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8598 struct signatured_type
);
8599 memset (sig_type
, 0, sizeof (*sig_type
));
8600 sig_type
->signature
= cu_header
.signature
;
8601 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8602 this_cu
= &sig_type
->per_cu
;
8604 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8605 this_cu
->sect_off
= sect_off
;
8606 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8607 this_cu
->is_dwz
= is_dwz
;
8608 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8609 this_cu
->section
= section
;
8611 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8613 info_ptr
= info_ptr
+ this_cu
->length
;
8617 /* Create a list of all compilation units in OBJFILE.
8618 This is only done for -readnow and building partial symtabs. */
8621 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8623 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8624 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8625 &dwarf2_per_objfile
->abbrev
, 0);
8627 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8629 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8633 /* Process all loaded DIEs for compilation unit CU, starting at
8634 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8635 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8636 DW_AT_ranges). See the comments of add_partial_subprogram on how
8637 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8640 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8641 CORE_ADDR
*highpc
, int set_addrmap
,
8642 struct dwarf2_cu
*cu
)
8644 struct partial_die_info
*pdi
;
8646 /* Now, march along the PDI's, descending into ones which have
8647 interesting children but skipping the children of the other ones,
8648 until we reach the end of the compilation unit. */
8656 /* Anonymous namespaces or modules have no name but have interesting
8657 children, so we need to look at them. Ditto for anonymous
8660 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8661 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8662 || pdi
->tag
== DW_TAG_imported_unit
8663 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8667 case DW_TAG_subprogram
:
8668 case DW_TAG_inlined_subroutine
:
8669 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8671 case DW_TAG_constant
:
8672 case DW_TAG_variable
:
8673 case DW_TAG_typedef
:
8674 case DW_TAG_union_type
:
8675 if (!pdi
->is_declaration
)
8677 add_partial_symbol (pdi
, cu
);
8680 case DW_TAG_class_type
:
8681 case DW_TAG_interface_type
:
8682 case DW_TAG_structure_type
:
8683 if (!pdi
->is_declaration
)
8685 add_partial_symbol (pdi
, cu
);
8687 if ((cu
->language
== language_rust
8688 || cu
->language
== language_cplus
) && pdi
->has_children
)
8689 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8692 case DW_TAG_enumeration_type
:
8693 if (!pdi
->is_declaration
)
8694 add_partial_enumeration (pdi
, cu
);
8696 case DW_TAG_base_type
:
8697 case DW_TAG_subrange_type
:
8698 /* File scope base type definitions are added to the partial
8700 add_partial_symbol (pdi
, cu
);
8702 case DW_TAG_namespace
:
8703 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8706 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8708 case DW_TAG_imported_unit
:
8710 struct dwarf2_per_cu_data
*per_cu
;
8712 /* For now we don't handle imported units in type units. */
8713 if (cu
->per_cu
->is_debug_types
)
8715 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8716 " supported in type units [in module %s]"),
8717 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8720 per_cu
= dwarf2_find_containing_comp_unit
8721 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8722 cu
->per_cu
->dwarf2_per_objfile
);
8724 /* Go read the partial unit, if needed. */
8725 if (per_cu
->v
.psymtab
== NULL
)
8726 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8728 cu
->per_cu
->imported_symtabs_push (per_cu
);
8731 case DW_TAG_imported_declaration
:
8732 add_partial_symbol (pdi
, cu
);
8739 /* If the die has a sibling, skip to the sibling. */
8741 pdi
= pdi
->die_sibling
;
8745 /* Functions used to compute the fully scoped name of a partial DIE.
8747 Normally, this is simple. For C++, the parent DIE's fully scoped
8748 name is concatenated with "::" and the partial DIE's name.
8749 Enumerators are an exception; they use the scope of their parent
8750 enumeration type, i.e. the name of the enumeration type is not
8751 prepended to the enumerator.
8753 There are two complexities. One is DW_AT_specification; in this
8754 case "parent" means the parent of the target of the specification,
8755 instead of the direct parent of the DIE. The other is compilers
8756 which do not emit DW_TAG_namespace; in this case we try to guess
8757 the fully qualified name of structure types from their members'
8758 linkage names. This must be done using the DIE's children rather
8759 than the children of any DW_AT_specification target. We only need
8760 to do this for structures at the top level, i.e. if the target of
8761 any DW_AT_specification (if any; otherwise the DIE itself) does not
8764 /* Compute the scope prefix associated with PDI's parent, in
8765 compilation unit CU. The result will be allocated on CU's
8766 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8767 field. NULL is returned if no prefix is necessary. */
8769 partial_die_parent_scope (struct partial_die_info
*pdi
,
8770 struct dwarf2_cu
*cu
)
8772 const char *grandparent_scope
;
8773 struct partial_die_info
*parent
, *real_pdi
;
8775 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8776 then this means the parent of the specification DIE. */
8779 while (real_pdi
->has_specification
)
8781 auto res
= find_partial_die (real_pdi
->spec_offset
,
8782 real_pdi
->spec_is_dwz
, cu
);
8787 parent
= real_pdi
->die_parent
;
8791 if (parent
->scope_set
)
8792 return parent
->scope
;
8796 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8798 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8799 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8800 Work around this problem here. */
8801 if (cu
->language
== language_cplus
8802 && parent
->tag
== DW_TAG_namespace
8803 && strcmp (parent
->name
, "::") == 0
8804 && grandparent_scope
== NULL
)
8806 parent
->scope
= NULL
;
8807 parent
->scope_set
= 1;
8811 /* Nested subroutines in Fortran get a prefix. */
8812 if (pdi
->tag
== DW_TAG_enumerator
)
8813 /* Enumerators should not get the name of the enumeration as a prefix. */
8814 parent
->scope
= grandparent_scope
;
8815 else if (parent
->tag
== DW_TAG_namespace
8816 || parent
->tag
== DW_TAG_module
8817 || parent
->tag
== DW_TAG_structure_type
8818 || parent
->tag
== DW_TAG_class_type
8819 || parent
->tag
== DW_TAG_interface_type
8820 || parent
->tag
== DW_TAG_union_type
8821 || parent
->tag
== DW_TAG_enumeration_type
8822 || (cu
->language
== language_fortran
8823 && parent
->tag
== DW_TAG_subprogram
8824 && pdi
->tag
== DW_TAG_subprogram
))
8826 if (grandparent_scope
== NULL
)
8827 parent
->scope
= parent
->name
;
8829 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8831 parent
->name
, 0, cu
);
8835 /* FIXME drow/2004-04-01: What should we be doing with
8836 function-local names? For partial symbols, we should probably be
8838 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8839 dwarf_tag_name (parent
->tag
),
8840 sect_offset_str (pdi
->sect_off
));
8841 parent
->scope
= grandparent_scope
;
8844 parent
->scope_set
= 1;
8845 return parent
->scope
;
8848 /* Return the fully scoped name associated with PDI, from compilation unit
8849 CU. The result will be allocated with malloc. */
8852 partial_die_full_name (struct partial_die_info
*pdi
,
8853 struct dwarf2_cu
*cu
)
8855 const char *parent_scope
;
8857 /* If this is a template instantiation, we can not work out the
8858 template arguments from partial DIEs. So, unfortunately, we have
8859 to go through the full DIEs. At least any work we do building
8860 types here will be reused if full symbols are loaded later. */
8861 if (pdi
->has_template_arguments
)
8865 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8867 struct die_info
*die
;
8868 struct attribute attr
;
8869 struct dwarf2_cu
*ref_cu
= cu
;
8871 /* DW_FORM_ref_addr is using section offset. */
8872 attr
.name
= (enum dwarf_attribute
) 0;
8873 attr
.form
= DW_FORM_ref_addr
;
8874 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8875 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8877 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8881 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8882 if (parent_scope
== NULL
)
8885 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
8889 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8891 struct dwarf2_per_objfile
*dwarf2_per_objfile
8892 = cu
->per_cu
->dwarf2_per_objfile
;
8893 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8894 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8896 const char *actual_name
= NULL
;
8898 char *built_actual_name
;
8900 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8902 built_actual_name
= partial_die_full_name (pdi
, cu
);
8903 if (built_actual_name
!= NULL
)
8904 actual_name
= built_actual_name
;
8906 if (actual_name
== NULL
)
8907 actual_name
= pdi
->name
;
8911 case DW_TAG_inlined_subroutine
:
8912 case DW_TAG_subprogram
:
8913 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8915 if (pdi
->is_external
8916 || cu
->language
== language_ada
8917 || (cu
->language
== language_fortran
8918 && pdi
->die_parent
!= NULL
8919 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8921 /* Normally, only "external" DIEs are part of the global scope.
8922 But in Ada and Fortran, we want to be able to access nested
8923 procedures globally. So all Ada and Fortran subprograms are
8924 stored in the global scope. */
8925 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8926 built_actual_name
!= NULL
,
8927 VAR_DOMAIN
, LOC_BLOCK
,
8928 SECT_OFF_TEXT (objfile
),
8929 psymbol_placement::GLOBAL
,
8931 cu
->language
, objfile
);
8935 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8936 built_actual_name
!= NULL
,
8937 VAR_DOMAIN
, LOC_BLOCK
,
8938 SECT_OFF_TEXT (objfile
),
8939 psymbol_placement::STATIC
,
8940 addr
, cu
->language
, objfile
);
8943 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8944 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8946 case DW_TAG_constant
:
8947 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8948 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8949 -1, (pdi
->is_external
8950 ? psymbol_placement::GLOBAL
8951 : psymbol_placement::STATIC
),
8952 0, cu
->language
, objfile
);
8954 case DW_TAG_variable
:
8956 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8960 && !dwarf2_per_objfile
->has_section_at_zero
)
8962 /* A global or static variable may also have been stripped
8963 out by the linker if unused, in which case its address
8964 will be nullified; do not add such variables into partial
8965 symbol table then. */
8967 else if (pdi
->is_external
)
8970 Don't enter into the minimal symbol tables as there is
8971 a minimal symbol table entry from the ELF symbols already.
8972 Enter into partial symbol table if it has a location
8973 descriptor or a type.
8974 If the location descriptor is missing, new_symbol will create
8975 a LOC_UNRESOLVED symbol, the address of the variable will then
8976 be determined from the minimal symbol table whenever the variable
8978 The address for the partial symbol table entry is not
8979 used by GDB, but it comes in handy for debugging partial symbol
8982 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8983 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8984 built_actual_name
!= NULL
,
8985 VAR_DOMAIN
, LOC_STATIC
,
8986 SECT_OFF_TEXT (objfile
),
8987 psymbol_placement::GLOBAL
,
8988 addr
, cu
->language
, objfile
);
8992 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8994 /* Static Variable. Skip symbols whose value we cannot know (those
8995 without location descriptors or constant values). */
8996 if (!has_loc
&& !pdi
->has_const_value
)
8998 xfree (built_actual_name
);
9002 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9003 built_actual_name
!= NULL
,
9004 VAR_DOMAIN
, LOC_STATIC
,
9005 SECT_OFF_TEXT (objfile
),
9006 psymbol_placement::STATIC
,
9008 cu
->language
, objfile
);
9011 case DW_TAG_typedef
:
9012 case DW_TAG_base_type
:
9013 case DW_TAG_subrange_type
:
9014 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9015 built_actual_name
!= NULL
,
9016 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9017 psymbol_placement::STATIC
,
9018 0, cu
->language
, objfile
);
9020 case DW_TAG_imported_declaration
:
9021 case DW_TAG_namespace
:
9022 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9023 built_actual_name
!= NULL
,
9024 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9025 psymbol_placement::GLOBAL
,
9026 0, cu
->language
, objfile
);
9029 /* With Fortran 77 there might be a "BLOCK DATA" module
9030 available without any name. If so, we skip the module as it
9031 doesn't bring any value. */
9032 if (actual_name
!= nullptr)
9033 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9034 built_actual_name
!= NULL
,
9035 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
9036 psymbol_placement::GLOBAL
,
9037 0, cu
->language
, objfile
);
9039 case DW_TAG_class_type
:
9040 case DW_TAG_interface_type
:
9041 case DW_TAG_structure_type
:
9042 case DW_TAG_union_type
:
9043 case DW_TAG_enumeration_type
:
9044 /* Skip external references. The DWARF standard says in the section
9045 about "Structure, Union, and Class Type Entries": "An incomplete
9046 structure, union or class type is represented by a structure,
9047 union or class entry that does not have a byte size attribute
9048 and that has a DW_AT_declaration attribute." */
9049 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9051 xfree (built_actual_name
);
9055 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9056 static vs. global. */
9057 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9058 built_actual_name
!= NULL
,
9059 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
9060 cu
->language
== language_cplus
9061 ? psymbol_placement::GLOBAL
9062 : psymbol_placement::STATIC
,
9063 0, cu
->language
, objfile
);
9066 case DW_TAG_enumerator
:
9067 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9068 built_actual_name
!= NULL
,
9069 VAR_DOMAIN
, LOC_CONST
, -1,
9070 cu
->language
== language_cplus
9071 ? psymbol_placement::GLOBAL
9072 : psymbol_placement::STATIC
,
9073 0, cu
->language
, objfile
);
9079 xfree (built_actual_name
);
9082 /* Read a partial die corresponding to a namespace; also, add a symbol
9083 corresponding to that namespace to the symbol table. NAMESPACE is
9084 the name of the enclosing namespace. */
9087 add_partial_namespace (struct partial_die_info
*pdi
,
9088 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9089 int set_addrmap
, struct dwarf2_cu
*cu
)
9091 /* Add a symbol for the namespace. */
9093 add_partial_symbol (pdi
, cu
);
9095 /* Now scan partial symbols in that namespace. */
9097 if (pdi
->has_children
)
9098 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9101 /* Read a partial die corresponding to a Fortran module. */
9104 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9105 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9107 /* Add a symbol for the namespace. */
9109 add_partial_symbol (pdi
, cu
);
9111 /* Now scan partial symbols in that module. */
9113 if (pdi
->has_children
)
9114 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9117 /* Read a partial die corresponding to a subprogram or an inlined
9118 subprogram and create a partial symbol for that subprogram.
9119 When the CU language allows it, this routine also defines a partial
9120 symbol for each nested subprogram that this subprogram contains.
9121 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9122 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9124 PDI may also be a lexical block, in which case we simply search
9125 recursively for subprograms defined inside that lexical block.
9126 Again, this is only performed when the CU language allows this
9127 type of definitions. */
9130 add_partial_subprogram (struct partial_die_info
*pdi
,
9131 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9132 int set_addrmap
, struct dwarf2_cu
*cu
)
9134 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9136 if (pdi
->has_pc_info
)
9138 if (pdi
->lowpc
< *lowpc
)
9139 *lowpc
= pdi
->lowpc
;
9140 if (pdi
->highpc
> *highpc
)
9141 *highpc
= pdi
->highpc
;
9144 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9145 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9147 CORE_ADDR this_highpc
;
9148 CORE_ADDR this_lowpc
;
9150 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9151 SECT_OFF_TEXT (objfile
));
9153 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9154 pdi
->lowpc
+ baseaddr
)
9157 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9158 pdi
->highpc
+ baseaddr
)
9160 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
9161 this_lowpc
, this_highpc
- 1,
9162 cu
->per_cu
->v
.psymtab
);
9166 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9168 if (!pdi
->is_declaration
)
9169 /* Ignore subprogram DIEs that do not have a name, they are
9170 illegal. Do not emit a complaint at this point, we will
9171 do so when we convert this psymtab into a symtab. */
9173 add_partial_symbol (pdi
, cu
);
9177 if (! pdi
->has_children
)
9180 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
9182 pdi
= pdi
->die_child
;
9186 if (pdi
->tag
== DW_TAG_subprogram
9187 || pdi
->tag
== DW_TAG_inlined_subroutine
9188 || pdi
->tag
== DW_TAG_lexical_block
)
9189 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9190 pdi
= pdi
->die_sibling
;
9195 /* Read a partial die corresponding to an enumeration type. */
9198 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9199 struct dwarf2_cu
*cu
)
9201 struct partial_die_info
*pdi
;
9203 if (enum_pdi
->name
!= NULL
)
9204 add_partial_symbol (enum_pdi
, cu
);
9206 pdi
= enum_pdi
->die_child
;
9209 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9210 complaint (_("malformed enumerator DIE ignored"));
9212 add_partial_symbol (pdi
, cu
);
9213 pdi
= pdi
->die_sibling
;
9217 /* Return the initial uleb128 in the die at INFO_PTR. */
9220 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9222 unsigned int bytes_read
;
9224 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9227 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9228 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9230 Return the corresponding abbrev, or NULL if the number is zero (indicating
9231 an empty DIE). In either case *BYTES_READ will be set to the length of
9232 the initial number. */
9234 static struct abbrev_info
*
9235 peek_die_abbrev (const die_reader_specs
&reader
,
9236 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9238 dwarf2_cu
*cu
= reader
.cu
;
9239 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9240 unsigned int abbrev_number
9241 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9243 if (abbrev_number
== 0)
9246 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9249 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9250 " at offset %s [in module %s]"),
9251 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9252 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9258 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9259 Returns a pointer to the end of a series of DIEs, terminated by an empty
9260 DIE. Any children of the skipped DIEs will also be skipped. */
9262 static const gdb_byte
*
9263 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9267 unsigned int bytes_read
;
9268 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9271 return info_ptr
+ bytes_read
;
9273 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9277 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9278 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9279 abbrev corresponding to that skipped uleb128 should be passed in
9280 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9283 static const gdb_byte
*
9284 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9285 struct abbrev_info
*abbrev
)
9287 unsigned int bytes_read
;
9288 struct attribute attr
;
9289 bfd
*abfd
= reader
->abfd
;
9290 struct dwarf2_cu
*cu
= reader
->cu
;
9291 const gdb_byte
*buffer
= reader
->buffer
;
9292 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9293 unsigned int form
, i
;
9295 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9297 /* The only abbrev we care about is DW_AT_sibling. */
9298 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9300 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9301 if (attr
.form
== DW_FORM_ref_addr
)
9302 complaint (_("ignoring absolute DW_AT_sibling"));
9305 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9306 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9308 if (sibling_ptr
< info_ptr
)
9309 complaint (_("DW_AT_sibling points backwards"));
9310 else if (sibling_ptr
> reader
->buffer_end
)
9311 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9317 /* If it isn't DW_AT_sibling, skip this attribute. */
9318 form
= abbrev
->attrs
[i
].form
;
9322 case DW_FORM_ref_addr
:
9323 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9324 and later it is offset sized. */
9325 if (cu
->header
.version
== 2)
9326 info_ptr
+= cu
->header
.addr_size
;
9328 info_ptr
+= cu
->header
.offset_size
;
9330 case DW_FORM_GNU_ref_alt
:
9331 info_ptr
+= cu
->header
.offset_size
;
9334 info_ptr
+= cu
->header
.addr_size
;
9342 case DW_FORM_flag_present
:
9343 case DW_FORM_implicit_const
:
9360 case DW_FORM_ref_sig8
:
9363 case DW_FORM_data16
:
9366 case DW_FORM_string
:
9367 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9368 info_ptr
+= bytes_read
;
9370 case DW_FORM_sec_offset
:
9372 case DW_FORM_GNU_strp_alt
:
9373 info_ptr
+= cu
->header
.offset_size
;
9375 case DW_FORM_exprloc
:
9377 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9378 info_ptr
+= bytes_read
;
9380 case DW_FORM_block1
:
9381 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9383 case DW_FORM_block2
:
9384 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9386 case DW_FORM_block4
:
9387 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9393 case DW_FORM_ref_udata
:
9394 case DW_FORM_GNU_addr_index
:
9395 case DW_FORM_GNU_str_index
:
9396 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9398 case DW_FORM_indirect
:
9399 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9400 info_ptr
+= bytes_read
;
9401 /* We need to continue parsing from here, so just go back to
9403 goto skip_attribute
;
9406 error (_("Dwarf Error: Cannot handle %s "
9407 "in DWARF reader [in module %s]"),
9408 dwarf_form_name (form
),
9409 bfd_get_filename (abfd
));
9413 if (abbrev
->has_children
)
9414 return skip_children (reader
, info_ptr
);
9419 /* Locate ORIG_PDI's sibling.
9420 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9422 static const gdb_byte
*
9423 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9424 struct partial_die_info
*orig_pdi
,
9425 const gdb_byte
*info_ptr
)
9427 /* Do we know the sibling already? */
9429 if (orig_pdi
->sibling
)
9430 return orig_pdi
->sibling
;
9432 /* Are there any children to deal with? */
9434 if (!orig_pdi
->has_children
)
9437 /* Skip the children the long way. */
9439 return skip_children (reader
, info_ptr
);
9442 /* Expand this partial symbol table into a full symbol table. SELF is
9446 dwarf2_read_symtab (struct partial_symtab
*self
,
9447 struct objfile
*objfile
)
9449 struct dwarf2_per_objfile
*dwarf2_per_objfile
9450 = get_dwarf2_per_objfile (objfile
);
9454 warning (_("bug: psymtab for %s is already read in."),
9461 printf_filtered (_("Reading in symbols for %s..."),
9463 gdb_flush (gdb_stdout
);
9466 /* If this psymtab is constructed from a debug-only objfile, the
9467 has_section_at_zero flag will not necessarily be correct. We
9468 can get the correct value for this flag by looking at the data
9469 associated with the (presumably stripped) associated objfile. */
9470 if (objfile
->separate_debug_objfile_backlink
)
9472 struct dwarf2_per_objfile
*dpo_backlink
9473 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9475 dwarf2_per_objfile
->has_section_at_zero
9476 = dpo_backlink
->has_section_at_zero
;
9479 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9481 psymtab_to_symtab_1 (self
);
9483 /* Finish up the debug error message. */
9485 printf_filtered (_("done.\n"));
9488 process_cu_includes (dwarf2_per_objfile
);
9491 /* Reading in full CUs. */
9493 /* Add PER_CU to the queue. */
9496 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9497 enum language pretend_language
)
9499 struct dwarf2_queue_item
*item
;
9502 item
= XNEW (struct dwarf2_queue_item
);
9503 item
->per_cu
= per_cu
;
9504 item
->pretend_language
= pretend_language
;
9507 if (dwarf2_queue
== NULL
)
9508 dwarf2_queue
= item
;
9510 dwarf2_queue_tail
->next
= item
;
9512 dwarf2_queue_tail
= item
;
9515 /* If PER_CU is not yet queued, add it to the queue.
9516 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9518 The result is non-zero if PER_CU was queued, otherwise the result is zero
9519 meaning either PER_CU is already queued or it is already loaded.
9521 N.B. There is an invariant here that if a CU is queued then it is loaded.
9522 The caller is required to load PER_CU if we return non-zero. */
9525 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9526 struct dwarf2_per_cu_data
*per_cu
,
9527 enum language pretend_language
)
9529 /* We may arrive here during partial symbol reading, if we need full
9530 DIEs to process an unusual case (e.g. template arguments). Do
9531 not queue PER_CU, just tell our caller to load its DIEs. */
9532 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9534 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9539 /* Mark the dependence relation so that we don't flush PER_CU
9541 if (dependent_cu
!= NULL
)
9542 dwarf2_add_dependence (dependent_cu
, per_cu
);
9544 /* If it's already on the queue, we have nothing to do. */
9548 /* If the compilation unit is already loaded, just mark it as
9550 if (per_cu
->cu
!= NULL
)
9552 per_cu
->cu
->last_used
= 0;
9556 /* Add it to the queue. */
9557 queue_comp_unit (per_cu
, pretend_language
);
9562 /* Process the queue. */
9565 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9567 struct dwarf2_queue_item
*item
, *next_item
;
9569 if (dwarf_read_debug
)
9571 fprintf_unfiltered (gdb_stdlog
,
9572 "Expanding one or more symtabs of objfile %s ...\n",
9573 objfile_name (dwarf2_per_objfile
->objfile
));
9576 /* The queue starts out with one item, but following a DIE reference
9577 may load a new CU, adding it to the end of the queue. */
9578 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9580 if ((dwarf2_per_objfile
->using_index
9581 ? !item
->per_cu
->v
.quick
->compunit_symtab
9582 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9583 /* Skip dummy CUs. */
9584 && item
->per_cu
->cu
!= NULL
)
9586 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9587 unsigned int debug_print_threshold
;
9590 if (per_cu
->is_debug_types
)
9592 struct signatured_type
*sig_type
=
9593 (struct signatured_type
*) per_cu
;
9595 sprintf (buf
, "TU %s at offset %s",
9596 hex_string (sig_type
->signature
),
9597 sect_offset_str (per_cu
->sect_off
));
9598 /* There can be 100s of TUs.
9599 Only print them in verbose mode. */
9600 debug_print_threshold
= 2;
9604 sprintf (buf
, "CU at offset %s",
9605 sect_offset_str (per_cu
->sect_off
));
9606 debug_print_threshold
= 1;
9609 if (dwarf_read_debug
>= debug_print_threshold
)
9610 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9612 if (per_cu
->is_debug_types
)
9613 process_full_type_unit (per_cu
, item
->pretend_language
);
9615 process_full_comp_unit (per_cu
, item
->pretend_language
);
9617 if (dwarf_read_debug
>= debug_print_threshold
)
9618 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9621 item
->per_cu
->queued
= 0;
9622 next_item
= item
->next
;
9626 dwarf2_queue_tail
= NULL
;
9628 if (dwarf_read_debug
)
9630 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9631 objfile_name (dwarf2_per_objfile
->objfile
));
9635 /* Read in full symbols for PST, and anything it depends on. */
9638 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9640 struct dwarf2_per_cu_data
*per_cu
;
9646 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9647 if (!pst
->dependencies
[i
]->readin
9648 && pst
->dependencies
[i
]->user
== NULL
)
9650 /* Inform about additional files that need to be read in. */
9653 /* FIXME: i18n: Need to make this a single string. */
9654 fputs_filtered (" ", gdb_stdout
);
9656 fputs_filtered ("and ", gdb_stdout
);
9658 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9659 wrap_here (""); /* Flush output. */
9660 gdb_flush (gdb_stdout
);
9662 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9665 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9669 /* It's an include file, no symbols to read for it.
9670 Everything is in the parent symtab. */
9675 dw2_do_instantiate_symtab (per_cu
, false);
9678 /* Trivial hash function for die_info: the hash value of a DIE
9679 is its offset in .debug_info for this objfile. */
9682 die_hash (const void *item
)
9684 const struct die_info
*die
= (const struct die_info
*) item
;
9686 return to_underlying (die
->sect_off
);
9689 /* Trivial comparison function for die_info structures: two DIEs
9690 are equal if they have the same offset. */
9693 die_eq (const void *item_lhs
, const void *item_rhs
)
9695 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9696 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9698 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9701 /* die_reader_func for load_full_comp_unit.
9702 This is identical to read_signatured_type_reader,
9703 but is kept separate for now. */
9706 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9707 const gdb_byte
*info_ptr
,
9708 struct die_info
*comp_unit_die
,
9712 struct dwarf2_cu
*cu
= reader
->cu
;
9713 enum language
*language_ptr
= (enum language
*) data
;
9715 gdb_assert (cu
->die_hash
== NULL
);
9717 htab_create_alloc_ex (cu
->header
.length
/ 12,
9721 &cu
->comp_unit_obstack
,
9722 hashtab_obstack_allocate
,
9723 dummy_obstack_deallocate
);
9726 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9727 &info_ptr
, comp_unit_die
);
9728 cu
->dies
= comp_unit_die
;
9729 /* comp_unit_die is not stored in die_hash, no need. */
9731 /* We try not to read any attributes in this function, because not
9732 all CUs needed for references have been loaded yet, and symbol
9733 table processing isn't initialized. But we have to set the CU language,
9734 or we won't be able to build types correctly.
9735 Similarly, if we do not read the producer, we can not apply
9736 producer-specific interpretation. */
9737 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9740 /* Load the DIEs associated with PER_CU into memory. */
9743 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9745 enum language pretend_language
)
9747 gdb_assert (! this_cu
->is_debug_types
);
9749 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, skip_partial
,
9750 load_full_comp_unit_reader
, &pretend_language
);
9753 /* Add a DIE to the delayed physname list. */
9756 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9757 const char *name
, struct die_info
*die
,
9758 struct dwarf2_cu
*cu
)
9760 struct delayed_method_info mi
;
9762 mi
.fnfield_index
= fnfield_index
;
9766 cu
->method_list
.push_back (mi
);
9769 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9770 "const" / "volatile". If so, decrements LEN by the length of the
9771 modifier and return true. Otherwise return false. */
9775 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9777 size_t mod_len
= sizeof (mod
) - 1;
9778 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9786 /* Compute the physnames of any methods on the CU's method list.
9788 The computation of method physnames is delayed in order to avoid the
9789 (bad) condition that one of the method's formal parameters is of an as yet
9793 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9795 /* Only C++ delays computing physnames. */
9796 if (cu
->method_list
.empty ())
9798 gdb_assert (cu
->language
== language_cplus
);
9800 for (const delayed_method_info
&mi
: cu
->method_list
)
9802 const char *physname
;
9803 struct fn_fieldlist
*fn_flp
9804 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9805 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9806 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9807 = physname
? physname
: "";
9809 /* Since there's no tag to indicate whether a method is a
9810 const/volatile overload, extract that information out of the
9812 if (physname
!= NULL
)
9814 size_t len
= strlen (physname
);
9818 if (physname
[len
] == ')') /* shortcut */
9820 else if (check_modifier (physname
, len
, " const"))
9821 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9822 else if (check_modifier (physname
, len
, " volatile"))
9823 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9830 /* The list is no longer needed. */
9831 cu
->method_list
.clear ();
9834 /* Go objects should be embedded in a DW_TAG_module DIE,
9835 and it's not clear if/how imported objects will appear.
9836 To keep Go support simple until that's worked out,
9837 go back through what we've read and create something usable.
9838 We could do this while processing each DIE, and feels kinda cleaner,
9839 but that way is more invasive.
9840 This is to, for example, allow the user to type "p var" or "b main"
9841 without having to specify the package name, and allow lookups
9842 of module.object to work in contexts that use the expression
9846 fixup_go_packaging (struct dwarf2_cu
*cu
)
9848 char *package_name
= NULL
;
9849 struct pending
*list
;
9852 for (list
= *cu
->get_builder ()->get_global_symbols ();
9856 for (i
= 0; i
< list
->nsyms
; ++i
)
9858 struct symbol
*sym
= list
->symbol
[i
];
9860 if (SYMBOL_LANGUAGE (sym
) == language_go
9861 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9863 char *this_package_name
= go_symbol_package_name (sym
);
9865 if (this_package_name
== NULL
)
9867 if (package_name
== NULL
)
9868 package_name
= this_package_name
;
9871 struct objfile
*objfile
9872 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9873 if (strcmp (package_name
, this_package_name
) != 0)
9874 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9875 (symbol_symtab (sym
) != NULL
9876 ? symtab_to_filename_for_display
9877 (symbol_symtab (sym
))
9878 : objfile_name (objfile
)),
9879 this_package_name
, package_name
);
9880 xfree (this_package_name
);
9886 if (package_name
!= NULL
)
9888 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9889 const char *saved_package_name
9890 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
);
9891 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9892 saved_package_name
);
9895 sym
= allocate_symbol (objfile
);
9896 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
9897 SYMBOL_SET_NAMES (sym
, saved_package_name
,
9898 strlen (saved_package_name
), 0, objfile
);
9899 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9900 e.g., "main" finds the "main" module and not C's main(). */
9901 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9902 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9903 SYMBOL_TYPE (sym
) = type
;
9905 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9907 xfree (package_name
);
9911 /* Allocate a fully-qualified name consisting of the two parts on the
9915 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9917 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9920 /* A helper that allocates a struct discriminant_info to attach to a
9923 static struct discriminant_info
*
9924 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9927 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9928 gdb_assert (discriminant_index
== -1
9929 || (discriminant_index
>= 0
9930 && discriminant_index
< TYPE_NFIELDS (type
)));
9931 gdb_assert (default_index
== -1
9932 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9934 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9936 struct discriminant_info
*disc
9937 = ((struct discriminant_info
*)
9939 offsetof (struct discriminant_info
, discriminants
)
9940 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9941 disc
->default_index
= default_index
;
9942 disc
->discriminant_index
= discriminant_index
;
9944 struct dynamic_prop prop
;
9945 prop
.kind
= PROP_UNDEFINED
;
9946 prop
.data
.baton
= disc
;
9948 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9953 /* Some versions of rustc emitted enums in an unusual way.
9955 Ordinary enums were emitted as unions. The first element of each
9956 structure in the union was named "RUST$ENUM$DISR". This element
9957 held the discriminant.
9959 These versions of Rust also implemented the "non-zero"
9960 optimization. When the enum had two values, and one is empty and
9961 the other holds a pointer that cannot be zero, the pointer is used
9962 as the discriminant, with a zero value meaning the empty variant.
9963 Here, the union's first member is of the form
9964 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9965 where the fieldnos are the indices of the fields that should be
9966 traversed in order to find the field (which may be several fields deep)
9967 and the variantname is the name of the variant of the case when the
9970 This function recognizes whether TYPE is of one of these forms,
9971 and, if so, smashes it to be a variant type. */
9974 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9976 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9978 /* We don't need to deal with empty enums. */
9979 if (TYPE_NFIELDS (type
) == 0)
9982 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9983 if (TYPE_NFIELDS (type
) == 1
9984 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9986 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9988 /* Decode the field name to find the offset of the
9990 ULONGEST bit_offset
= 0;
9991 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9992 while (name
[0] >= '0' && name
[0] <= '9')
9995 unsigned long index
= strtoul (name
, &tail
, 10);
9998 || index
>= TYPE_NFIELDS (field_type
)
9999 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
10000 != FIELD_LOC_KIND_BITPOS
))
10002 complaint (_("Could not parse Rust enum encoding string \"%s\""
10004 TYPE_FIELD_NAME (type
, 0),
10005 objfile_name (objfile
));
10010 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10011 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10014 /* Make a union to hold the variants. */
10015 struct type
*union_type
= alloc_type (objfile
);
10016 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10017 TYPE_NFIELDS (union_type
) = 3;
10018 TYPE_FIELDS (union_type
)
10019 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10020 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10021 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10023 /* Put the discriminant must at index 0. */
10024 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10025 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10026 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10027 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10029 /* The order of fields doesn't really matter, so put the real
10030 field at index 1 and the data-less field at index 2. */
10031 struct discriminant_info
*disc
10032 = alloc_discriminant_info (union_type
, 0, 1);
10033 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10034 TYPE_FIELD_NAME (union_type
, 1)
10035 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10036 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10037 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10038 TYPE_FIELD_NAME (union_type
, 1));
10040 const char *dataless_name
10041 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10043 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10045 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10046 /* NAME points into the original discriminant name, which
10047 already has the correct lifetime. */
10048 TYPE_FIELD_NAME (union_type
, 2) = name
;
10049 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10050 disc
->discriminants
[2] = 0;
10052 /* Smash this type to be a structure type. We have to do this
10053 because the type has already been recorded. */
10054 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10055 TYPE_NFIELDS (type
) = 1;
10057 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10059 /* Install the variant part. */
10060 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10061 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10062 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10064 /* A union with a single anonymous field is probably an old-style
10065 univariant enum. */
10066 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
10068 /* Smash this type to be a structure type. We have to do this
10069 because the type has already been recorded. */
10070 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10072 /* Make a union to hold the variants. */
10073 struct type
*union_type
= alloc_type (objfile
);
10074 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10075 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10076 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10077 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10078 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10080 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10081 const char *variant_name
10082 = rust_last_path_segment (TYPE_NAME (field_type
));
10083 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10084 TYPE_NAME (field_type
)
10085 = rust_fully_qualify (&objfile
->objfile_obstack
,
10086 TYPE_NAME (type
), variant_name
);
10088 /* Install the union in the outer struct type. */
10089 TYPE_NFIELDS (type
) = 1;
10091 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10092 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10093 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10094 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10096 alloc_discriminant_info (union_type
, -1, 0);
10100 struct type
*disr_type
= nullptr;
10101 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10103 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10105 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10107 /* All fields of a true enum will be structs. */
10110 else if (TYPE_NFIELDS (disr_type
) == 0)
10112 /* Could be data-less variant, so keep going. */
10113 disr_type
= nullptr;
10115 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10116 "RUST$ENUM$DISR") != 0)
10118 /* Not a Rust enum. */
10128 /* If we got here without a discriminant, then it's probably
10130 if (disr_type
== nullptr)
10133 /* Smash this type to be a structure type. We have to do this
10134 because the type has already been recorded. */
10135 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10137 /* Make a union to hold the variants. */
10138 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10139 struct type
*union_type
= alloc_type (objfile
);
10140 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10141 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10142 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10143 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10144 TYPE_FIELDS (union_type
)
10145 = (struct field
*) TYPE_ZALLOC (union_type
,
10146 (TYPE_NFIELDS (union_type
)
10147 * sizeof (struct field
)));
10149 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10150 TYPE_NFIELDS (type
) * sizeof (struct field
));
10152 /* Install the discriminant at index 0 in the union. */
10153 TYPE_FIELD (union_type
, 0) = *disr_field
;
10154 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10155 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10157 /* Install the union in the outer struct type. */
10158 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10159 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10160 TYPE_NFIELDS (type
) = 1;
10162 /* Set the size and offset of the union type. */
10163 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10165 /* We need a way to find the correct discriminant given a
10166 variant name. For convenience we build a map here. */
10167 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10168 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10169 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10171 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10174 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10175 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10179 int n_fields
= TYPE_NFIELDS (union_type
);
10180 struct discriminant_info
*disc
10181 = alloc_discriminant_info (union_type
, 0, -1);
10182 /* Skip the discriminant here. */
10183 for (int i
= 1; i
< n_fields
; ++i
)
10185 /* Find the final word in the name of this variant's type.
10186 That name can be used to look up the correct
10188 const char *variant_name
10189 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10192 auto iter
= discriminant_map
.find (variant_name
);
10193 if (iter
!= discriminant_map
.end ())
10194 disc
->discriminants
[i
] = iter
->second
;
10196 /* Remove the discriminant field, if it exists. */
10197 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10198 if (TYPE_NFIELDS (sub_type
) > 0)
10200 --TYPE_NFIELDS (sub_type
);
10201 ++TYPE_FIELDS (sub_type
);
10203 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10204 TYPE_NAME (sub_type
)
10205 = rust_fully_qualify (&objfile
->objfile_obstack
,
10206 TYPE_NAME (type
), variant_name
);
10211 /* Rewrite some Rust unions to be structures with variants parts. */
10214 rust_union_quirks (struct dwarf2_cu
*cu
)
10216 gdb_assert (cu
->language
== language_rust
);
10217 for (type
*type_
: cu
->rust_unions
)
10218 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10219 /* We don't need this any more. */
10220 cu
->rust_unions
.clear ();
10223 /* Return the symtab for PER_CU. This works properly regardless of
10224 whether we're using the index or psymtabs. */
10226 static struct compunit_symtab
*
10227 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10229 return (per_cu
->dwarf2_per_objfile
->using_index
10230 ? per_cu
->v
.quick
->compunit_symtab
10231 : per_cu
->v
.psymtab
->compunit_symtab
);
10234 /* A helper function for computing the list of all symbol tables
10235 included by PER_CU. */
10238 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
10239 htab_t all_children
, htab_t all_type_symtabs
,
10240 struct dwarf2_per_cu_data
*per_cu
,
10241 struct compunit_symtab
*immediate_parent
)
10244 struct compunit_symtab
*cust
;
10246 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10249 /* This inclusion and its children have been processed. */
10254 /* Only add a CU if it has a symbol table. */
10255 cust
= get_compunit_symtab (per_cu
);
10258 /* If this is a type unit only add its symbol table if we haven't
10259 seen it yet (type unit per_cu's can share symtabs). */
10260 if (per_cu
->is_debug_types
)
10262 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10266 result
->push_back (cust
);
10267 if (cust
->user
== NULL
)
10268 cust
->user
= immediate_parent
;
10273 result
->push_back (cust
);
10274 if (cust
->user
== NULL
)
10275 cust
->user
= immediate_parent
;
10279 if (!per_cu
->imported_symtabs_empty ())
10280 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10282 recursively_compute_inclusions (result
, all_children
,
10283 all_type_symtabs
, ptr
, cust
);
10287 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10291 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10293 gdb_assert (! per_cu
->is_debug_types
);
10295 if (!per_cu
->imported_symtabs_empty ())
10298 std::vector
<compunit_symtab
*> result_symtabs
;
10299 htab_t all_children
, all_type_symtabs
;
10300 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10302 /* If we don't have a symtab, we can just skip this case. */
10306 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10307 NULL
, xcalloc
, xfree
);
10308 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10309 NULL
, xcalloc
, xfree
);
10311 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10313 recursively_compute_inclusions (&result_symtabs
, all_children
,
10314 all_type_symtabs
, ptr
, cust
);
10317 /* Now we have a transitive closure of all the included symtabs. */
10318 len
= result_symtabs
.size ();
10320 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10321 struct compunit_symtab
*, len
+ 1);
10322 memcpy (cust
->includes
, result_symtabs
.data (),
10323 len
* sizeof (compunit_symtab
*));
10324 cust
->includes
[len
] = NULL
;
10326 htab_delete (all_children
);
10327 htab_delete (all_type_symtabs
);
10331 /* Compute the 'includes' field for the symtabs of all the CUs we just
10335 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10337 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10339 if (! iter
->is_debug_types
)
10340 compute_compunit_symtab_includes (iter
);
10343 dwarf2_per_objfile
->just_read_cus
.clear ();
10346 /* Generate full symbol information for PER_CU, whose DIEs have
10347 already been loaded into memory. */
10350 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10351 enum language pretend_language
)
10353 struct dwarf2_cu
*cu
= per_cu
->cu
;
10354 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10355 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10356 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10357 CORE_ADDR lowpc
, highpc
;
10358 struct compunit_symtab
*cust
;
10359 CORE_ADDR baseaddr
;
10360 struct block
*static_block
;
10363 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10365 /* Clear the list here in case something was left over. */
10366 cu
->method_list
.clear ();
10368 cu
->language
= pretend_language
;
10369 cu
->language_defn
= language_def (cu
->language
);
10371 /* Do line number decoding in read_file_scope () */
10372 process_die (cu
->dies
, cu
);
10374 /* For now fudge the Go package. */
10375 if (cu
->language
== language_go
)
10376 fixup_go_packaging (cu
);
10378 /* Now that we have processed all the DIEs in the CU, all the types
10379 should be complete, and it should now be safe to compute all of the
10381 compute_delayed_physnames (cu
);
10383 if (cu
->language
== language_rust
)
10384 rust_union_quirks (cu
);
10386 /* Some compilers don't define a DW_AT_high_pc attribute for the
10387 compilation unit. If the DW_AT_high_pc is missing, synthesize
10388 it, by scanning the DIE's below the compilation unit. */
10389 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10391 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10392 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10394 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10395 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10396 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10397 addrmap to help ensure it has an accurate map of pc values belonging to
10399 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10401 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10402 SECT_OFF_TEXT (objfile
),
10407 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10409 /* Set symtab language to language from DW_AT_language. If the
10410 compilation is from a C file generated by language preprocessors, do
10411 not set the language if it was already deduced by start_subfile. */
10412 if (!(cu
->language
== language_c
10413 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10414 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10416 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10417 produce DW_AT_location with location lists but it can be possibly
10418 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10419 there were bugs in prologue debug info, fixed later in GCC-4.5
10420 by "unwind info for epilogues" patch (which is not directly related).
10422 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10423 needed, it would be wrong due to missing DW_AT_producer there.
10425 Still one can confuse GDB by using non-standard GCC compilation
10426 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10428 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10429 cust
->locations_valid
= 1;
10431 if (gcc_4_minor
>= 5)
10432 cust
->epilogue_unwind_valid
= 1;
10434 cust
->call_site_htab
= cu
->call_site_htab
;
10437 if (dwarf2_per_objfile
->using_index
)
10438 per_cu
->v
.quick
->compunit_symtab
= cust
;
10441 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10442 pst
->compunit_symtab
= cust
;
10446 /* Push it for inclusion processing later. */
10447 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10449 /* Not needed any more. */
10450 cu
->reset_builder ();
10453 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10454 already been loaded into memory. */
10457 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10458 enum language pretend_language
)
10460 struct dwarf2_cu
*cu
= per_cu
->cu
;
10461 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10462 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10463 struct compunit_symtab
*cust
;
10464 struct signatured_type
*sig_type
;
10466 gdb_assert (per_cu
->is_debug_types
);
10467 sig_type
= (struct signatured_type
*) per_cu
;
10469 /* Clear the list here in case something was left over. */
10470 cu
->method_list
.clear ();
10472 cu
->language
= pretend_language
;
10473 cu
->language_defn
= language_def (cu
->language
);
10475 /* The symbol tables are set up in read_type_unit_scope. */
10476 process_die (cu
->dies
, cu
);
10478 /* For now fudge the Go package. */
10479 if (cu
->language
== language_go
)
10480 fixup_go_packaging (cu
);
10482 /* Now that we have processed all the DIEs in the CU, all the types
10483 should be complete, and it should now be safe to compute all of the
10485 compute_delayed_physnames (cu
);
10487 if (cu
->language
== language_rust
)
10488 rust_union_quirks (cu
);
10490 /* TUs share symbol tables.
10491 If this is the first TU to use this symtab, complete the construction
10492 of it with end_expandable_symtab. Otherwise, complete the addition of
10493 this TU's symbols to the existing symtab. */
10494 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10496 buildsym_compunit
*builder
= cu
->get_builder ();
10497 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10498 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10502 /* Set symtab language to language from DW_AT_language. If the
10503 compilation is from a C file generated by language preprocessors,
10504 do not set the language if it was already deduced by
10506 if (!(cu
->language
== language_c
10507 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10508 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10513 cu
->get_builder ()->augment_type_symtab ();
10514 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10517 if (dwarf2_per_objfile
->using_index
)
10518 per_cu
->v
.quick
->compunit_symtab
= cust
;
10521 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10522 pst
->compunit_symtab
= cust
;
10526 /* Not needed any more. */
10527 cu
->reset_builder ();
10530 /* Process an imported unit DIE. */
10533 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10535 struct attribute
*attr
;
10537 /* For now we don't handle imported units in type units. */
10538 if (cu
->per_cu
->is_debug_types
)
10540 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10541 " supported in type units [in module %s]"),
10542 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10545 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10548 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10549 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10550 dwarf2_per_cu_data
*per_cu
10551 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10552 cu
->per_cu
->dwarf2_per_objfile
);
10554 /* If necessary, add it to the queue and load its DIEs. */
10555 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10556 load_full_comp_unit (per_cu
, false, cu
->language
);
10558 cu
->per_cu
->imported_symtabs_push (per_cu
);
10562 /* RAII object that represents a process_die scope: i.e.,
10563 starts/finishes processing a DIE. */
10564 class process_die_scope
10567 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10568 : m_die (die
), m_cu (cu
)
10570 /* We should only be processing DIEs not already in process. */
10571 gdb_assert (!m_die
->in_process
);
10572 m_die
->in_process
= true;
10575 ~process_die_scope ()
10577 m_die
->in_process
= false;
10579 /* If we're done processing the DIE for the CU that owns the line
10580 header, we don't need the line header anymore. */
10581 if (m_cu
->line_header_die_owner
== m_die
)
10583 delete m_cu
->line_header
;
10584 m_cu
->line_header
= NULL
;
10585 m_cu
->line_header_die_owner
= NULL
;
10594 /* Process a die and its children. */
10597 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10599 process_die_scope
scope (die
, cu
);
10603 case DW_TAG_padding
:
10605 case DW_TAG_compile_unit
:
10606 case DW_TAG_partial_unit
:
10607 read_file_scope (die
, cu
);
10609 case DW_TAG_type_unit
:
10610 read_type_unit_scope (die
, cu
);
10612 case DW_TAG_subprogram
:
10613 /* Nested subprograms in Fortran get a prefix. */
10614 if (cu
->language
== language_fortran
10615 && die
->parent
!= NULL
10616 && die
->parent
->tag
== DW_TAG_subprogram
)
10617 cu
->processing_has_namespace_info
= true;
10618 /* Fall through. */
10619 case DW_TAG_inlined_subroutine
:
10620 read_func_scope (die
, cu
);
10622 case DW_TAG_lexical_block
:
10623 case DW_TAG_try_block
:
10624 case DW_TAG_catch_block
:
10625 read_lexical_block_scope (die
, cu
);
10627 case DW_TAG_call_site
:
10628 case DW_TAG_GNU_call_site
:
10629 read_call_site_scope (die
, cu
);
10631 case DW_TAG_class_type
:
10632 case DW_TAG_interface_type
:
10633 case DW_TAG_structure_type
:
10634 case DW_TAG_union_type
:
10635 process_structure_scope (die
, cu
);
10637 case DW_TAG_enumeration_type
:
10638 process_enumeration_scope (die
, cu
);
10641 /* These dies have a type, but processing them does not create
10642 a symbol or recurse to process the children. Therefore we can
10643 read them on-demand through read_type_die. */
10644 case DW_TAG_subroutine_type
:
10645 case DW_TAG_set_type
:
10646 case DW_TAG_array_type
:
10647 case DW_TAG_pointer_type
:
10648 case DW_TAG_ptr_to_member_type
:
10649 case DW_TAG_reference_type
:
10650 case DW_TAG_rvalue_reference_type
:
10651 case DW_TAG_string_type
:
10654 case DW_TAG_base_type
:
10655 case DW_TAG_subrange_type
:
10656 case DW_TAG_typedef
:
10657 /* Add a typedef symbol for the type definition, if it has a
10659 new_symbol (die
, read_type_die (die
, cu
), cu
);
10661 case DW_TAG_common_block
:
10662 read_common_block (die
, cu
);
10664 case DW_TAG_common_inclusion
:
10666 case DW_TAG_namespace
:
10667 cu
->processing_has_namespace_info
= true;
10668 read_namespace (die
, cu
);
10670 case DW_TAG_module
:
10671 cu
->processing_has_namespace_info
= true;
10672 read_module (die
, cu
);
10674 case DW_TAG_imported_declaration
:
10675 cu
->processing_has_namespace_info
= true;
10676 if (read_namespace_alias (die
, cu
))
10678 /* The declaration is not a global namespace alias. */
10679 /* Fall through. */
10680 case DW_TAG_imported_module
:
10681 cu
->processing_has_namespace_info
= true;
10682 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10683 || cu
->language
!= language_fortran
))
10684 complaint (_("Tag '%s' has unexpected children"),
10685 dwarf_tag_name (die
->tag
));
10686 read_import_statement (die
, cu
);
10689 case DW_TAG_imported_unit
:
10690 process_imported_unit_die (die
, cu
);
10693 case DW_TAG_variable
:
10694 read_variable (die
, cu
);
10698 new_symbol (die
, NULL
, cu
);
10703 /* DWARF name computation. */
10705 /* A helper function for dwarf2_compute_name which determines whether DIE
10706 needs to have the name of the scope prepended to the name listed in the
10710 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10712 struct attribute
*attr
;
10716 case DW_TAG_namespace
:
10717 case DW_TAG_typedef
:
10718 case DW_TAG_class_type
:
10719 case DW_TAG_interface_type
:
10720 case DW_TAG_structure_type
:
10721 case DW_TAG_union_type
:
10722 case DW_TAG_enumeration_type
:
10723 case DW_TAG_enumerator
:
10724 case DW_TAG_subprogram
:
10725 case DW_TAG_inlined_subroutine
:
10726 case DW_TAG_member
:
10727 case DW_TAG_imported_declaration
:
10730 case DW_TAG_variable
:
10731 case DW_TAG_constant
:
10732 /* We only need to prefix "globally" visible variables. These include
10733 any variable marked with DW_AT_external or any variable that
10734 lives in a namespace. [Variables in anonymous namespaces
10735 require prefixing, but they are not DW_AT_external.] */
10737 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10739 struct dwarf2_cu
*spec_cu
= cu
;
10741 return die_needs_namespace (die_specification (die
, &spec_cu
),
10745 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10746 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10747 && die
->parent
->tag
!= DW_TAG_module
)
10749 /* A variable in a lexical block of some kind does not need a
10750 namespace, even though in C++ such variables may be external
10751 and have a mangled name. */
10752 if (die
->parent
->tag
== DW_TAG_lexical_block
10753 || die
->parent
->tag
== DW_TAG_try_block
10754 || die
->parent
->tag
== DW_TAG_catch_block
10755 || die
->parent
->tag
== DW_TAG_subprogram
)
10764 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10765 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10766 defined for the given DIE. */
10768 static struct attribute
*
10769 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10771 struct attribute
*attr
;
10773 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10775 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10780 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10781 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10782 defined for the given DIE. */
10784 static const char *
10785 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10787 const char *linkage_name
;
10789 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10790 if (linkage_name
== NULL
)
10791 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10793 return linkage_name
;
10796 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10797 compute the physname for the object, which include a method's:
10798 - formal parameters (C++),
10799 - receiver type (Go),
10801 The term "physname" is a bit confusing.
10802 For C++, for example, it is the demangled name.
10803 For Go, for example, it's the mangled name.
10805 For Ada, return the DIE's linkage name rather than the fully qualified
10806 name. PHYSNAME is ignored..
10808 The result is allocated on the objfile_obstack and canonicalized. */
10810 static const char *
10811 dwarf2_compute_name (const char *name
,
10812 struct die_info
*die
, struct dwarf2_cu
*cu
,
10815 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10818 name
= dwarf2_name (die
, cu
);
10820 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10821 but otherwise compute it by typename_concat inside GDB.
10822 FIXME: Actually this is not really true, or at least not always true.
10823 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
10824 Fortran names because there is no mangling standard. So new_symbol
10825 will set the demangled name to the result of dwarf2_full_name, and it is
10826 the demangled name that GDB uses if it exists. */
10827 if (cu
->language
== language_ada
10828 || (cu
->language
== language_fortran
&& physname
))
10830 /* For Ada unit, we prefer the linkage name over the name, as
10831 the former contains the exported name, which the user expects
10832 to be able to reference. Ideally, we want the user to be able
10833 to reference this entity using either natural or linkage name,
10834 but we haven't started looking at this enhancement yet. */
10835 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10837 if (linkage_name
!= NULL
)
10838 return linkage_name
;
10841 /* These are the only languages we know how to qualify names in. */
10843 && (cu
->language
== language_cplus
10844 || cu
->language
== language_fortran
|| cu
->language
== language_d
10845 || cu
->language
== language_rust
))
10847 if (die_needs_namespace (die
, cu
))
10849 const char *prefix
;
10850 const char *canonical_name
= NULL
;
10854 prefix
= determine_prefix (die
, cu
);
10855 if (*prefix
!= '\0')
10857 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
10860 buf
.puts (prefixed_name
);
10861 xfree (prefixed_name
);
10866 /* Template parameters may be specified in the DIE's DW_AT_name, or
10867 as children with DW_TAG_template_type_param or
10868 DW_TAG_value_type_param. If the latter, add them to the name
10869 here. If the name already has template parameters, then
10870 skip this step; some versions of GCC emit both, and
10871 it is more efficient to use the pre-computed name.
10873 Something to keep in mind about this process: it is very
10874 unlikely, or in some cases downright impossible, to produce
10875 something that will match the mangled name of a function.
10876 If the definition of the function has the same debug info,
10877 we should be able to match up with it anyway. But fallbacks
10878 using the minimal symbol, for instance to find a method
10879 implemented in a stripped copy of libstdc++, will not work.
10880 If we do not have debug info for the definition, we will have to
10881 match them up some other way.
10883 When we do name matching there is a related problem with function
10884 templates; two instantiated function templates are allowed to
10885 differ only by their return types, which we do not add here. */
10887 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10889 struct attribute
*attr
;
10890 struct die_info
*child
;
10893 die
->building_fullname
= 1;
10895 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10899 const gdb_byte
*bytes
;
10900 struct dwarf2_locexpr_baton
*baton
;
10903 if (child
->tag
!= DW_TAG_template_type_param
10904 && child
->tag
!= DW_TAG_template_value_param
)
10915 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10918 complaint (_("template parameter missing DW_AT_type"));
10919 buf
.puts ("UNKNOWN_TYPE");
10922 type
= die_type (child
, cu
);
10924 if (child
->tag
== DW_TAG_template_type_param
)
10926 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10927 &type_print_raw_options
);
10931 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10934 complaint (_("template parameter missing "
10935 "DW_AT_const_value"));
10936 buf
.puts ("UNKNOWN_VALUE");
10940 dwarf2_const_value_attr (attr
, type
, name
,
10941 &cu
->comp_unit_obstack
, cu
,
10942 &value
, &bytes
, &baton
);
10944 if (TYPE_NOSIGN (type
))
10945 /* GDB prints characters as NUMBER 'CHAR'. If that's
10946 changed, this can use value_print instead. */
10947 c_printchar (value
, type
, &buf
);
10950 struct value_print_options opts
;
10953 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10957 else if (bytes
!= NULL
)
10959 v
= allocate_value (type
);
10960 memcpy (value_contents_writeable (v
), bytes
,
10961 TYPE_LENGTH (type
));
10964 v
= value_from_longest (type
, value
);
10966 /* Specify decimal so that we do not depend on
10968 get_formatted_print_options (&opts
, 'd');
10970 value_print (v
, &buf
, &opts
);
10975 die
->building_fullname
= 0;
10979 /* Close the argument list, with a space if necessary
10980 (nested templates). */
10981 if (!buf
.empty () && buf
.string ().back () == '>')
10988 /* For C++ methods, append formal parameter type
10989 information, if PHYSNAME. */
10991 if (physname
&& die
->tag
== DW_TAG_subprogram
10992 && cu
->language
== language_cplus
)
10994 struct type
*type
= read_type_die (die
, cu
);
10996 c_type_print_args (type
, &buf
, 1, cu
->language
,
10997 &type_print_raw_options
);
10999 if (cu
->language
== language_cplus
)
11001 /* Assume that an artificial first parameter is
11002 "this", but do not crash if it is not. RealView
11003 marks unnamed (and thus unused) parameters as
11004 artificial; there is no way to differentiate
11006 if (TYPE_NFIELDS (type
) > 0
11007 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11008 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11009 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11011 buf
.puts (" const");
11015 const std::string
&intermediate_name
= buf
.string ();
11017 if (cu
->language
== language_cplus
)
11019 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11020 &objfile
->per_bfd
->storage_obstack
);
11022 /* If we only computed INTERMEDIATE_NAME, or if
11023 INTERMEDIATE_NAME is already canonical, then we need to
11024 copy it to the appropriate obstack. */
11025 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11026 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
11027 intermediate_name
);
11029 name
= canonical_name
;
11036 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11037 If scope qualifiers are appropriate they will be added. The result
11038 will be allocated on the storage_obstack, or NULL if the DIE does
11039 not have a name. NAME may either be from a previous call to
11040 dwarf2_name or NULL.
11042 The output string will be canonicalized (if C++). */
11044 static const char *
11045 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11047 return dwarf2_compute_name (name
, die
, cu
, 0);
11050 /* Construct a physname for the given DIE in CU. NAME may either be
11051 from a previous call to dwarf2_name or NULL. The result will be
11052 allocated on the objfile_objstack or NULL if the DIE does not have a
11055 The output string will be canonicalized (if C++). */
11057 static const char *
11058 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11060 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11061 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11064 /* In this case dwarf2_compute_name is just a shortcut not building anything
11066 if (!die_needs_namespace (die
, cu
))
11067 return dwarf2_compute_name (name
, die
, cu
, 1);
11069 mangled
= dw2_linkage_name (die
, cu
);
11071 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11072 See https://github.com/rust-lang/rust/issues/32925. */
11073 if (cu
->language
== language_rust
&& mangled
!= NULL
11074 && strchr (mangled
, '{') != NULL
)
11077 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11079 gdb::unique_xmalloc_ptr
<char> demangled
;
11080 if (mangled
!= NULL
)
11083 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11085 /* Do nothing (do not demangle the symbol name). */
11087 else if (cu
->language
== language_go
)
11089 /* This is a lie, but we already lie to the caller new_symbol.
11090 new_symbol assumes we return the mangled name.
11091 This just undoes that lie until things are cleaned up. */
11095 /* Use DMGL_RET_DROP for C++ template functions to suppress
11096 their return type. It is easier for GDB users to search
11097 for such functions as `name(params)' than `long name(params)'.
11098 In such case the minimal symbol names do not match the full
11099 symbol names but for template functions there is never a need
11100 to look up their definition from their declaration so
11101 the only disadvantage remains the minimal symbol variant
11102 `long name(params)' does not have the proper inferior type. */
11103 demangled
.reset (gdb_demangle (mangled
,
11104 (DMGL_PARAMS
| DMGL_ANSI
11105 | DMGL_RET_DROP
)));
11108 canon
= demangled
.get ();
11116 if (canon
== NULL
|| check_physname
)
11118 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11120 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11122 /* It may not mean a bug in GDB. The compiler could also
11123 compute DW_AT_linkage_name incorrectly. But in such case
11124 GDB would need to be bug-to-bug compatible. */
11126 complaint (_("Computed physname <%s> does not match demangled <%s> "
11127 "(from linkage <%s>) - DIE at %s [in module %s]"),
11128 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11129 objfile_name (objfile
));
11131 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11132 is available here - over computed PHYSNAME. It is safer
11133 against both buggy GDB and buggy compilers. */
11147 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
11152 /* Inspect DIE in CU for a namespace alias. If one exists, record
11153 a new symbol for it.
11155 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11158 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11160 struct attribute
*attr
;
11162 /* If the die does not have a name, this is not a namespace
11164 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11168 struct die_info
*d
= die
;
11169 struct dwarf2_cu
*imported_cu
= cu
;
11171 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11172 keep inspecting DIEs until we hit the underlying import. */
11173 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11174 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11176 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11180 d
= follow_die_ref (d
, attr
, &imported_cu
);
11181 if (d
->tag
!= DW_TAG_imported_declaration
)
11185 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11187 complaint (_("DIE at %s has too many recursively imported "
11188 "declarations"), sect_offset_str (d
->sect_off
));
11195 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11197 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11198 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11200 /* This declaration is a global namespace alias. Add
11201 a symbol for it whose type is the aliased namespace. */
11202 new_symbol (die
, type
, cu
);
11211 /* Return the using directives repository (global or local?) to use in the
11212 current context for CU.
11214 For Ada, imported declarations can materialize renamings, which *may* be
11215 global. However it is impossible (for now?) in DWARF to distinguish
11216 "external" imported declarations and "static" ones. As all imported
11217 declarations seem to be static in all other languages, make them all CU-wide
11218 global only in Ada. */
11220 static struct using_direct
**
11221 using_directives (struct dwarf2_cu
*cu
)
11223 if (cu
->language
== language_ada
11224 && cu
->get_builder ()->outermost_context_p ())
11225 return cu
->get_builder ()->get_global_using_directives ();
11227 return cu
->get_builder ()->get_local_using_directives ();
11230 /* Read the import statement specified by the given die and record it. */
11233 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11235 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11236 struct attribute
*import_attr
;
11237 struct die_info
*imported_die
, *child_die
;
11238 struct dwarf2_cu
*imported_cu
;
11239 const char *imported_name
;
11240 const char *imported_name_prefix
;
11241 const char *canonical_name
;
11242 const char *import_alias
;
11243 const char *imported_declaration
= NULL
;
11244 const char *import_prefix
;
11245 std::vector
<const char *> excludes
;
11247 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11248 if (import_attr
== NULL
)
11250 complaint (_("Tag '%s' has no DW_AT_import"),
11251 dwarf_tag_name (die
->tag
));
11256 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11257 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11258 if (imported_name
== NULL
)
11260 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11262 The import in the following code:
11276 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11277 <52> DW_AT_decl_file : 1
11278 <53> DW_AT_decl_line : 6
11279 <54> DW_AT_import : <0x75>
11280 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11281 <59> DW_AT_name : B
11282 <5b> DW_AT_decl_file : 1
11283 <5c> DW_AT_decl_line : 2
11284 <5d> DW_AT_type : <0x6e>
11286 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11287 <76> DW_AT_byte_size : 4
11288 <77> DW_AT_encoding : 5 (signed)
11290 imports the wrong die ( 0x75 instead of 0x58 ).
11291 This case will be ignored until the gcc bug is fixed. */
11295 /* Figure out the local name after import. */
11296 import_alias
= dwarf2_name (die
, cu
);
11298 /* Figure out where the statement is being imported to. */
11299 import_prefix
= determine_prefix (die
, cu
);
11301 /* Figure out what the scope of the imported die is and prepend it
11302 to the name of the imported die. */
11303 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11305 if (imported_die
->tag
!= DW_TAG_namespace
11306 && imported_die
->tag
!= DW_TAG_module
)
11308 imported_declaration
= imported_name
;
11309 canonical_name
= imported_name_prefix
;
11311 else if (strlen (imported_name_prefix
) > 0)
11312 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11313 imported_name_prefix
,
11314 (cu
->language
== language_d
? "." : "::"),
11315 imported_name
, (char *) NULL
);
11317 canonical_name
= imported_name
;
11319 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11320 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11321 child_die
= sibling_die (child_die
))
11323 /* DWARF-4: A Fortran use statement with a “rename list” may be
11324 represented by an imported module entry with an import attribute
11325 referring to the module and owned entries corresponding to those
11326 entities that are renamed as part of being imported. */
11328 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11330 complaint (_("child DW_TAG_imported_declaration expected "
11331 "- DIE at %s [in module %s]"),
11332 sect_offset_str (child_die
->sect_off
),
11333 objfile_name (objfile
));
11337 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11338 if (import_attr
== NULL
)
11340 complaint (_("Tag '%s' has no DW_AT_import"),
11341 dwarf_tag_name (child_die
->tag
));
11346 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11348 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11349 if (imported_name
== NULL
)
11351 complaint (_("child DW_TAG_imported_declaration has unknown "
11352 "imported name - DIE at %s [in module %s]"),
11353 sect_offset_str (child_die
->sect_off
),
11354 objfile_name (objfile
));
11358 excludes
.push_back (imported_name
);
11360 process_die (child_die
, cu
);
11363 add_using_directive (using_directives (cu
),
11367 imported_declaration
,
11370 &objfile
->objfile_obstack
);
11373 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11374 types, but gives them a size of zero. Starting with version 14,
11375 ICC is compatible with GCC. */
11378 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11380 if (!cu
->checked_producer
)
11381 check_producer (cu
);
11383 return cu
->producer_is_icc_lt_14
;
11386 /* ICC generates a DW_AT_type for C void functions. This was observed on
11387 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11388 which says that void functions should not have a DW_AT_type. */
11391 producer_is_icc (struct dwarf2_cu
*cu
)
11393 if (!cu
->checked_producer
)
11394 check_producer (cu
);
11396 return cu
->producer_is_icc
;
11399 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11400 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11401 this, it was first present in GCC release 4.3.0. */
11404 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11406 if (!cu
->checked_producer
)
11407 check_producer (cu
);
11409 return cu
->producer_is_gcc_lt_4_3
;
11412 static file_and_directory
11413 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11415 file_and_directory res
;
11417 /* Find the filename. Do not use dwarf2_name here, since the filename
11418 is not a source language identifier. */
11419 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11420 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11422 if (res
.comp_dir
== NULL
11423 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11424 && IS_ABSOLUTE_PATH (res
.name
))
11426 res
.comp_dir_storage
= ldirname (res
.name
);
11427 if (!res
.comp_dir_storage
.empty ())
11428 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11430 if (res
.comp_dir
!= NULL
)
11432 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11433 directory, get rid of it. */
11434 const char *cp
= strchr (res
.comp_dir
, ':');
11436 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11437 res
.comp_dir
= cp
+ 1;
11440 if (res
.name
== NULL
)
11441 res
.name
= "<unknown>";
11446 /* Handle DW_AT_stmt_list for a compilation unit.
11447 DIE is the DW_TAG_compile_unit die for CU.
11448 COMP_DIR is the compilation directory. LOWPC is passed to
11449 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11452 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11453 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11455 struct dwarf2_per_objfile
*dwarf2_per_objfile
11456 = cu
->per_cu
->dwarf2_per_objfile
;
11457 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11458 struct attribute
*attr
;
11459 struct line_header line_header_local
;
11460 hashval_t line_header_local_hash
;
11462 int decode_mapping
;
11464 gdb_assert (! cu
->per_cu
->is_debug_types
);
11466 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11470 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11472 /* The line header hash table is only created if needed (it exists to
11473 prevent redundant reading of the line table for partial_units).
11474 If we're given a partial_unit, we'll need it. If we're given a
11475 compile_unit, then use the line header hash table if it's already
11476 created, but don't create one just yet. */
11478 if (dwarf2_per_objfile
->line_header_hash
== NULL
11479 && die
->tag
== DW_TAG_partial_unit
)
11481 dwarf2_per_objfile
->line_header_hash
11482 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11483 line_header_eq_voidp
,
11484 free_line_header_voidp
,
11485 &objfile
->objfile_obstack
,
11486 hashtab_obstack_allocate
,
11487 dummy_obstack_deallocate
);
11490 line_header_local
.sect_off
= line_offset
;
11491 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11492 line_header_local_hash
= line_header_hash (&line_header_local
);
11493 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11495 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11496 &line_header_local
,
11497 line_header_local_hash
, NO_INSERT
);
11499 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11500 is not present in *SLOT (since if there is something in *SLOT then
11501 it will be for a partial_unit). */
11502 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11504 gdb_assert (*slot
!= NULL
);
11505 cu
->line_header
= (struct line_header
*) *slot
;
11510 /* dwarf_decode_line_header does not yet provide sufficient information.
11511 We always have to call also dwarf_decode_lines for it. */
11512 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11516 cu
->line_header
= lh
.release ();
11517 cu
->line_header_die_owner
= die
;
11519 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11523 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11524 &line_header_local
,
11525 line_header_local_hash
, INSERT
);
11526 gdb_assert (slot
!= NULL
);
11528 if (slot
!= NULL
&& *slot
== NULL
)
11530 /* This newly decoded line number information unit will be owned
11531 by line_header_hash hash table. */
11532 *slot
= cu
->line_header
;
11533 cu
->line_header_die_owner
= NULL
;
11537 /* We cannot free any current entry in (*slot) as that struct line_header
11538 may be already used by multiple CUs. Create only temporary decoded
11539 line_header for this CU - it may happen at most once for each line
11540 number information unit. And if we're not using line_header_hash
11541 then this is what we want as well. */
11542 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11544 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11545 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11550 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11553 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11555 struct dwarf2_per_objfile
*dwarf2_per_objfile
11556 = cu
->per_cu
->dwarf2_per_objfile
;
11557 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11558 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11559 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11560 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11561 struct attribute
*attr
;
11562 struct die_info
*child_die
;
11563 CORE_ADDR baseaddr
;
11565 prepare_one_comp_unit (cu
, die
, cu
->language
);
11566 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11568 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11570 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11571 from finish_block. */
11572 if (lowpc
== ((CORE_ADDR
) -1))
11574 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11576 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11578 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11579 standardised yet. As a workaround for the language detection we fall
11580 back to the DW_AT_producer string. */
11581 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11582 cu
->language
= language_opencl
;
11584 /* Similar hack for Go. */
11585 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11586 set_cu_language (DW_LANG_Go
, cu
);
11588 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11590 /* Decode line number information if present. We do this before
11591 processing child DIEs, so that the line header table is available
11592 for DW_AT_decl_file. */
11593 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11595 /* Process all dies in compilation unit. */
11596 if (die
->child
!= NULL
)
11598 child_die
= die
->child
;
11599 while (child_die
&& child_die
->tag
)
11601 process_die (child_die
, cu
);
11602 child_die
= sibling_die (child_die
);
11606 /* Decode macro information, if present. Dwarf 2 macro information
11607 refers to information in the line number info statement program
11608 header, so we can only read it if we've read the header
11610 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11612 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11613 if (attr
&& cu
->line_header
)
11615 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11616 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11618 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11622 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11623 if (attr
&& cu
->line_header
)
11625 unsigned int macro_offset
= DW_UNSND (attr
);
11627 dwarf_decode_macros (cu
, macro_offset
, 0);
11633 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11635 struct type_unit_group
*tu_group
;
11637 struct attribute
*attr
;
11639 struct signatured_type
*sig_type
;
11641 gdb_assert (per_cu
->is_debug_types
);
11642 sig_type
= (struct signatured_type
*) per_cu
;
11644 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11646 /* If we're using .gdb_index (includes -readnow) then
11647 per_cu->type_unit_group may not have been set up yet. */
11648 if (sig_type
->type_unit_group
== NULL
)
11649 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11650 tu_group
= sig_type
->type_unit_group
;
11652 /* If we've already processed this stmt_list there's no real need to
11653 do it again, we could fake it and just recreate the part we need
11654 (file name,index -> symtab mapping). If data shows this optimization
11655 is useful we can do it then. */
11656 first_time
= tu_group
->compunit_symtab
== NULL
;
11658 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11663 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11664 lh
= dwarf_decode_line_header (line_offset
, this);
11669 start_symtab ("", NULL
, 0);
11672 gdb_assert (tu_group
->symtabs
== NULL
);
11673 gdb_assert (m_builder
== nullptr);
11674 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11675 m_builder
.reset (new struct buildsym_compunit
11676 (COMPUNIT_OBJFILE (cust
), "",
11677 COMPUNIT_DIRNAME (cust
),
11678 compunit_language (cust
),
11684 line_header
= lh
.release ();
11685 line_header_die_owner
= die
;
11689 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11691 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11692 still initializing it, and our caller (a few levels up)
11693 process_full_type_unit still needs to know if this is the first
11696 tu_group
->num_symtabs
= line_header
->file_names
.size ();
11697 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11698 line_header
->file_names
.size ());
11700 for (i
= 0; i
< line_header
->file_names
.size (); ++i
)
11702 file_entry
&fe
= line_header
->file_names
[i
];
11704 dwarf2_start_subfile (this, fe
.name
,
11705 fe
.include_dir (line_header
));
11706 buildsym_compunit
*b
= get_builder ();
11707 if (b
->get_current_subfile ()->symtab
== NULL
)
11709 /* NOTE: start_subfile will recognize when it's been
11710 passed a file it has already seen. So we can't
11711 assume there's a simple mapping from
11712 cu->line_header->file_names to subfiles, plus
11713 cu->line_header->file_names may contain dups. */
11714 b
->get_current_subfile ()->symtab
11715 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11718 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11719 tu_group
->symtabs
[i
] = fe
.symtab
;
11724 gdb_assert (m_builder
== nullptr);
11725 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11726 m_builder
.reset (new struct buildsym_compunit
11727 (COMPUNIT_OBJFILE (cust
), "",
11728 COMPUNIT_DIRNAME (cust
),
11729 compunit_language (cust
),
11732 for (i
= 0; i
< line_header
->file_names
.size (); ++i
)
11734 file_entry
&fe
= line_header
->file_names
[i
];
11736 fe
.symtab
= tu_group
->symtabs
[i
];
11740 /* The main symtab is allocated last. Type units don't have DW_AT_name
11741 so they don't have a "real" (so to speak) symtab anyway.
11742 There is later code that will assign the main symtab to all symbols
11743 that don't have one. We need to handle the case of a symbol with a
11744 missing symtab (DW_AT_decl_file) anyway. */
11747 /* Process DW_TAG_type_unit.
11748 For TUs we want to skip the first top level sibling if it's not the
11749 actual type being defined by this TU. In this case the first top
11750 level sibling is there to provide context only. */
11753 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11755 struct die_info
*child_die
;
11757 prepare_one_comp_unit (cu
, die
, language_minimal
);
11759 /* Initialize (or reinitialize) the machinery for building symtabs.
11760 We do this before processing child DIEs, so that the line header table
11761 is available for DW_AT_decl_file. */
11762 cu
->setup_type_unit_groups (die
);
11764 if (die
->child
!= NULL
)
11766 child_die
= die
->child
;
11767 while (child_die
&& child_die
->tag
)
11769 process_die (child_die
, cu
);
11770 child_die
= sibling_die (child_die
);
11777 http://gcc.gnu.org/wiki/DebugFission
11778 http://gcc.gnu.org/wiki/DebugFissionDWP
11780 To simplify handling of both DWO files ("object" files with the DWARF info)
11781 and DWP files (a file with the DWOs packaged up into one file), we treat
11782 DWP files as having a collection of virtual DWO files. */
11785 hash_dwo_file (const void *item
)
11787 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11790 hash
= htab_hash_string (dwo_file
->dwo_name
);
11791 if (dwo_file
->comp_dir
!= NULL
)
11792 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11797 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11799 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11800 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11802 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11804 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11805 return lhs
->comp_dir
== rhs
->comp_dir
;
11806 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11809 /* Allocate a hash table for DWO files. */
11812 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11814 auto delete_dwo_file
= [] (void *item
)
11816 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11821 return htab_up (htab_create_alloc_ex (41,
11825 &objfile
->objfile_obstack
,
11826 hashtab_obstack_allocate
,
11827 dummy_obstack_deallocate
));
11830 /* Lookup DWO file DWO_NAME. */
11833 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11834 const char *dwo_name
,
11835 const char *comp_dir
)
11837 struct dwo_file find_entry
;
11840 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11841 dwarf2_per_objfile
->dwo_files
11842 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11844 find_entry
.dwo_name
= dwo_name
;
11845 find_entry
.comp_dir
= comp_dir
;
11846 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11853 hash_dwo_unit (const void *item
)
11855 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11857 /* This drops the top 32 bits of the id, but is ok for a hash. */
11858 return dwo_unit
->signature
;
11862 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11864 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11865 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11867 /* The signature is assumed to be unique within the DWO file.
11868 So while object file CU dwo_id's always have the value zero,
11869 that's OK, assuming each object file DWO file has only one CU,
11870 and that's the rule for now. */
11871 return lhs
->signature
== rhs
->signature
;
11874 /* Allocate a hash table for DWO CUs,TUs.
11875 There is one of these tables for each of CUs,TUs for each DWO file. */
11878 allocate_dwo_unit_table (struct objfile
*objfile
)
11880 /* Start out with a pretty small number.
11881 Generally DWO files contain only one CU and maybe some TUs. */
11882 return htab_create_alloc_ex (3,
11886 &objfile
->objfile_obstack
,
11887 hashtab_obstack_allocate
,
11888 dummy_obstack_deallocate
);
11891 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11893 struct create_dwo_cu_data
11895 struct dwo_file
*dwo_file
;
11896 struct dwo_unit dwo_unit
;
11899 /* die_reader_func for create_dwo_cu. */
11902 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11903 const gdb_byte
*info_ptr
,
11904 struct die_info
*comp_unit_die
,
11908 struct dwarf2_cu
*cu
= reader
->cu
;
11909 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11910 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11911 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11912 struct dwo_file
*dwo_file
= data
->dwo_file
;
11913 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11915 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11916 if (!signature
.has_value ())
11918 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11919 " its dwo_id [in module %s]"),
11920 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11924 dwo_unit
->dwo_file
= dwo_file
;
11925 dwo_unit
->signature
= *signature
;
11926 dwo_unit
->section
= section
;
11927 dwo_unit
->sect_off
= sect_off
;
11928 dwo_unit
->length
= cu
->per_cu
->length
;
11930 if (dwarf_read_debug
)
11931 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11932 sect_offset_str (sect_off
),
11933 hex_string (dwo_unit
->signature
));
11936 /* Create the dwo_units for the CUs in a DWO_FILE.
11937 Note: This function processes DWO files only, not DWP files. */
11940 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11941 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11944 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11945 const gdb_byte
*info_ptr
, *end_ptr
;
11947 dwarf2_read_section (objfile
, §ion
);
11948 info_ptr
= section
.buffer
;
11950 if (info_ptr
== NULL
)
11953 if (dwarf_read_debug
)
11955 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11956 get_section_name (§ion
),
11957 get_section_file_name (§ion
));
11960 end_ptr
= info_ptr
+ section
.size
;
11961 while (info_ptr
< end_ptr
)
11963 struct dwarf2_per_cu_data per_cu
;
11964 struct create_dwo_cu_data create_dwo_cu_data
;
11965 struct dwo_unit
*dwo_unit
;
11967 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11969 memset (&create_dwo_cu_data
.dwo_unit
, 0,
11970 sizeof (create_dwo_cu_data
.dwo_unit
));
11971 memset (&per_cu
, 0, sizeof (per_cu
));
11972 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11973 per_cu
.is_debug_types
= 0;
11974 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11975 per_cu
.section
= §ion
;
11976 create_dwo_cu_data
.dwo_file
= &dwo_file
;
11978 init_cutu_and_read_dies_no_follow (
11979 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
11980 info_ptr
+= per_cu
.length
;
11982 // If the unit could not be parsed, skip it.
11983 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
11986 if (cus_htab
== NULL
)
11987 cus_htab
= allocate_dwo_unit_table (objfile
);
11989 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11990 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
11991 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
11992 gdb_assert (slot
!= NULL
);
11995 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11996 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11998 complaint (_("debug cu entry at offset %s is duplicate to"
11999 " the entry at offset %s, signature %s"),
12000 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
12001 hex_string (dwo_unit
->signature
));
12003 *slot
= (void *)dwo_unit
;
12007 /* DWP file .debug_{cu,tu}_index section format:
12008 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12012 Both index sections have the same format, and serve to map a 64-bit
12013 signature to a set of section numbers. Each section begins with a header,
12014 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12015 indexes, and a pool of 32-bit section numbers. The index sections will be
12016 aligned at 8-byte boundaries in the file.
12018 The index section header consists of:
12020 V, 32 bit version number
12022 N, 32 bit number of compilation units or type units in the index
12023 M, 32 bit number of slots in the hash table
12025 Numbers are recorded using the byte order of the application binary.
12027 The hash table begins at offset 16 in the section, and consists of an array
12028 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12029 order of the application binary). Unused slots in the hash table are 0.
12030 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12032 The parallel table begins immediately after the hash table
12033 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12034 array of 32-bit indexes (using the byte order of the application binary),
12035 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12036 table contains a 32-bit index into the pool of section numbers. For unused
12037 hash table slots, the corresponding entry in the parallel table will be 0.
12039 The pool of section numbers begins immediately following the hash table
12040 (at offset 16 + 12 * M from the beginning of the section). The pool of
12041 section numbers consists of an array of 32-bit words (using the byte order
12042 of the application binary). Each item in the array is indexed starting
12043 from 0. The hash table entry provides the index of the first section
12044 number in the set. Additional section numbers in the set follow, and the
12045 set is terminated by a 0 entry (section number 0 is not used in ELF).
12047 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12048 section must be the first entry in the set, and the .debug_abbrev.dwo must
12049 be the second entry. Other members of the set may follow in any order.
12055 DWP Version 2 combines all the .debug_info, etc. sections into one,
12056 and the entries in the index tables are now offsets into these sections.
12057 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12060 Index Section Contents:
12062 Hash Table of Signatures dwp_hash_table.hash_table
12063 Parallel Table of Indices dwp_hash_table.unit_table
12064 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12065 Table of Section Sizes dwp_hash_table.v2.sizes
12067 The index section header consists of:
12069 V, 32 bit version number
12070 L, 32 bit number of columns in the table of section offsets
12071 N, 32 bit number of compilation units or type units in the index
12072 M, 32 bit number of slots in the hash table
12074 Numbers are recorded using the byte order of the application binary.
12076 The hash table has the same format as version 1.
12077 The parallel table of indices has the same format as version 1,
12078 except that the entries are origin-1 indices into the table of sections
12079 offsets and the table of section sizes.
12081 The table of offsets begins immediately following the parallel table
12082 (at offset 16 + 12 * M from the beginning of the section). The table is
12083 a two-dimensional array of 32-bit words (using the byte order of the
12084 application binary), with L columns and N+1 rows, in row-major order.
12085 Each row in the array is indexed starting from 0. The first row provides
12086 a key to the remaining rows: each column in this row provides an identifier
12087 for a debug section, and the offsets in the same column of subsequent rows
12088 refer to that section. The section identifiers are:
12090 DW_SECT_INFO 1 .debug_info.dwo
12091 DW_SECT_TYPES 2 .debug_types.dwo
12092 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12093 DW_SECT_LINE 4 .debug_line.dwo
12094 DW_SECT_LOC 5 .debug_loc.dwo
12095 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12096 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12097 DW_SECT_MACRO 8 .debug_macro.dwo
12099 The offsets provided by the CU and TU index sections are the base offsets
12100 for the contributions made by each CU or TU to the corresponding section
12101 in the package file. Each CU and TU header contains an abbrev_offset
12102 field, used to find the abbreviations table for that CU or TU within the
12103 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12104 be interpreted as relative to the base offset given in the index section.
12105 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12106 should be interpreted as relative to the base offset for .debug_line.dwo,
12107 and offsets into other debug sections obtained from DWARF attributes should
12108 also be interpreted as relative to the corresponding base offset.
12110 The table of sizes begins immediately following the table of offsets.
12111 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12112 with L columns and N rows, in row-major order. Each row in the array is
12113 indexed starting from 1 (row 0 is shared by the two tables).
12117 Hash table lookup is handled the same in version 1 and 2:
12119 We assume that N and M will not exceed 2^32 - 1.
12120 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12122 Given a 64-bit compilation unit signature or a type signature S, an entry
12123 in the hash table is located as follows:
12125 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12126 the low-order k bits all set to 1.
12128 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12130 3) If the hash table entry at index H matches the signature, use that
12131 entry. If the hash table entry at index H is unused (all zeroes),
12132 terminate the search: the signature is not present in the table.
12134 4) Let H = (H + H') modulo M. Repeat at Step 3.
12136 Because M > N and H' and M are relatively prime, the search is guaranteed
12137 to stop at an unused slot or find the match. */
12139 /* Create a hash table to map DWO IDs to their CU/TU entry in
12140 .debug_{info,types}.dwo in DWP_FILE.
12141 Returns NULL if there isn't one.
12142 Note: This function processes DWP files only, not DWO files. */
12144 static struct dwp_hash_table
*
12145 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12146 struct dwp_file
*dwp_file
, int is_debug_types
)
12148 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12149 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12150 const gdb_byte
*index_ptr
, *index_end
;
12151 struct dwarf2_section_info
*index
;
12152 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12153 struct dwp_hash_table
*htab
;
12155 if (is_debug_types
)
12156 index
= &dwp_file
->sections
.tu_index
;
12158 index
= &dwp_file
->sections
.cu_index
;
12160 if (dwarf2_section_empty_p (index
))
12162 dwarf2_read_section (objfile
, index
);
12164 index_ptr
= index
->buffer
;
12165 index_end
= index_ptr
+ index
->size
;
12167 version
= read_4_bytes (dbfd
, index_ptr
);
12170 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12174 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12176 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12179 if (version
!= 1 && version
!= 2)
12181 error (_("Dwarf Error: unsupported DWP file version (%s)"
12182 " [in module %s]"),
12183 pulongest (version
), dwp_file
->name
);
12185 if (nr_slots
!= (nr_slots
& -nr_slots
))
12187 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12188 " is not power of 2 [in module %s]"),
12189 pulongest (nr_slots
), dwp_file
->name
);
12192 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12193 htab
->version
= version
;
12194 htab
->nr_columns
= nr_columns
;
12195 htab
->nr_units
= nr_units
;
12196 htab
->nr_slots
= nr_slots
;
12197 htab
->hash_table
= index_ptr
;
12198 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12200 /* Exit early if the table is empty. */
12201 if (nr_slots
== 0 || nr_units
== 0
12202 || (version
== 2 && nr_columns
== 0))
12204 /* All must be zero. */
12205 if (nr_slots
!= 0 || nr_units
!= 0
12206 || (version
== 2 && nr_columns
!= 0))
12208 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
12209 " all zero [in modules %s]"),
12217 htab
->section_pool
.v1
.indices
=
12218 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12219 /* It's harder to decide whether the section is too small in v1.
12220 V1 is deprecated anyway so we punt. */
12224 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12225 int *ids
= htab
->section_pool
.v2
.section_ids
;
12226 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
12227 /* Reverse map for error checking. */
12228 int ids_seen
[DW_SECT_MAX
+ 1];
12231 if (nr_columns
< 2)
12233 error (_("Dwarf Error: bad DWP hash table, too few columns"
12234 " in section table [in module %s]"),
12237 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12239 error (_("Dwarf Error: bad DWP hash table, too many columns"
12240 " in section table [in module %s]"),
12243 memset (ids
, 255, sizeof_ids
);
12244 memset (ids_seen
, 255, sizeof (ids_seen
));
12245 for (i
= 0; i
< nr_columns
; ++i
)
12247 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12249 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12251 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12252 " in section table [in module %s]"),
12253 id
, dwp_file
->name
);
12255 if (ids_seen
[id
] != -1)
12257 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12258 " id %d in section table [in module %s]"),
12259 id
, dwp_file
->name
);
12264 /* Must have exactly one info or types section. */
12265 if (((ids_seen
[DW_SECT_INFO
] != -1)
12266 + (ids_seen
[DW_SECT_TYPES
] != -1))
12269 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12270 " DWO info/types section [in module %s]"),
12273 /* Must have an abbrev section. */
12274 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12276 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12277 " section [in module %s]"),
12280 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12281 htab
->section_pool
.v2
.sizes
=
12282 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12283 * nr_units
* nr_columns
);
12284 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12285 * nr_units
* nr_columns
))
12288 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12289 " [in module %s]"),
12297 /* Update SECTIONS with the data from SECTP.
12299 This function is like the other "locate" section routines that are
12300 passed to bfd_map_over_sections, but in this context the sections to
12301 read comes from the DWP V1 hash table, not the full ELF section table.
12303 The result is non-zero for success, or zero if an error was found. */
12306 locate_v1_virtual_dwo_sections (asection
*sectp
,
12307 struct virtual_v1_dwo_sections
*sections
)
12309 const struct dwop_section_names
*names
= &dwop_section_names
;
12311 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12313 /* There can be only one. */
12314 if (sections
->abbrev
.s
.section
!= NULL
)
12316 sections
->abbrev
.s
.section
= sectp
;
12317 sections
->abbrev
.size
= bfd_section_size (sectp
);
12319 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12320 || section_is_p (sectp
->name
, &names
->types_dwo
))
12322 /* There can be only one. */
12323 if (sections
->info_or_types
.s
.section
!= NULL
)
12325 sections
->info_or_types
.s
.section
= sectp
;
12326 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12328 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12330 /* There can be only one. */
12331 if (sections
->line
.s
.section
!= NULL
)
12333 sections
->line
.s
.section
= sectp
;
12334 sections
->line
.size
= bfd_section_size (sectp
);
12336 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12338 /* There can be only one. */
12339 if (sections
->loc
.s
.section
!= NULL
)
12341 sections
->loc
.s
.section
= sectp
;
12342 sections
->loc
.size
= bfd_section_size (sectp
);
12344 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12346 /* There can be only one. */
12347 if (sections
->macinfo
.s
.section
!= NULL
)
12349 sections
->macinfo
.s
.section
= sectp
;
12350 sections
->macinfo
.size
= bfd_section_size (sectp
);
12352 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12354 /* There can be only one. */
12355 if (sections
->macro
.s
.section
!= NULL
)
12357 sections
->macro
.s
.section
= sectp
;
12358 sections
->macro
.size
= bfd_section_size (sectp
);
12360 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12362 /* There can be only one. */
12363 if (sections
->str_offsets
.s
.section
!= NULL
)
12365 sections
->str_offsets
.s
.section
= sectp
;
12366 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12370 /* No other kind of section is valid. */
12377 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12378 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12379 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12380 This is for DWP version 1 files. */
12382 static struct dwo_unit
*
12383 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12384 struct dwp_file
*dwp_file
,
12385 uint32_t unit_index
,
12386 const char *comp_dir
,
12387 ULONGEST signature
, int is_debug_types
)
12389 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12390 const struct dwp_hash_table
*dwp_htab
=
12391 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12392 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12393 const char *kind
= is_debug_types
? "TU" : "CU";
12394 struct dwo_file
*dwo_file
;
12395 struct dwo_unit
*dwo_unit
;
12396 struct virtual_v1_dwo_sections sections
;
12397 void **dwo_file_slot
;
12400 gdb_assert (dwp_file
->version
== 1);
12402 if (dwarf_read_debug
)
12404 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12406 pulongest (unit_index
), hex_string (signature
),
12410 /* Fetch the sections of this DWO unit.
12411 Put a limit on the number of sections we look for so that bad data
12412 doesn't cause us to loop forever. */
12414 #define MAX_NR_V1_DWO_SECTIONS \
12415 (1 /* .debug_info or .debug_types */ \
12416 + 1 /* .debug_abbrev */ \
12417 + 1 /* .debug_line */ \
12418 + 1 /* .debug_loc */ \
12419 + 1 /* .debug_str_offsets */ \
12420 + 1 /* .debug_macro or .debug_macinfo */ \
12421 + 1 /* trailing zero */)
12423 memset (§ions
, 0, sizeof (sections
));
12425 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12428 uint32_t section_nr
=
12429 read_4_bytes (dbfd
,
12430 dwp_htab
->section_pool
.v1
.indices
12431 + (unit_index
+ i
) * sizeof (uint32_t));
12433 if (section_nr
== 0)
12435 if (section_nr
>= dwp_file
->num_sections
)
12437 error (_("Dwarf Error: bad DWP hash table, section number too large"
12438 " [in module %s]"),
12442 sectp
= dwp_file
->elf_sections
[section_nr
];
12443 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12445 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12446 " [in module %s]"),
12452 || dwarf2_section_empty_p (§ions
.info_or_types
)
12453 || dwarf2_section_empty_p (§ions
.abbrev
))
12455 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12456 " [in module %s]"),
12459 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12461 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12462 " [in module %s]"),
12466 /* It's easier for the rest of the code if we fake a struct dwo_file and
12467 have dwo_unit "live" in that. At least for now.
12469 The DWP file can be made up of a random collection of CUs and TUs.
12470 However, for each CU + set of TUs that came from the same original DWO
12471 file, we can combine them back into a virtual DWO file to save space
12472 (fewer struct dwo_file objects to allocate). Remember that for really
12473 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12475 std::string virtual_dwo_name
=
12476 string_printf ("virtual-dwo/%d-%d-%d-%d",
12477 get_section_id (§ions
.abbrev
),
12478 get_section_id (§ions
.line
),
12479 get_section_id (§ions
.loc
),
12480 get_section_id (§ions
.str_offsets
));
12481 /* Can we use an existing virtual DWO file? */
12482 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12483 virtual_dwo_name
.c_str (),
12485 /* Create one if necessary. */
12486 if (*dwo_file_slot
== NULL
)
12488 if (dwarf_read_debug
)
12490 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12491 virtual_dwo_name
.c_str ());
12493 dwo_file
= new struct dwo_file
;
12494 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12496 dwo_file
->comp_dir
= comp_dir
;
12497 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12498 dwo_file
->sections
.line
= sections
.line
;
12499 dwo_file
->sections
.loc
= sections
.loc
;
12500 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12501 dwo_file
->sections
.macro
= sections
.macro
;
12502 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12503 /* The "str" section is global to the entire DWP file. */
12504 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12505 /* The info or types section is assigned below to dwo_unit,
12506 there's no need to record it in dwo_file.
12507 Also, we can't simply record type sections in dwo_file because
12508 we record a pointer into the vector in dwo_unit. As we collect more
12509 types we'll grow the vector and eventually have to reallocate space
12510 for it, invalidating all copies of pointers into the previous
12512 *dwo_file_slot
= dwo_file
;
12516 if (dwarf_read_debug
)
12518 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12519 virtual_dwo_name
.c_str ());
12521 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12524 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12525 dwo_unit
->dwo_file
= dwo_file
;
12526 dwo_unit
->signature
= signature
;
12527 dwo_unit
->section
=
12528 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12529 *dwo_unit
->section
= sections
.info_or_types
;
12530 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12535 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12536 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12537 piece within that section used by a TU/CU, return a virtual section
12538 of just that piece. */
12540 static struct dwarf2_section_info
12541 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12542 struct dwarf2_section_info
*section
,
12543 bfd_size_type offset
, bfd_size_type size
)
12545 struct dwarf2_section_info result
;
12548 gdb_assert (section
!= NULL
);
12549 gdb_assert (!section
->is_virtual
);
12551 memset (&result
, 0, sizeof (result
));
12552 result
.s
.containing_section
= section
;
12553 result
.is_virtual
= true;
12558 sectp
= get_section_bfd_section (section
);
12560 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12561 bounds of the real section. This is a pretty-rare event, so just
12562 flag an error (easier) instead of a warning and trying to cope. */
12564 || offset
+ size
> bfd_section_size (sectp
))
12566 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12567 " in section %s [in module %s]"),
12568 sectp
? bfd_section_name (sectp
) : "<unknown>",
12569 objfile_name (dwarf2_per_objfile
->objfile
));
12572 result
.virtual_offset
= offset
;
12573 result
.size
= size
;
12577 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12578 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12579 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12580 This is for DWP version 2 files. */
12582 static struct dwo_unit
*
12583 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12584 struct dwp_file
*dwp_file
,
12585 uint32_t unit_index
,
12586 const char *comp_dir
,
12587 ULONGEST signature
, int is_debug_types
)
12589 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12590 const struct dwp_hash_table
*dwp_htab
=
12591 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12592 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12593 const char *kind
= is_debug_types
? "TU" : "CU";
12594 struct dwo_file
*dwo_file
;
12595 struct dwo_unit
*dwo_unit
;
12596 struct virtual_v2_dwo_sections sections
;
12597 void **dwo_file_slot
;
12600 gdb_assert (dwp_file
->version
== 2);
12602 if (dwarf_read_debug
)
12604 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12606 pulongest (unit_index
), hex_string (signature
),
12610 /* Fetch the section offsets of this DWO unit. */
12612 memset (§ions
, 0, sizeof (sections
));
12614 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12616 uint32_t offset
= read_4_bytes (dbfd
,
12617 dwp_htab
->section_pool
.v2
.offsets
12618 + (((unit_index
- 1) * dwp_htab
->nr_columns
12620 * sizeof (uint32_t)));
12621 uint32_t size
= read_4_bytes (dbfd
,
12622 dwp_htab
->section_pool
.v2
.sizes
12623 + (((unit_index
- 1) * dwp_htab
->nr_columns
12625 * sizeof (uint32_t)));
12627 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12630 case DW_SECT_TYPES
:
12631 sections
.info_or_types_offset
= offset
;
12632 sections
.info_or_types_size
= size
;
12634 case DW_SECT_ABBREV
:
12635 sections
.abbrev_offset
= offset
;
12636 sections
.abbrev_size
= size
;
12639 sections
.line_offset
= offset
;
12640 sections
.line_size
= size
;
12643 sections
.loc_offset
= offset
;
12644 sections
.loc_size
= size
;
12646 case DW_SECT_STR_OFFSETS
:
12647 sections
.str_offsets_offset
= offset
;
12648 sections
.str_offsets_size
= size
;
12650 case DW_SECT_MACINFO
:
12651 sections
.macinfo_offset
= offset
;
12652 sections
.macinfo_size
= size
;
12654 case DW_SECT_MACRO
:
12655 sections
.macro_offset
= offset
;
12656 sections
.macro_size
= size
;
12661 /* It's easier for the rest of the code if we fake a struct dwo_file and
12662 have dwo_unit "live" in that. At least for now.
12664 The DWP file can be made up of a random collection of CUs and TUs.
12665 However, for each CU + set of TUs that came from the same original DWO
12666 file, we can combine them back into a virtual DWO file to save space
12667 (fewer struct dwo_file objects to allocate). Remember that for really
12668 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12670 std::string virtual_dwo_name
=
12671 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12672 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12673 (long) (sections
.line_size
? sections
.line_offset
: 0),
12674 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12675 (long) (sections
.str_offsets_size
12676 ? sections
.str_offsets_offset
: 0));
12677 /* Can we use an existing virtual DWO file? */
12678 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12679 virtual_dwo_name
.c_str (),
12681 /* Create one if necessary. */
12682 if (*dwo_file_slot
== NULL
)
12684 if (dwarf_read_debug
)
12686 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12687 virtual_dwo_name
.c_str ());
12689 dwo_file
= new struct dwo_file
;
12690 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12692 dwo_file
->comp_dir
= comp_dir
;
12693 dwo_file
->sections
.abbrev
=
12694 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12695 sections
.abbrev_offset
, sections
.abbrev_size
);
12696 dwo_file
->sections
.line
=
12697 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12698 sections
.line_offset
, sections
.line_size
);
12699 dwo_file
->sections
.loc
=
12700 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12701 sections
.loc_offset
, sections
.loc_size
);
12702 dwo_file
->sections
.macinfo
=
12703 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12704 sections
.macinfo_offset
, sections
.macinfo_size
);
12705 dwo_file
->sections
.macro
=
12706 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12707 sections
.macro_offset
, sections
.macro_size
);
12708 dwo_file
->sections
.str_offsets
=
12709 create_dwp_v2_section (dwarf2_per_objfile
,
12710 &dwp_file
->sections
.str_offsets
,
12711 sections
.str_offsets_offset
,
12712 sections
.str_offsets_size
);
12713 /* The "str" section is global to the entire DWP file. */
12714 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12715 /* The info or types section is assigned below to dwo_unit,
12716 there's no need to record it in dwo_file.
12717 Also, we can't simply record type sections in dwo_file because
12718 we record a pointer into the vector in dwo_unit. As we collect more
12719 types we'll grow the vector and eventually have to reallocate space
12720 for it, invalidating all copies of pointers into the previous
12722 *dwo_file_slot
= dwo_file
;
12726 if (dwarf_read_debug
)
12728 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12729 virtual_dwo_name
.c_str ());
12731 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12734 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12735 dwo_unit
->dwo_file
= dwo_file
;
12736 dwo_unit
->signature
= signature
;
12737 dwo_unit
->section
=
12738 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12739 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12741 ? &dwp_file
->sections
.types
12742 : &dwp_file
->sections
.info
,
12743 sections
.info_or_types_offset
,
12744 sections
.info_or_types_size
);
12745 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12750 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12751 Returns NULL if the signature isn't found. */
12753 static struct dwo_unit
*
12754 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12755 struct dwp_file
*dwp_file
, const char *comp_dir
,
12756 ULONGEST signature
, int is_debug_types
)
12758 const struct dwp_hash_table
*dwp_htab
=
12759 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12760 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12761 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12762 uint32_t hash
= signature
& mask
;
12763 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12766 struct dwo_unit find_dwo_cu
;
12768 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12769 find_dwo_cu
.signature
= signature
;
12770 slot
= htab_find_slot (is_debug_types
12771 ? dwp_file
->loaded_tus
12772 : dwp_file
->loaded_cus
,
12773 &find_dwo_cu
, INSERT
);
12776 return (struct dwo_unit
*) *slot
;
12778 /* Use a for loop so that we don't loop forever on bad debug info. */
12779 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12781 ULONGEST signature_in_table
;
12783 signature_in_table
=
12784 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12785 if (signature_in_table
== signature
)
12787 uint32_t unit_index
=
12788 read_4_bytes (dbfd
,
12789 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12791 if (dwp_file
->version
== 1)
12793 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12794 dwp_file
, unit_index
,
12795 comp_dir
, signature
,
12800 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12801 dwp_file
, unit_index
,
12802 comp_dir
, signature
,
12805 return (struct dwo_unit
*) *slot
;
12807 if (signature_in_table
== 0)
12809 hash
= (hash
+ hash2
) & mask
;
12812 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12813 " [in module %s]"),
12817 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12818 Open the file specified by FILE_NAME and hand it off to BFD for
12819 preliminary analysis. Return a newly initialized bfd *, which
12820 includes a canonicalized copy of FILE_NAME.
12821 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12822 SEARCH_CWD is true if the current directory is to be searched.
12823 It will be searched before debug-file-directory.
12824 If successful, the file is added to the bfd include table of the
12825 objfile's bfd (see gdb_bfd_record_inclusion).
12826 If unable to find/open the file, return NULL.
12827 NOTE: This function is derived from symfile_bfd_open. */
12829 static gdb_bfd_ref_ptr
12830 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12831 const char *file_name
, int is_dwp
, int search_cwd
)
12834 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12835 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12836 to debug_file_directory. */
12837 const char *search_path
;
12838 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12840 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12843 if (*debug_file_directory
!= '\0')
12845 search_path_holder
.reset (concat (".", dirname_separator_string
,
12846 debug_file_directory
,
12848 search_path
= search_path_holder
.get ();
12854 search_path
= debug_file_directory
;
12856 openp_flags flags
= OPF_RETURN_REALPATH
;
12858 flags
|= OPF_SEARCH_IN_PATH
;
12860 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12861 desc
= openp (search_path
, flags
, file_name
,
12862 O_RDONLY
| O_BINARY
, &absolute_name
);
12866 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12868 if (sym_bfd
== NULL
)
12870 bfd_set_cacheable (sym_bfd
.get (), 1);
12872 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12875 /* Success. Record the bfd as having been included by the objfile's bfd.
12876 This is important because things like demangled_names_hash lives in the
12877 objfile's per_bfd space and may have references to things like symbol
12878 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12879 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12884 /* Try to open DWO file FILE_NAME.
12885 COMP_DIR is the DW_AT_comp_dir attribute.
12886 The result is the bfd handle of the file.
12887 If there is a problem finding or opening the file, return NULL.
12888 Upon success, the canonicalized path of the file is stored in the bfd,
12889 same as symfile_bfd_open. */
12891 static gdb_bfd_ref_ptr
12892 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12893 const char *file_name
, const char *comp_dir
)
12895 if (IS_ABSOLUTE_PATH (file_name
))
12896 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12897 0 /*is_dwp*/, 0 /*search_cwd*/);
12899 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12901 if (comp_dir
!= NULL
)
12903 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
12904 file_name
, (char *) NULL
);
12906 /* NOTE: If comp_dir is a relative path, this will also try the
12907 search path, which seems useful. */
12908 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12911 1 /*search_cwd*/));
12912 xfree (path_to_try
);
12917 /* That didn't work, try debug-file-directory, which, despite its name,
12918 is a list of paths. */
12920 if (*debug_file_directory
== '\0')
12923 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12924 0 /*is_dwp*/, 1 /*search_cwd*/);
12927 /* This function is mapped across the sections and remembers the offset and
12928 size of each of the DWO debugging sections we are interested in. */
12931 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12933 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12934 const struct dwop_section_names
*names
= &dwop_section_names
;
12936 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12938 dwo_sections
->abbrev
.s
.section
= sectp
;
12939 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12941 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12943 dwo_sections
->info
.s
.section
= sectp
;
12944 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12946 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12948 dwo_sections
->line
.s
.section
= sectp
;
12949 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12951 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12953 dwo_sections
->loc
.s
.section
= sectp
;
12954 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12956 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12958 dwo_sections
->macinfo
.s
.section
= sectp
;
12959 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12961 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12963 dwo_sections
->macro
.s
.section
= sectp
;
12964 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12966 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12968 dwo_sections
->str
.s
.section
= sectp
;
12969 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12971 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12973 dwo_sections
->str_offsets
.s
.section
= sectp
;
12974 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12976 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12978 struct dwarf2_section_info type_section
;
12980 memset (&type_section
, 0, sizeof (type_section
));
12981 type_section
.s
.section
= sectp
;
12982 type_section
.size
= bfd_section_size (sectp
);
12983 dwo_sections
->types
.push_back (type_section
);
12987 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12988 by PER_CU. This is for the non-DWP case.
12989 The result is NULL if DWO_NAME can't be found. */
12991 static struct dwo_file
*
12992 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12993 const char *dwo_name
, const char *comp_dir
)
12995 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12997 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
13000 if (dwarf_read_debug
)
13001 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13005 dwo_file_up
dwo_file (new struct dwo_file
);
13006 dwo_file
->dwo_name
= dwo_name
;
13007 dwo_file
->comp_dir
= comp_dir
;
13008 dwo_file
->dbfd
= std::move (dbfd
);
13010 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
13011 &dwo_file
->sections
);
13013 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13016 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
13017 dwo_file
->sections
.types
, dwo_file
->tus
);
13019 if (dwarf_read_debug
)
13020 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13022 return dwo_file
.release ();
13025 /* This function is mapped across the sections and remembers the offset and
13026 size of each of the DWP debugging sections common to version 1 and 2 that
13027 we are interested in. */
13030 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13031 void *dwp_file_ptr
)
13033 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13034 const struct dwop_section_names
*names
= &dwop_section_names
;
13035 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13037 /* Record the ELF section number for later lookup: this is what the
13038 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13039 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13040 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13042 /* Look for specific sections that we need. */
13043 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13045 dwp_file
->sections
.str
.s
.section
= sectp
;
13046 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
13048 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13050 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13051 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
13053 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13055 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13056 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
13060 /* This function is mapped across the sections and remembers the offset and
13061 size of each of the DWP version 2 debugging sections that we are interested
13062 in. This is split into a separate function because we don't know if we
13063 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13066 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13068 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13069 const struct dwop_section_names
*names
= &dwop_section_names
;
13070 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13072 /* Record the ELF section number for later lookup: this is what the
13073 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13074 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13075 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13077 /* Look for specific sections that we need. */
13078 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13080 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13081 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13083 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13085 dwp_file
->sections
.info
.s
.section
= sectp
;
13086 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13088 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13090 dwp_file
->sections
.line
.s
.section
= sectp
;
13091 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13093 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13095 dwp_file
->sections
.loc
.s
.section
= sectp
;
13096 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
13098 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13100 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13101 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
13103 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13105 dwp_file
->sections
.macro
.s
.section
= sectp
;
13106 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13108 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13110 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13111 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13113 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13115 dwp_file
->sections
.types
.s
.section
= sectp
;
13116 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13120 /* Hash function for dwp_file loaded CUs/TUs. */
13123 hash_dwp_loaded_cutus (const void *item
)
13125 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13127 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13128 return dwo_unit
->signature
;
13131 /* Equality function for dwp_file loaded CUs/TUs. */
13134 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13136 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13137 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13139 return dua
->signature
== dub
->signature
;
13142 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13145 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13147 return htab_create_alloc_ex (3,
13148 hash_dwp_loaded_cutus
,
13149 eq_dwp_loaded_cutus
,
13151 &objfile
->objfile_obstack
,
13152 hashtab_obstack_allocate
,
13153 dummy_obstack_deallocate
);
13156 /* Try to open DWP file FILE_NAME.
13157 The result is the bfd handle of the file.
13158 If there is a problem finding or opening the file, return NULL.
13159 Upon success, the canonicalized path of the file is stored in the bfd,
13160 same as symfile_bfd_open. */
13162 static gdb_bfd_ref_ptr
13163 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13164 const char *file_name
)
13166 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13168 1 /*search_cwd*/));
13172 /* Work around upstream bug 15652.
13173 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13174 [Whether that's a "bug" is debatable, but it is getting in our way.]
13175 We have no real idea where the dwp file is, because gdb's realpath-ing
13176 of the executable's path may have discarded the needed info.
13177 [IWBN if the dwp file name was recorded in the executable, akin to
13178 .gnu_debuglink, but that doesn't exist yet.]
13179 Strip the directory from FILE_NAME and search again. */
13180 if (*debug_file_directory
!= '\0')
13182 /* Don't implicitly search the current directory here.
13183 If the user wants to search "." to handle this case,
13184 it must be added to debug-file-directory. */
13185 return try_open_dwop_file (dwarf2_per_objfile
,
13186 lbasename (file_name
), 1 /*is_dwp*/,
13193 /* Initialize the use of the DWP file for the current objfile.
13194 By convention the name of the DWP file is ${objfile}.dwp.
13195 The result is NULL if it can't be found. */
13197 static std::unique_ptr
<struct dwp_file
>
13198 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13200 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13202 /* Try to find first .dwp for the binary file before any symbolic links
13205 /* If the objfile is a debug file, find the name of the real binary
13206 file and get the name of dwp file from there. */
13207 std::string dwp_name
;
13208 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13210 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13211 const char *backlink_basename
= lbasename (backlink
->original_name
);
13213 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13216 dwp_name
= objfile
->original_name
;
13218 dwp_name
+= ".dwp";
13220 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13222 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13224 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13225 dwp_name
= objfile_name (objfile
);
13226 dwp_name
+= ".dwp";
13227 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13232 if (dwarf_read_debug
)
13233 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13234 return std::unique_ptr
<dwp_file
> ();
13237 const char *name
= bfd_get_filename (dbfd
.get ());
13238 std::unique_ptr
<struct dwp_file
> dwp_file
13239 (new struct dwp_file (name
, std::move (dbfd
)));
13241 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13242 dwp_file
->elf_sections
=
13243 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13244 dwp_file
->num_sections
, asection
*);
13246 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13247 dwarf2_locate_common_dwp_sections
,
13250 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13253 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13256 /* The DWP file version is stored in the hash table. Oh well. */
13257 if (dwp_file
->cus
&& dwp_file
->tus
13258 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13260 /* Technically speaking, we should try to limp along, but this is
13261 pretty bizarre. We use pulongest here because that's the established
13262 portability solution (e.g, we cannot use %u for uint32_t). */
13263 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13264 " TU version %s [in DWP file %s]"),
13265 pulongest (dwp_file
->cus
->version
),
13266 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13270 dwp_file
->version
= dwp_file
->cus
->version
;
13271 else if (dwp_file
->tus
)
13272 dwp_file
->version
= dwp_file
->tus
->version
;
13274 dwp_file
->version
= 2;
13276 if (dwp_file
->version
== 2)
13277 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13278 dwarf2_locate_v2_dwp_sections
,
13281 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13282 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13284 if (dwarf_read_debug
)
13286 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13287 fprintf_unfiltered (gdb_stdlog
,
13288 " %s CUs, %s TUs\n",
13289 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13290 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13296 /* Wrapper around open_and_init_dwp_file, only open it once. */
13298 static struct dwp_file
*
13299 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13301 if (! dwarf2_per_objfile
->dwp_checked
)
13303 dwarf2_per_objfile
->dwp_file
13304 = open_and_init_dwp_file (dwarf2_per_objfile
);
13305 dwarf2_per_objfile
->dwp_checked
= 1;
13307 return dwarf2_per_objfile
->dwp_file
.get ();
13310 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13311 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13312 or in the DWP file for the objfile, referenced by THIS_UNIT.
13313 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13314 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13316 This is called, for example, when wanting to read a variable with a
13317 complex location. Therefore we don't want to do file i/o for every call.
13318 Therefore we don't want to look for a DWO file on every call.
13319 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13320 then we check if we've already seen DWO_NAME, and only THEN do we check
13323 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13324 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13326 static struct dwo_unit
*
13327 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13328 const char *dwo_name
, const char *comp_dir
,
13329 ULONGEST signature
, int is_debug_types
)
13331 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13332 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13333 const char *kind
= is_debug_types
? "TU" : "CU";
13334 void **dwo_file_slot
;
13335 struct dwo_file
*dwo_file
;
13336 struct dwp_file
*dwp_file
;
13338 /* First see if there's a DWP file.
13339 If we have a DWP file but didn't find the DWO inside it, don't
13340 look for the original DWO file. It makes gdb behave differently
13341 depending on whether one is debugging in the build tree. */
13343 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13344 if (dwp_file
!= NULL
)
13346 const struct dwp_hash_table
*dwp_htab
=
13347 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13349 if (dwp_htab
!= NULL
)
13351 struct dwo_unit
*dwo_cutu
=
13352 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13353 signature
, is_debug_types
);
13355 if (dwo_cutu
!= NULL
)
13357 if (dwarf_read_debug
)
13359 fprintf_unfiltered (gdb_stdlog
,
13360 "Virtual DWO %s %s found: @%s\n",
13361 kind
, hex_string (signature
),
13362 host_address_to_string (dwo_cutu
));
13370 /* No DWP file, look for the DWO file. */
13372 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13373 dwo_name
, comp_dir
);
13374 if (*dwo_file_slot
== NULL
)
13376 /* Read in the file and build a table of the CUs/TUs it contains. */
13377 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13379 /* NOTE: This will be NULL if unable to open the file. */
13380 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13382 if (dwo_file
!= NULL
)
13384 struct dwo_unit
*dwo_cutu
= NULL
;
13386 if (is_debug_types
&& dwo_file
->tus
)
13388 struct dwo_unit find_dwo_cutu
;
13390 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13391 find_dwo_cutu
.signature
= signature
;
13393 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13395 else if (!is_debug_types
&& dwo_file
->cus
)
13397 struct dwo_unit find_dwo_cutu
;
13399 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13400 find_dwo_cutu
.signature
= signature
;
13401 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13405 if (dwo_cutu
!= NULL
)
13407 if (dwarf_read_debug
)
13409 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13410 kind
, dwo_name
, hex_string (signature
),
13411 host_address_to_string (dwo_cutu
));
13418 /* We didn't find it. This could mean a dwo_id mismatch, or
13419 someone deleted the DWO/DWP file, or the search path isn't set up
13420 correctly to find the file. */
13422 if (dwarf_read_debug
)
13424 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13425 kind
, dwo_name
, hex_string (signature
));
13428 /* This is a warning and not a complaint because it can be caused by
13429 pilot error (e.g., user accidentally deleting the DWO). */
13431 /* Print the name of the DWP file if we looked there, helps the user
13432 better diagnose the problem. */
13433 std::string dwp_text
;
13435 if (dwp_file
!= NULL
)
13436 dwp_text
= string_printf (" [in DWP file %s]",
13437 lbasename (dwp_file
->name
));
13439 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13440 " [in module %s]"),
13441 kind
, dwo_name
, hex_string (signature
),
13443 this_unit
->is_debug_types
? "TU" : "CU",
13444 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13449 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13450 See lookup_dwo_cutu_unit for details. */
13452 static struct dwo_unit
*
13453 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13454 const char *dwo_name
, const char *comp_dir
,
13455 ULONGEST signature
)
13457 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13460 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13461 See lookup_dwo_cutu_unit for details. */
13463 static struct dwo_unit
*
13464 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13465 const char *dwo_name
, const char *comp_dir
)
13467 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13470 /* Traversal function for queue_and_load_all_dwo_tus. */
13473 queue_and_load_dwo_tu (void **slot
, void *info
)
13475 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13476 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13477 ULONGEST signature
= dwo_unit
->signature
;
13478 struct signatured_type
*sig_type
=
13479 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13481 if (sig_type
!= NULL
)
13483 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13485 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13486 a real dependency of PER_CU on SIG_TYPE. That is detected later
13487 while processing PER_CU. */
13488 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13489 load_full_type_unit (sig_cu
);
13490 per_cu
->imported_symtabs_push (sig_cu
);
13496 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13497 The DWO may have the only definition of the type, though it may not be
13498 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13499 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13502 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13504 struct dwo_unit
*dwo_unit
;
13505 struct dwo_file
*dwo_file
;
13507 gdb_assert (!per_cu
->is_debug_types
);
13508 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13509 gdb_assert (per_cu
->cu
!= NULL
);
13511 dwo_unit
= per_cu
->cu
->dwo_unit
;
13512 gdb_assert (dwo_unit
!= NULL
);
13514 dwo_file
= dwo_unit
->dwo_file
;
13515 if (dwo_file
->tus
!= NULL
)
13516 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13519 /* Read in various DIEs. */
13521 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13522 Inherit only the children of the DW_AT_abstract_origin DIE not being
13523 already referenced by DW_AT_abstract_origin from the children of the
13527 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13529 struct die_info
*child_die
;
13530 sect_offset
*offsetp
;
13531 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13532 struct die_info
*origin_die
;
13533 /* Iterator of the ORIGIN_DIE children. */
13534 struct die_info
*origin_child_die
;
13535 struct attribute
*attr
;
13536 struct dwarf2_cu
*origin_cu
;
13537 struct pending
**origin_previous_list_in_scope
;
13539 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13543 /* Note that following die references may follow to a die in a
13547 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13549 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13551 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13552 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13554 if (die
->tag
!= origin_die
->tag
13555 && !(die
->tag
== DW_TAG_inlined_subroutine
13556 && origin_die
->tag
== DW_TAG_subprogram
))
13557 complaint (_("DIE %s and its abstract origin %s have different tags"),
13558 sect_offset_str (die
->sect_off
),
13559 sect_offset_str (origin_die
->sect_off
));
13561 std::vector
<sect_offset
> offsets
;
13563 for (child_die
= die
->child
;
13564 child_die
&& child_die
->tag
;
13565 child_die
= sibling_die (child_die
))
13567 struct die_info
*child_origin_die
;
13568 struct dwarf2_cu
*child_origin_cu
;
13570 /* We are trying to process concrete instance entries:
13571 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13572 it's not relevant to our analysis here. i.e. detecting DIEs that are
13573 present in the abstract instance but not referenced in the concrete
13575 if (child_die
->tag
== DW_TAG_call_site
13576 || child_die
->tag
== DW_TAG_GNU_call_site
)
13579 /* For each CHILD_DIE, find the corresponding child of
13580 ORIGIN_DIE. If there is more than one layer of
13581 DW_AT_abstract_origin, follow them all; there shouldn't be,
13582 but GCC versions at least through 4.4 generate this (GCC PR
13584 child_origin_die
= child_die
;
13585 child_origin_cu
= cu
;
13588 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13592 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13596 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13597 counterpart may exist. */
13598 if (child_origin_die
!= child_die
)
13600 if (child_die
->tag
!= child_origin_die
->tag
13601 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13602 && child_origin_die
->tag
== DW_TAG_subprogram
))
13603 complaint (_("Child DIE %s and its abstract origin %s have "
13605 sect_offset_str (child_die
->sect_off
),
13606 sect_offset_str (child_origin_die
->sect_off
));
13607 if (child_origin_die
->parent
!= origin_die
)
13608 complaint (_("Child DIE %s and its abstract origin %s have "
13609 "different parents"),
13610 sect_offset_str (child_die
->sect_off
),
13611 sect_offset_str (child_origin_die
->sect_off
));
13613 offsets
.push_back (child_origin_die
->sect_off
);
13616 std::sort (offsets
.begin (), offsets
.end ());
13617 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13618 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13619 if (offsetp
[-1] == *offsetp
)
13620 complaint (_("Multiple children of DIE %s refer "
13621 "to DIE %s as their abstract origin"),
13622 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13624 offsetp
= offsets
.data ();
13625 origin_child_die
= origin_die
->child
;
13626 while (origin_child_die
&& origin_child_die
->tag
)
13628 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13629 while (offsetp
< offsets_end
13630 && *offsetp
< origin_child_die
->sect_off
)
13632 if (offsetp
>= offsets_end
13633 || *offsetp
> origin_child_die
->sect_off
)
13635 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13636 Check whether we're already processing ORIGIN_CHILD_DIE.
13637 This can happen with mutually referenced abstract_origins.
13639 if (!origin_child_die
->in_process
)
13640 process_die (origin_child_die
, origin_cu
);
13642 origin_child_die
= sibling_die (origin_child_die
);
13644 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13648 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13650 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13651 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13652 struct context_stack
*newobj
;
13655 struct die_info
*child_die
;
13656 struct attribute
*attr
, *call_line
, *call_file
;
13658 CORE_ADDR baseaddr
;
13659 struct block
*block
;
13660 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13661 std::vector
<struct symbol
*> template_args
;
13662 struct template_symbol
*templ_func
= NULL
;
13666 /* If we do not have call site information, we can't show the
13667 caller of this inlined function. That's too confusing, so
13668 only use the scope for local variables. */
13669 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13670 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13671 if (call_line
== NULL
|| call_file
== NULL
)
13673 read_lexical_block_scope (die
, cu
);
13678 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13680 name
= dwarf2_name (die
, cu
);
13682 /* Ignore functions with missing or empty names. These are actually
13683 illegal according to the DWARF standard. */
13686 complaint (_("missing name for subprogram DIE at %s"),
13687 sect_offset_str (die
->sect_off
));
13691 /* Ignore functions with missing or invalid low and high pc attributes. */
13692 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13693 <= PC_BOUNDS_INVALID
)
13695 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13696 if (!attr
|| !DW_UNSND (attr
))
13697 complaint (_("cannot get low and high bounds "
13698 "for subprogram DIE at %s"),
13699 sect_offset_str (die
->sect_off
));
13703 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13704 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13706 /* If we have any template arguments, then we must allocate a
13707 different sort of symbol. */
13708 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13710 if (child_die
->tag
== DW_TAG_template_type_param
13711 || child_die
->tag
== DW_TAG_template_value_param
)
13713 templ_func
= allocate_template_symbol (objfile
);
13714 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13719 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13720 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13721 (struct symbol
*) templ_func
);
13723 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13724 set_objfile_main_name (objfile
, SYMBOL_LINKAGE_NAME (newobj
->name
),
13727 /* If there is a location expression for DW_AT_frame_base, record
13729 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13731 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13733 /* If there is a location for the static link, record it. */
13734 newobj
->static_link
= NULL
;
13735 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13738 newobj
->static_link
13739 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13740 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13741 dwarf2_per_cu_addr_type (cu
->per_cu
));
13744 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13746 if (die
->child
!= NULL
)
13748 child_die
= die
->child
;
13749 while (child_die
&& child_die
->tag
)
13751 if (child_die
->tag
== DW_TAG_template_type_param
13752 || child_die
->tag
== DW_TAG_template_value_param
)
13754 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13757 template_args
.push_back (arg
);
13760 process_die (child_die
, cu
);
13761 child_die
= sibling_die (child_die
);
13765 inherit_abstract_dies (die
, cu
);
13767 /* If we have a DW_AT_specification, we might need to import using
13768 directives from the context of the specification DIE. See the
13769 comment in determine_prefix. */
13770 if (cu
->language
== language_cplus
13771 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13773 struct dwarf2_cu
*spec_cu
= cu
;
13774 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13778 child_die
= spec_die
->child
;
13779 while (child_die
&& child_die
->tag
)
13781 if (child_die
->tag
== DW_TAG_imported_module
)
13782 process_die (child_die
, spec_cu
);
13783 child_die
= sibling_die (child_die
);
13786 /* In some cases, GCC generates specification DIEs that
13787 themselves contain DW_AT_specification attributes. */
13788 spec_die
= die_specification (spec_die
, &spec_cu
);
13792 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13793 /* Make a block for the local symbols within. */
13794 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13795 cstk
.static_link
, lowpc
, highpc
);
13797 /* For C++, set the block's scope. */
13798 if ((cu
->language
== language_cplus
13799 || cu
->language
== language_fortran
13800 || cu
->language
== language_d
13801 || cu
->language
== language_rust
)
13802 && cu
->processing_has_namespace_info
)
13803 block_set_scope (block
, determine_prefix (die
, cu
),
13804 &objfile
->objfile_obstack
);
13806 /* If we have address ranges, record them. */
13807 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13809 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13811 /* Attach template arguments to function. */
13812 if (!template_args
.empty ())
13814 gdb_assert (templ_func
!= NULL
);
13816 templ_func
->n_template_arguments
= template_args
.size ();
13817 templ_func
->template_arguments
13818 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13819 templ_func
->n_template_arguments
);
13820 memcpy (templ_func
->template_arguments
,
13821 template_args
.data (),
13822 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13824 /* Make sure that the symtab is set on the new symbols. Even
13825 though they don't appear in this symtab directly, other parts
13826 of gdb assume that symbols do, and this is reasonably
13828 for (symbol
*sym
: template_args
)
13829 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13832 /* In C++, we can have functions nested inside functions (e.g., when
13833 a function declares a class that has methods). This means that
13834 when we finish processing a function scope, we may need to go
13835 back to building a containing block's symbol lists. */
13836 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13837 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13839 /* If we've finished processing a top-level function, subsequent
13840 symbols go in the file symbol list. */
13841 if (cu
->get_builder ()->outermost_context_p ())
13842 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13845 /* Process all the DIES contained within a lexical block scope. Start
13846 a new scope, process the dies, and then close the scope. */
13849 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13851 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13852 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13853 CORE_ADDR lowpc
, highpc
;
13854 struct die_info
*child_die
;
13855 CORE_ADDR baseaddr
;
13857 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13859 /* Ignore blocks with missing or invalid low and high pc attributes. */
13860 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13861 as multiple lexical blocks? Handling children in a sane way would
13862 be nasty. Might be easier to properly extend generic blocks to
13863 describe ranges. */
13864 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13866 case PC_BOUNDS_NOT_PRESENT
:
13867 /* DW_TAG_lexical_block has no attributes, process its children as if
13868 there was no wrapping by that DW_TAG_lexical_block.
13869 GCC does no longer produces such DWARF since GCC r224161. */
13870 for (child_die
= die
->child
;
13871 child_die
!= NULL
&& child_die
->tag
;
13872 child_die
= sibling_die (child_die
))
13873 process_die (child_die
, cu
);
13875 case PC_BOUNDS_INVALID
:
13878 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13879 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13881 cu
->get_builder ()->push_context (0, lowpc
);
13882 if (die
->child
!= NULL
)
13884 child_die
= die
->child
;
13885 while (child_die
&& child_die
->tag
)
13887 process_die (child_die
, cu
);
13888 child_die
= sibling_die (child_die
);
13891 inherit_abstract_dies (die
, cu
);
13892 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13894 if (*cu
->get_builder ()->get_local_symbols () != NULL
13895 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13897 struct block
*block
13898 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13899 cstk
.start_addr
, highpc
);
13901 /* Note that recording ranges after traversing children, as we
13902 do here, means that recording a parent's ranges entails
13903 walking across all its children's ranges as they appear in
13904 the address map, which is quadratic behavior.
13906 It would be nicer to record the parent's ranges before
13907 traversing its children, simply overriding whatever you find
13908 there. But since we don't even decide whether to create a
13909 block until after we've traversed its children, that's hard
13911 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13913 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13914 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13917 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13920 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13922 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13923 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13924 CORE_ADDR pc
, baseaddr
;
13925 struct attribute
*attr
;
13926 struct call_site
*call_site
, call_site_local
;
13929 struct die_info
*child_die
;
13931 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13933 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13936 /* This was a pre-DWARF-5 GNU extension alias
13937 for DW_AT_call_return_pc. */
13938 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13942 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13943 "DIE %s [in module %s]"),
13944 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13947 pc
= attr_value_as_address (attr
) + baseaddr
;
13948 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13950 if (cu
->call_site_htab
== NULL
)
13951 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13952 NULL
, &objfile
->objfile_obstack
,
13953 hashtab_obstack_allocate
, NULL
);
13954 call_site_local
.pc
= pc
;
13955 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13958 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13959 "DIE %s [in module %s]"),
13960 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13961 objfile_name (objfile
));
13965 /* Count parameters at the caller. */
13968 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13969 child_die
= sibling_die (child_die
))
13971 if (child_die
->tag
!= DW_TAG_call_site_parameter
13972 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13974 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13975 "DW_TAG_call_site child DIE %s [in module %s]"),
13976 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13977 objfile_name (objfile
));
13985 = ((struct call_site
*)
13986 obstack_alloc (&objfile
->objfile_obstack
,
13987 sizeof (*call_site
)
13988 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13990 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13991 call_site
->pc
= pc
;
13993 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13994 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13996 struct die_info
*func_die
;
13998 /* Skip also over DW_TAG_inlined_subroutine. */
13999 for (func_die
= die
->parent
;
14000 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14001 && func_die
->tag
!= DW_TAG_subroutine_type
;
14002 func_die
= func_die
->parent
);
14004 /* DW_AT_call_all_calls is a superset
14005 of DW_AT_call_all_tail_calls. */
14007 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14008 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14009 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14010 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14012 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14013 not complete. But keep CALL_SITE for look ups via call_site_htab,
14014 both the initial caller containing the real return address PC and
14015 the final callee containing the current PC of a chain of tail
14016 calls do not need to have the tail call list complete. But any
14017 function candidate for a virtual tail call frame searched via
14018 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14019 determined unambiguously. */
14023 struct type
*func_type
= NULL
;
14026 func_type
= get_die_type (func_die
, cu
);
14027 if (func_type
!= NULL
)
14029 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14031 /* Enlist this call site to the function. */
14032 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14033 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14036 complaint (_("Cannot find function owning DW_TAG_call_site "
14037 "DIE %s [in module %s]"),
14038 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14042 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14044 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14046 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14049 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14050 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14052 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14053 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14054 /* Keep NULL DWARF_BLOCK. */;
14055 else if (attr_form_is_block (attr
))
14057 struct dwarf2_locexpr_baton
*dlbaton
;
14059 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14060 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14061 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14062 dlbaton
->per_cu
= cu
->per_cu
;
14064 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14066 else if (attr_form_is_ref (attr
))
14068 struct dwarf2_cu
*target_cu
= cu
;
14069 struct die_info
*target_die
;
14071 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14072 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14073 if (die_is_declaration (target_die
, target_cu
))
14075 const char *target_physname
;
14077 /* Prefer the mangled name; otherwise compute the demangled one. */
14078 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14079 if (target_physname
== NULL
)
14080 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14081 if (target_physname
== NULL
)
14082 complaint (_("DW_AT_call_target target DIE has invalid "
14083 "physname, for referencing DIE %s [in module %s]"),
14084 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14086 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14092 /* DW_AT_entry_pc should be preferred. */
14093 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14094 <= PC_BOUNDS_INVALID
)
14095 complaint (_("DW_AT_call_target target DIE has invalid "
14096 "low pc, for referencing DIE %s [in module %s]"),
14097 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14100 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14101 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14106 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14107 "block nor reference, for DIE %s [in module %s]"),
14108 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14110 call_site
->per_cu
= cu
->per_cu
;
14112 for (child_die
= die
->child
;
14113 child_die
&& child_die
->tag
;
14114 child_die
= sibling_die (child_die
))
14116 struct call_site_parameter
*parameter
;
14117 struct attribute
*loc
, *origin
;
14119 if (child_die
->tag
!= DW_TAG_call_site_parameter
14120 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14122 /* Already printed the complaint above. */
14126 gdb_assert (call_site
->parameter_count
< nparams
);
14127 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14129 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14130 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14131 register is contained in DW_AT_call_value. */
14133 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14134 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14135 if (origin
== NULL
)
14137 /* This was a pre-DWARF-5 GNU extension alias
14138 for DW_AT_call_parameter. */
14139 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14141 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14143 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14145 sect_offset sect_off
14146 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14147 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14149 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14150 binding can be done only inside one CU. Such referenced DIE
14151 therefore cannot be even moved to DW_TAG_partial_unit. */
14152 complaint (_("DW_AT_call_parameter offset is not in CU for "
14153 "DW_TAG_call_site child DIE %s [in module %s]"),
14154 sect_offset_str (child_die
->sect_off
),
14155 objfile_name (objfile
));
14158 parameter
->u
.param_cu_off
14159 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14161 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14163 complaint (_("No DW_FORM_block* DW_AT_location for "
14164 "DW_TAG_call_site child DIE %s [in module %s]"),
14165 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14170 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14171 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14172 if (parameter
->u
.dwarf_reg
!= -1)
14173 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14174 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14175 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14176 ¶meter
->u
.fb_offset
))
14177 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14180 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14181 "for DW_FORM_block* DW_AT_location is supported for "
14182 "DW_TAG_call_site child DIE %s "
14184 sect_offset_str (child_die
->sect_off
),
14185 objfile_name (objfile
));
14190 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14192 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14193 if (!attr_form_is_block (attr
))
14195 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14196 "DW_TAG_call_site child DIE %s [in module %s]"),
14197 sect_offset_str (child_die
->sect_off
),
14198 objfile_name (objfile
));
14201 parameter
->value
= DW_BLOCK (attr
)->data
;
14202 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14204 /* Parameters are not pre-cleared by memset above. */
14205 parameter
->data_value
= NULL
;
14206 parameter
->data_value_size
= 0;
14207 call_site
->parameter_count
++;
14209 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14211 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14214 if (!attr_form_is_block (attr
))
14215 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14216 "DW_TAG_call_site child DIE %s [in module %s]"),
14217 sect_offset_str (child_die
->sect_off
),
14218 objfile_name (objfile
));
14221 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14222 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14228 /* Helper function for read_variable. If DIE represents a virtual
14229 table, then return the type of the concrete object that is
14230 associated with the virtual table. Otherwise, return NULL. */
14232 static struct type
*
14233 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14235 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14239 /* Find the type DIE. */
14240 struct die_info
*type_die
= NULL
;
14241 struct dwarf2_cu
*type_cu
= cu
;
14243 if (attr_form_is_ref (attr
))
14244 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14245 if (type_die
== NULL
)
14248 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14250 return die_containing_type (type_die
, type_cu
);
14253 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14256 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14258 struct rust_vtable_symbol
*storage
= NULL
;
14260 if (cu
->language
== language_rust
)
14262 struct type
*containing_type
= rust_containing_type (die
, cu
);
14264 if (containing_type
!= NULL
)
14266 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14268 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14269 struct rust_vtable_symbol
);
14270 initialize_objfile_symbol (storage
);
14271 storage
->concrete_type
= containing_type
;
14272 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14276 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14277 struct attribute
*abstract_origin
14278 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14279 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14280 if (res
== NULL
&& loc
&& abstract_origin
)
14282 /* We have a variable without a name, but with a location and an abstract
14283 origin. This may be a concrete instance of an abstract variable
14284 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14286 struct dwarf2_cu
*origin_cu
= cu
;
14287 struct die_info
*origin_die
14288 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14289 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14290 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
14294 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14295 reading .debug_rnglists.
14296 Callback's type should be:
14297 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14298 Return true if the attributes are present and valid, otherwise,
14301 template <typename Callback
>
14303 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14304 Callback
&&callback
)
14306 struct dwarf2_per_objfile
*dwarf2_per_objfile
14307 = cu
->per_cu
->dwarf2_per_objfile
;
14308 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14309 bfd
*obfd
= objfile
->obfd
;
14310 /* Base address selection entry. */
14313 const gdb_byte
*buffer
;
14314 CORE_ADDR baseaddr
;
14315 bool overflow
= false;
14317 found_base
= cu
->base_known
;
14318 base
= cu
->base_address
;
14320 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14321 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14323 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14327 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14329 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14333 /* Initialize it due to a false compiler warning. */
14334 CORE_ADDR range_beginning
= 0, range_end
= 0;
14335 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14336 + dwarf2_per_objfile
->rnglists
.size
);
14337 unsigned int bytes_read
;
14339 if (buffer
== buf_end
)
14344 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14347 case DW_RLE_end_of_list
:
14349 case DW_RLE_base_address
:
14350 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14355 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14357 buffer
+= bytes_read
;
14359 case DW_RLE_start_length
:
14360 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14365 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14366 buffer
+= bytes_read
;
14367 range_end
= (range_beginning
14368 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14369 buffer
+= bytes_read
;
14370 if (buffer
> buf_end
)
14376 case DW_RLE_offset_pair
:
14377 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14378 buffer
+= bytes_read
;
14379 if (buffer
> buf_end
)
14384 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14385 buffer
+= bytes_read
;
14386 if (buffer
> buf_end
)
14392 case DW_RLE_start_end
:
14393 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14398 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14399 buffer
+= bytes_read
;
14400 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14401 buffer
+= bytes_read
;
14404 complaint (_("Invalid .debug_rnglists data (no base address)"));
14407 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14409 if (rlet
== DW_RLE_base_address
)
14414 /* We have no valid base address for the ranges
14416 complaint (_("Invalid .debug_rnglists data (no base address)"));
14420 if (range_beginning
> range_end
)
14422 /* Inverted range entries are invalid. */
14423 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14427 /* Empty range entries have no effect. */
14428 if (range_beginning
== range_end
)
14431 range_beginning
+= base
;
14434 /* A not-uncommon case of bad debug info.
14435 Don't pollute the addrmap with bad data. */
14436 if (range_beginning
+ baseaddr
== 0
14437 && !dwarf2_per_objfile
->has_section_at_zero
)
14439 complaint (_(".debug_rnglists entry has start address of zero"
14440 " [in module %s]"), objfile_name (objfile
));
14444 callback (range_beginning
, range_end
);
14449 complaint (_("Offset %d is not terminated "
14450 "for DW_AT_ranges attribute"),
14458 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14459 Callback's type should be:
14460 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14461 Return 1 if the attributes are present and valid, otherwise, return 0. */
14463 template <typename Callback
>
14465 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14466 Callback
&&callback
)
14468 struct dwarf2_per_objfile
*dwarf2_per_objfile
14469 = cu
->per_cu
->dwarf2_per_objfile
;
14470 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14471 struct comp_unit_head
*cu_header
= &cu
->header
;
14472 bfd
*obfd
= objfile
->obfd
;
14473 unsigned int addr_size
= cu_header
->addr_size
;
14474 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14475 /* Base address selection entry. */
14478 unsigned int dummy
;
14479 const gdb_byte
*buffer
;
14480 CORE_ADDR baseaddr
;
14482 if (cu_header
->version
>= 5)
14483 return dwarf2_rnglists_process (offset
, cu
, callback
);
14485 found_base
= cu
->base_known
;
14486 base
= cu
->base_address
;
14488 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14489 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14491 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14495 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14497 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14501 CORE_ADDR range_beginning
, range_end
;
14503 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14504 buffer
+= addr_size
;
14505 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14506 buffer
+= addr_size
;
14507 offset
+= 2 * addr_size
;
14509 /* An end of list marker is a pair of zero addresses. */
14510 if (range_beginning
== 0 && range_end
== 0)
14511 /* Found the end of list entry. */
14514 /* Each base address selection entry is a pair of 2 values.
14515 The first is the largest possible address, the second is
14516 the base address. Check for a base address here. */
14517 if ((range_beginning
& mask
) == mask
)
14519 /* If we found the largest possible address, then we already
14520 have the base address in range_end. */
14528 /* We have no valid base address for the ranges
14530 complaint (_("Invalid .debug_ranges data (no base address)"));
14534 if (range_beginning
> range_end
)
14536 /* Inverted range entries are invalid. */
14537 complaint (_("Invalid .debug_ranges data (inverted range)"));
14541 /* Empty range entries have no effect. */
14542 if (range_beginning
== range_end
)
14545 range_beginning
+= base
;
14548 /* A not-uncommon case of bad debug info.
14549 Don't pollute the addrmap with bad data. */
14550 if (range_beginning
+ baseaddr
== 0
14551 && !dwarf2_per_objfile
->has_section_at_zero
)
14553 complaint (_(".debug_ranges entry has start address of zero"
14554 " [in module %s]"), objfile_name (objfile
));
14558 callback (range_beginning
, range_end
);
14564 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14565 Return 1 if the attributes are present and valid, otherwise, return 0.
14566 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14569 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14570 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14571 struct partial_symtab
*ranges_pst
)
14573 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14574 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14575 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14576 SECT_OFF_TEXT (objfile
));
14579 CORE_ADDR high
= 0;
14582 retval
= dwarf2_ranges_process (offset
, cu
,
14583 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14585 if (ranges_pst
!= NULL
)
14590 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14591 range_beginning
+ baseaddr
)
14593 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14594 range_end
+ baseaddr
)
14596 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14597 lowpc
, highpc
- 1, ranges_pst
);
14600 /* FIXME: This is recording everything as a low-high
14601 segment of consecutive addresses. We should have a
14602 data structure for discontiguous block ranges
14606 low
= range_beginning
;
14612 if (range_beginning
< low
)
14613 low
= range_beginning
;
14614 if (range_end
> high
)
14622 /* If the first entry is an end-of-list marker, the range
14623 describes an empty scope, i.e. no instructions. */
14629 *high_return
= high
;
14633 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14634 definition for the return value. *LOWPC and *HIGHPC are set iff
14635 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14637 static enum pc_bounds_kind
14638 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14639 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14640 struct partial_symtab
*pst
)
14642 struct dwarf2_per_objfile
*dwarf2_per_objfile
14643 = cu
->per_cu
->dwarf2_per_objfile
;
14644 struct attribute
*attr
;
14645 struct attribute
*attr_high
;
14647 CORE_ADDR high
= 0;
14648 enum pc_bounds_kind ret
;
14650 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14653 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14656 low
= attr_value_as_address (attr
);
14657 high
= attr_value_as_address (attr_high
);
14658 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14662 /* Found high w/o low attribute. */
14663 return PC_BOUNDS_INVALID
;
14665 /* Found consecutive range of addresses. */
14666 ret
= PC_BOUNDS_HIGH_LOW
;
14670 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14673 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14674 We take advantage of the fact that DW_AT_ranges does not appear
14675 in DW_TAG_compile_unit of DWO files. */
14676 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14677 unsigned int ranges_offset
= (DW_UNSND (attr
)
14678 + (need_ranges_base
14682 /* Value of the DW_AT_ranges attribute is the offset in the
14683 .debug_ranges section. */
14684 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14685 return PC_BOUNDS_INVALID
;
14686 /* Found discontinuous range of addresses. */
14687 ret
= PC_BOUNDS_RANGES
;
14690 return PC_BOUNDS_NOT_PRESENT
;
14693 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14695 return PC_BOUNDS_INVALID
;
14697 /* When using the GNU linker, .gnu.linkonce. sections are used to
14698 eliminate duplicate copies of functions and vtables and such.
14699 The linker will arbitrarily choose one and discard the others.
14700 The AT_*_pc values for such functions refer to local labels in
14701 these sections. If the section from that file was discarded, the
14702 labels are not in the output, so the relocs get a value of 0.
14703 If this is a discarded function, mark the pc bounds as invalid,
14704 so that GDB will ignore it. */
14705 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14706 return PC_BOUNDS_INVALID
;
14714 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14715 its low and high PC addresses. Do nothing if these addresses could not
14716 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14717 and HIGHPC to the high address if greater than HIGHPC. */
14720 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14721 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14722 struct dwarf2_cu
*cu
)
14724 CORE_ADDR low
, high
;
14725 struct die_info
*child
= die
->child
;
14727 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14729 *lowpc
= std::min (*lowpc
, low
);
14730 *highpc
= std::max (*highpc
, high
);
14733 /* If the language does not allow nested subprograms (either inside
14734 subprograms or lexical blocks), we're done. */
14735 if (cu
->language
!= language_ada
)
14738 /* Check all the children of the given DIE. If it contains nested
14739 subprograms, then check their pc bounds. Likewise, we need to
14740 check lexical blocks as well, as they may also contain subprogram
14742 while (child
&& child
->tag
)
14744 if (child
->tag
== DW_TAG_subprogram
14745 || child
->tag
== DW_TAG_lexical_block
)
14746 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14747 child
= sibling_die (child
);
14751 /* Get the low and high pc's represented by the scope DIE, and store
14752 them in *LOWPC and *HIGHPC. If the correct values can't be
14753 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14756 get_scope_pc_bounds (struct die_info
*die
,
14757 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14758 struct dwarf2_cu
*cu
)
14760 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14761 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14762 CORE_ADDR current_low
, current_high
;
14764 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14765 >= PC_BOUNDS_RANGES
)
14767 best_low
= current_low
;
14768 best_high
= current_high
;
14772 struct die_info
*child
= die
->child
;
14774 while (child
&& child
->tag
)
14776 switch (child
->tag
) {
14777 case DW_TAG_subprogram
:
14778 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14780 case DW_TAG_namespace
:
14781 case DW_TAG_module
:
14782 /* FIXME: carlton/2004-01-16: Should we do this for
14783 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14784 that current GCC's always emit the DIEs corresponding
14785 to definitions of methods of classes as children of a
14786 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14787 the DIEs giving the declarations, which could be
14788 anywhere). But I don't see any reason why the
14789 standards says that they have to be there. */
14790 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14792 if (current_low
!= ((CORE_ADDR
) -1))
14794 best_low
= std::min (best_low
, current_low
);
14795 best_high
= std::max (best_high
, current_high
);
14803 child
= sibling_die (child
);
14808 *highpc
= best_high
;
14811 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14815 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14816 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14818 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14819 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14820 struct attribute
*attr
;
14821 struct attribute
*attr_high
;
14823 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14826 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14829 CORE_ADDR low
= attr_value_as_address (attr
);
14830 CORE_ADDR high
= attr_value_as_address (attr_high
);
14832 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14835 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14836 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14837 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14841 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14844 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14845 We take advantage of the fact that DW_AT_ranges does not appear
14846 in DW_TAG_compile_unit of DWO files. */
14847 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14849 /* The value of the DW_AT_ranges attribute is the offset of the
14850 address range list in the .debug_ranges section. */
14851 unsigned long offset
= (DW_UNSND (attr
)
14852 + (need_ranges_base
? cu
->ranges_base
: 0));
14854 std::vector
<blockrange
> blockvec
;
14855 dwarf2_ranges_process (offset
, cu
,
14856 [&] (CORE_ADDR start
, CORE_ADDR end
)
14860 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14861 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14862 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14863 blockvec
.emplace_back (start
, end
);
14866 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14870 /* Check whether the producer field indicates either of GCC < 4.6, or the
14871 Intel C/C++ compiler, and cache the result in CU. */
14874 check_producer (struct dwarf2_cu
*cu
)
14878 if (cu
->producer
== NULL
)
14880 /* For unknown compilers expect their behavior is DWARF version
14883 GCC started to support .debug_types sections by -gdwarf-4 since
14884 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14885 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14886 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14887 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14889 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14891 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14892 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14894 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14896 cu
->producer_is_icc
= true;
14897 cu
->producer_is_icc_lt_14
= major
< 14;
14899 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14900 cu
->producer_is_codewarrior
= true;
14903 /* For other non-GCC compilers, expect their behavior is DWARF version
14907 cu
->checked_producer
= true;
14910 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14911 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14912 during 4.6.0 experimental. */
14915 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14917 if (!cu
->checked_producer
)
14918 check_producer (cu
);
14920 return cu
->producer_is_gxx_lt_4_6
;
14924 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14925 with incorrect is_stmt attributes. */
14928 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14930 if (!cu
->checked_producer
)
14931 check_producer (cu
);
14933 return cu
->producer_is_codewarrior
;
14936 /* Return the default accessibility type if it is not overriden by
14937 DW_AT_accessibility. */
14939 static enum dwarf_access_attribute
14940 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14942 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14944 /* The default DWARF 2 accessibility for members is public, the default
14945 accessibility for inheritance is private. */
14947 if (die
->tag
!= DW_TAG_inheritance
)
14948 return DW_ACCESS_public
;
14950 return DW_ACCESS_private
;
14954 /* DWARF 3+ defines the default accessibility a different way. The same
14955 rules apply now for DW_TAG_inheritance as for the members and it only
14956 depends on the container kind. */
14958 if (die
->parent
->tag
== DW_TAG_class_type
)
14959 return DW_ACCESS_private
;
14961 return DW_ACCESS_public
;
14965 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14966 offset. If the attribute was not found return 0, otherwise return
14967 1. If it was found but could not properly be handled, set *OFFSET
14971 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14974 struct attribute
*attr
;
14976 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14981 /* Note that we do not check for a section offset first here.
14982 This is because DW_AT_data_member_location is new in DWARF 4,
14983 so if we see it, we can assume that a constant form is really
14984 a constant and not a section offset. */
14985 if (attr_form_is_constant (attr
))
14986 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14987 else if (attr_form_is_section_offset (attr
))
14988 dwarf2_complex_location_expr_complaint ();
14989 else if (attr_form_is_block (attr
))
14990 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14992 dwarf2_complex_location_expr_complaint ();
15000 /* Add an aggregate field to the field list. */
15003 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15004 struct dwarf2_cu
*cu
)
15006 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15007 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15008 struct nextfield
*new_field
;
15009 struct attribute
*attr
;
15011 const char *fieldname
= "";
15013 if (die
->tag
== DW_TAG_inheritance
)
15015 fip
->baseclasses
.emplace_back ();
15016 new_field
= &fip
->baseclasses
.back ();
15020 fip
->fields
.emplace_back ();
15021 new_field
= &fip
->fields
.back ();
15026 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15028 new_field
->accessibility
= DW_UNSND (attr
);
15030 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15031 if (new_field
->accessibility
!= DW_ACCESS_public
)
15032 fip
->non_public_fields
= 1;
15034 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15036 new_field
->virtuality
= DW_UNSND (attr
);
15038 new_field
->virtuality
= DW_VIRTUALITY_none
;
15040 fp
= &new_field
->field
;
15042 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15046 /* Data member other than a C++ static data member. */
15048 /* Get type of field. */
15049 fp
->type
= die_type (die
, cu
);
15051 SET_FIELD_BITPOS (*fp
, 0);
15053 /* Get bit size of field (zero if none). */
15054 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15057 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15061 FIELD_BITSIZE (*fp
) = 0;
15064 /* Get bit offset of field. */
15065 if (handle_data_member_location (die
, cu
, &offset
))
15066 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15067 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15070 if (gdbarch_bits_big_endian (gdbarch
))
15072 /* For big endian bits, the DW_AT_bit_offset gives the
15073 additional bit offset from the MSB of the containing
15074 anonymous object to the MSB of the field. We don't
15075 have to do anything special since we don't need to
15076 know the size of the anonymous object. */
15077 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15081 /* For little endian bits, compute the bit offset to the
15082 MSB of the anonymous object, subtract off the number of
15083 bits from the MSB of the field to the MSB of the
15084 object, and then subtract off the number of bits of
15085 the field itself. The result is the bit offset of
15086 the LSB of the field. */
15087 int anonymous_size
;
15088 int bit_offset
= DW_UNSND (attr
);
15090 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15093 /* The size of the anonymous object containing
15094 the bit field is explicit, so use the
15095 indicated size (in bytes). */
15096 anonymous_size
= DW_UNSND (attr
);
15100 /* The size of the anonymous object containing
15101 the bit field must be inferred from the type
15102 attribute of the data member containing the
15104 anonymous_size
= TYPE_LENGTH (fp
->type
);
15106 SET_FIELD_BITPOS (*fp
,
15107 (FIELD_BITPOS (*fp
)
15108 + anonymous_size
* bits_per_byte
15109 - bit_offset
- FIELD_BITSIZE (*fp
)));
15112 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15114 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15115 + dwarf2_get_attr_constant_value (attr
, 0)));
15117 /* Get name of field. */
15118 fieldname
= dwarf2_name (die
, cu
);
15119 if (fieldname
== NULL
)
15122 /* The name is already allocated along with this objfile, so we don't
15123 need to duplicate it for the type. */
15124 fp
->name
= fieldname
;
15126 /* Change accessibility for artificial fields (e.g. virtual table
15127 pointer or virtual base class pointer) to private. */
15128 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15130 FIELD_ARTIFICIAL (*fp
) = 1;
15131 new_field
->accessibility
= DW_ACCESS_private
;
15132 fip
->non_public_fields
= 1;
15135 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15137 /* C++ static member. */
15139 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15140 is a declaration, but all versions of G++ as of this writing
15141 (so through at least 3.2.1) incorrectly generate
15142 DW_TAG_variable tags. */
15144 const char *physname
;
15146 /* Get name of field. */
15147 fieldname
= dwarf2_name (die
, cu
);
15148 if (fieldname
== NULL
)
15151 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15153 /* Only create a symbol if this is an external value.
15154 new_symbol checks this and puts the value in the global symbol
15155 table, which we want. If it is not external, new_symbol
15156 will try to put the value in cu->list_in_scope which is wrong. */
15157 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15159 /* A static const member, not much different than an enum as far as
15160 we're concerned, except that we can support more types. */
15161 new_symbol (die
, NULL
, cu
);
15164 /* Get physical name. */
15165 physname
= dwarf2_physname (fieldname
, die
, cu
);
15167 /* The name is already allocated along with this objfile, so we don't
15168 need to duplicate it for the type. */
15169 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15170 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15171 FIELD_NAME (*fp
) = fieldname
;
15173 else if (die
->tag
== DW_TAG_inheritance
)
15177 /* C++ base class field. */
15178 if (handle_data_member_location (die
, cu
, &offset
))
15179 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15180 FIELD_BITSIZE (*fp
) = 0;
15181 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15182 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
15184 else if (die
->tag
== DW_TAG_variant_part
)
15186 /* process_structure_scope will treat this DIE as a union. */
15187 process_structure_scope (die
, cu
);
15189 /* The variant part is relative to the start of the enclosing
15191 SET_FIELD_BITPOS (*fp
, 0);
15192 fp
->type
= get_die_type (die
, cu
);
15193 fp
->artificial
= 1;
15194 fp
->name
= "<<variant>>";
15196 /* Normally a DW_TAG_variant_part won't have a size, but our
15197 representation requires one, so set it to the maximum of the
15199 if (TYPE_LENGTH (fp
->type
) == 0)
15202 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
15203 if (TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)) > max
)
15204 max
= TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
));
15205 TYPE_LENGTH (fp
->type
) = max
;
15209 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15212 /* Can the type given by DIE define another type? */
15215 type_can_define_types (const struct die_info
*die
)
15219 case DW_TAG_typedef
:
15220 case DW_TAG_class_type
:
15221 case DW_TAG_structure_type
:
15222 case DW_TAG_union_type
:
15223 case DW_TAG_enumeration_type
:
15231 /* Add a type definition defined in the scope of the FIP's class. */
15234 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15235 struct dwarf2_cu
*cu
)
15237 struct decl_field fp
;
15238 memset (&fp
, 0, sizeof (fp
));
15240 gdb_assert (type_can_define_types (die
));
15242 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15243 fp
.name
= dwarf2_name (die
, cu
);
15244 fp
.type
= read_type_die (die
, cu
);
15246 /* Save accessibility. */
15247 enum dwarf_access_attribute accessibility
;
15248 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15250 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15252 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15253 switch (accessibility
)
15255 case DW_ACCESS_public
:
15256 /* The assumed value if neither private nor protected. */
15258 case DW_ACCESS_private
:
15261 case DW_ACCESS_protected
:
15262 fp
.is_protected
= 1;
15265 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15268 if (die
->tag
== DW_TAG_typedef
)
15269 fip
->typedef_field_list
.push_back (fp
);
15271 fip
->nested_types_list
.push_back (fp
);
15274 /* Create the vector of fields, and attach it to the type. */
15277 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15278 struct dwarf2_cu
*cu
)
15280 int nfields
= fip
->nfields
;
15282 /* Record the field count, allocate space for the array of fields,
15283 and create blank accessibility bitfields if necessary. */
15284 TYPE_NFIELDS (type
) = nfields
;
15285 TYPE_FIELDS (type
) = (struct field
*)
15286 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15288 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15290 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15292 TYPE_FIELD_PRIVATE_BITS (type
) =
15293 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15294 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15296 TYPE_FIELD_PROTECTED_BITS (type
) =
15297 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15298 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15300 TYPE_FIELD_IGNORE_BITS (type
) =
15301 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15302 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15305 /* If the type has baseclasses, allocate and clear a bit vector for
15306 TYPE_FIELD_VIRTUAL_BITS. */
15307 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15309 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15310 unsigned char *pointer
;
15312 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15313 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15314 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15315 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15316 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15319 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15321 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15323 for (int index
= 0; index
< nfields
; ++index
)
15325 struct nextfield
&field
= fip
->fields
[index
];
15327 if (field
.variant
.is_discriminant
)
15328 di
->discriminant_index
= index
;
15329 else if (field
.variant
.default_branch
)
15330 di
->default_index
= index
;
15332 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15336 /* Copy the saved-up fields into the field vector. */
15337 for (int i
= 0; i
< nfields
; ++i
)
15339 struct nextfield
&field
15340 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15341 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15343 TYPE_FIELD (type
, i
) = field
.field
;
15344 switch (field
.accessibility
)
15346 case DW_ACCESS_private
:
15347 if (cu
->language
!= language_ada
)
15348 SET_TYPE_FIELD_PRIVATE (type
, i
);
15351 case DW_ACCESS_protected
:
15352 if (cu
->language
!= language_ada
)
15353 SET_TYPE_FIELD_PROTECTED (type
, i
);
15356 case DW_ACCESS_public
:
15360 /* Unknown accessibility. Complain and treat it as public. */
15362 complaint (_("unsupported accessibility %d"),
15363 field
.accessibility
);
15367 if (i
< fip
->baseclasses
.size ())
15369 switch (field
.virtuality
)
15371 case DW_VIRTUALITY_virtual
:
15372 case DW_VIRTUALITY_pure_virtual
:
15373 if (cu
->language
== language_ada
)
15374 error (_("unexpected virtuality in component of Ada type"));
15375 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15382 /* Return true if this member function is a constructor, false
15386 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15388 const char *fieldname
;
15389 const char *type_name
;
15392 if (die
->parent
== NULL
)
15395 if (die
->parent
->tag
!= DW_TAG_structure_type
15396 && die
->parent
->tag
!= DW_TAG_union_type
15397 && die
->parent
->tag
!= DW_TAG_class_type
)
15400 fieldname
= dwarf2_name (die
, cu
);
15401 type_name
= dwarf2_name (die
->parent
, cu
);
15402 if (fieldname
== NULL
|| type_name
== NULL
)
15405 len
= strlen (fieldname
);
15406 return (strncmp (fieldname
, type_name
, len
) == 0
15407 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15410 /* Add a member function to the proper fieldlist. */
15413 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15414 struct type
*type
, struct dwarf2_cu
*cu
)
15416 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15417 struct attribute
*attr
;
15419 struct fnfieldlist
*flp
= nullptr;
15420 struct fn_field
*fnp
;
15421 const char *fieldname
;
15422 struct type
*this_type
;
15423 enum dwarf_access_attribute accessibility
;
15425 if (cu
->language
== language_ada
)
15426 error (_("unexpected member function in Ada type"));
15428 /* Get name of member function. */
15429 fieldname
= dwarf2_name (die
, cu
);
15430 if (fieldname
== NULL
)
15433 /* Look up member function name in fieldlist. */
15434 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15436 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15438 flp
= &fip
->fnfieldlists
[i
];
15443 /* Create a new fnfieldlist if necessary. */
15444 if (flp
== nullptr)
15446 fip
->fnfieldlists
.emplace_back ();
15447 flp
= &fip
->fnfieldlists
.back ();
15448 flp
->name
= fieldname
;
15449 i
= fip
->fnfieldlists
.size () - 1;
15452 /* Create a new member function field and add it to the vector of
15454 flp
->fnfields
.emplace_back ();
15455 fnp
= &flp
->fnfields
.back ();
15457 /* Delay processing of the physname until later. */
15458 if (cu
->language
== language_cplus
)
15459 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15463 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15464 fnp
->physname
= physname
? physname
: "";
15467 fnp
->type
= alloc_type (objfile
);
15468 this_type
= read_type_die (die
, cu
);
15469 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15471 int nparams
= TYPE_NFIELDS (this_type
);
15473 /* TYPE is the domain of this method, and THIS_TYPE is the type
15474 of the method itself (TYPE_CODE_METHOD). */
15475 smash_to_method_type (fnp
->type
, type
,
15476 TYPE_TARGET_TYPE (this_type
),
15477 TYPE_FIELDS (this_type
),
15478 TYPE_NFIELDS (this_type
),
15479 TYPE_VARARGS (this_type
));
15481 /* Handle static member functions.
15482 Dwarf2 has no clean way to discern C++ static and non-static
15483 member functions. G++ helps GDB by marking the first
15484 parameter for non-static member functions (which is the this
15485 pointer) as artificial. We obtain this information from
15486 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15487 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15488 fnp
->voffset
= VOFFSET_STATIC
;
15491 complaint (_("member function type missing for '%s'"),
15492 dwarf2_full_name (fieldname
, die
, cu
));
15494 /* Get fcontext from DW_AT_containing_type if present. */
15495 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15496 fnp
->fcontext
= die_containing_type (die
, cu
);
15498 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15499 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15501 /* Get accessibility. */
15502 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15504 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15506 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15507 switch (accessibility
)
15509 case DW_ACCESS_private
:
15510 fnp
->is_private
= 1;
15512 case DW_ACCESS_protected
:
15513 fnp
->is_protected
= 1;
15517 /* Check for artificial methods. */
15518 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15519 if (attr
&& DW_UNSND (attr
) != 0)
15520 fnp
->is_artificial
= 1;
15522 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15524 /* Get index in virtual function table if it is a virtual member
15525 function. For older versions of GCC, this is an offset in the
15526 appropriate virtual table, as specified by DW_AT_containing_type.
15527 For everyone else, it is an expression to be evaluated relative
15528 to the object address. */
15530 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15533 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15535 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15537 /* Old-style GCC. */
15538 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15540 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15541 || (DW_BLOCK (attr
)->size
> 1
15542 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15543 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15545 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15546 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15547 dwarf2_complex_location_expr_complaint ();
15549 fnp
->voffset
/= cu
->header
.addr_size
;
15553 dwarf2_complex_location_expr_complaint ();
15555 if (!fnp
->fcontext
)
15557 /* If there is no `this' field and no DW_AT_containing_type,
15558 we cannot actually find a base class context for the
15560 if (TYPE_NFIELDS (this_type
) == 0
15561 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15563 complaint (_("cannot determine context for virtual member "
15564 "function \"%s\" (offset %s)"),
15565 fieldname
, sect_offset_str (die
->sect_off
));
15570 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15574 else if (attr_form_is_section_offset (attr
))
15576 dwarf2_complex_location_expr_complaint ();
15580 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15586 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15587 if (attr
&& DW_UNSND (attr
))
15589 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15590 complaint (_("Member function \"%s\" (offset %s) is virtual "
15591 "but the vtable offset is not specified"),
15592 fieldname
, sect_offset_str (die
->sect_off
));
15593 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15594 TYPE_CPLUS_DYNAMIC (type
) = 1;
15599 /* Create the vector of member function fields, and attach it to the type. */
15602 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15603 struct dwarf2_cu
*cu
)
15605 if (cu
->language
== language_ada
)
15606 error (_("unexpected member functions in Ada type"));
15608 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15609 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15611 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15613 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15615 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15616 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15618 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15619 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15620 fn_flp
->fn_fields
= (struct fn_field
*)
15621 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15623 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15624 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15627 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15630 /* Returns non-zero if NAME is the name of a vtable member in CU's
15631 language, zero otherwise. */
15633 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15635 static const char vptr
[] = "_vptr";
15637 /* Look for the C++ form of the vtable. */
15638 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15644 /* GCC outputs unnamed structures that are really pointers to member
15645 functions, with the ABI-specified layout. If TYPE describes
15646 such a structure, smash it into a member function type.
15648 GCC shouldn't do this; it should just output pointer to member DIEs.
15649 This is GCC PR debug/28767. */
15652 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15654 struct type
*pfn_type
, *self_type
, *new_type
;
15656 /* Check for a structure with no name and two children. */
15657 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15660 /* Check for __pfn and __delta members. */
15661 if (TYPE_FIELD_NAME (type
, 0) == NULL
15662 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15663 || TYPE_FIELD_NAME (type
, 1) == NULL
15664 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15667 /* Find the type of the method. */
15668 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15669 if (pfn_type
== NULL
15670 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15671 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15674 /* Look for the "this" argument. */
15675 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15676 if (TYPE_NFIELDS (pfn_type
) == 0
15677 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15678 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15681 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15682 new_type
= alloc_type (objfile
);
15683 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15684 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15685 TYPE_VARARGS (pfn_type
));
15686 smash_to_methodptr_type (type
, new_type
);
15689 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15690 appropriate error checking and issuing complaints if there is a
15694 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15696 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15698 if (attr
== nullptr)
15701 if (!attr_form_is_constant (attr
))
15703 complaint (_("DW_AT_alignment must have constant form"
15704 " - DIE at %s [in module %s]"),
15705 sect_offset_str (die
->sect_off
),
15706 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15711 if (attr
->form
== DW_FORM_sdata
)
15713 LONGEST val
= DW_SND (attr
);
15716 complaint (_("DW_AT_alignment value must not be negative"
15717 " - DIE at %s [in module %s]"),
15718 sect_offset_str (die
->sect_off
),
15719 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15725 align
= DW_UNSND (attr
);
15729 complaint (_("DW_AT_alignment value must not be zero"
15730 " - DIE at %s [in module %s]"),
15731 sect_offset_str (die
->sect_off
),
15732 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15735 if ((align
& (align
- 1)) != 0)
15737 complaint (_("DW_AT_alignment value must be a power of 2"
15738 " - DIE at %s [in module %s]"),
15739 sect_offset_str (die
->sect_off
),
15740 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15747 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15748 the alignment for TYPE. */
15751 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15754 if (!set_type_align (type
, get_alignment (cu
, die
)))
15755 complaint (_("DW_AT_alignment value too large"
15756 " - DIE at %s [in module %s]"),
15757 sect_offset_str (die
->sect_off
),
15758 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15761 /* Called when we find the DIE that starts a structure or union scope
15762 (definition) to create a type for the structure or union. Fill in
15763 the type's name and general properties; the members will not be
15764 processed until process_structure_scope. A symbol table entry for
15765 the type will also not be done until process_structure_scope (assuming
15766 the type has a name).
15768 NOTE: we need to call these functions regardless of whether or not the
15769 DIE has a DW_AT_name attribute, since it might be an anonymous
15770 structure or union. This gets the type entered into our set of
15771 user defined types. */
15773 static struct type
*
15774 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15776 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15778 struct attribute
*attr
;
15781 /* If the definition of this type lives in .debug_types, read that type.
15782 Don't follow DW_AT_specification though, that will take us back up
15783 the chain and we want to go down. */
15784 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15787 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15789 /* The type's CU may not be the same as CU.
15790 Ensure TYPE is recorded with CU in die_type_hash. */
15791 return set_die_type (die
, type
, cu
);
15794 type
= alloc_type (objfile
);
15795 INIT_CPLUS_SPECIFIC (type
);
15797 name
= dwarf2_name (die
, cu
);
15800 if (cu
->language
== language_cplus
15801 || cu
->language
== language_d
15802 || cu
->language
== language_rust
)
15804 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15806 /* dwarf2_full_name might have already finished building the DIE's
15807 type. If so, there is no need to continue. */
15808 if (get_die_type (die
, cu
) != NULL
)
15809 return get_die_type (die
, cu
);
15811 TYPE_NAME (type
) = full_name
;
15815 /* The name is already allocated along with this objfile, so
15816 we don't need to duplicate it for the type. */
15817 TYPE_NAME (type
) = name
;
15821 if (die
->tag
== DW_TAG_structure_type
)
15823 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15825 else if (die
->tag
== DW_TAG_union_type
)
15827 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15829 else if (die
->tag
== DW_TAG_variant_part
)
15831 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15832 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15836 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15839 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15840 TYPE_DECLARED_CLASS (type
) = 1;
15842 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15845 if (attr_form_is_constant (attr
))
15846 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15849 /* For the moment, dynamic type sizes are not supported
15850 by GDB's struct type. The actual size is determined
15851 on-demand when resolving the type of a given object,
15852 so set the type's length to zero for now. Otherwise,
15853 we record an expression as the length, and that expression
15854 could lead to a very large value, which could eventually
15855 lead to us trying to allocate that much memory when creating
15856 a value of that type. */
15857 TYPE_LENGTH (type
) = 0;
15862 TYPE_LENGTH (type
) = 0;
15865 maybe_set_alignment (cu
, die
, type
);
15867 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15869 /* ICC<14 does not output the required DW_AT_declaration on
15870 incomplete types, but gives them a size of zero. */
15871 TYPE_STUB (type
) = 1;
15874 TYPE_STUB_SUPPORTED (type
) = 1;
15876 if (die_is_declaration (die
, cu
))
15877 TYPE_STUB (type
) = 1;
15878 else if (attr
== NULL
&& die
->child
== NULL
15879 && producer_is_realview (cu
->producer
))
15880 /* RealView does not output the required DW_AT_declaration
15881 on incomplete types. */
15882 TYPE_STUB (type
) = 1;
15884 /* We need to add the type field to the die immediately so we don't
15885 infinitely recurse when dealing with pointers to the structure
15886 type within the structure itself. */
15887 set_die_type (die
, type
, cu
);
15889 /* set_die_type should be already done. */
15890 set_descriptive_type (type
, die
, cu
);
15895 /* A helper for process_structure_scope that handles a single member
15899 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15900 struct field_info
*fi
,
15901 std::vector
<struct symbol
*> *template_args
,
15902 struct dwarf2_cu
*cu
)
15904 if (child_die
->tag
== DW_TAG_member
15905 || child_die
->tag
== DW_TAG_variable
15906 || child_die
->tag
== DW_TAG_variant_part
)
15908 /* NOTE: carlton/2002-11-05: A C++ static data member
15909 should be a DW_TAG_member that is a declaration, but
15910 all versions of G++ as of this writing (so through at
15911 least 3.2.1) incorrectly generate DW_TAG_variable
15912 tags for them instead. */
15913 dwarf2_add_field (fi
, child_die
, cu
);
15915 else if (child_die
->tag
== DW_TAG_subprogram
)
15917 /* Rust doesn't have member functions in the C++ sense.
15918 However, it does emit ordinary functions as children
15919 of a struct DIE. */
15920 if (cu
->language
== language_rust
)
15921 read_func_scope (child_die
, cu
);
15924 /* C++ member function. */
15925 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15928 else if (child_die
->tag
== DW_TAG_inheritance
)
15930 /* C++ base class field. */
15931 dwarf2_add_field (fi
, child_die
, cu
);
15933 else if (type_can_define_types (child_die
))
15934 dwarf2_add_type_defn (fi
, child_die
, cu
);
15935 else if (child_die
->tag
== DW_TAG_template_type_param
15936 || child_die
->tag
== DW_TAG_template_value_param
)
15938 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15941 template_args
->push_back (arg
);
15943 else if (child_die
->tag
== DW_TAG_variant
)
15945 /* In a variant we want to get the discriminant and also add a
15946 field for our sole member child. */
15947 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15949 for (die_info
*variant_child
= child_die
->child
;
15950 variant_child
!= NULL
;
15951 variant_child
= sibling_die (variant_child
))
15953 if (variant_child
->tag
== DW_TAG_member
)
15955 handle_struct_member_die (variant_child
, type
, fi
,
15956 template_args
, cu
);
15957 /* Only handle the one. */
15962 /* We don't handle this but we might as well report it if we see
15964 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15965 complaint (_("DW_AT_discr_list is not supported yet"
15966 " - DIE at %s [in module %s]"),
15967 sect_offset_str (child_die
->sect_off
),
15968 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15970 /* The first field was just added, so we can stash the
15971 discriminant there. */
15972 gdb_assert (!fi
->fields
.empty ());
15974 fi
->fields
.back ().variant
.default_branch
= true;
15976 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15980 /* Finish creating a structure or union type, including filling in
15981 its members and creating a symbol for it. */
15984 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15986 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15987 struct die_info
*child_die
;
15990 type
= get_die_type (die
, cu
);
15992 type
= read_structure_type (die
, cu
);
15994 /* When reading a DW_TAG_variant_part, we need to notice when we
15995 read the discriminant member, so we can record it later in the
15996 discriminant_info. */
15997 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15998 sect_offset discr_offset
;
15999 bool has_template_parameters
= false;
16001 if (is_variant_part
)
16003 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16006 /* Maybe it's a univariant form, an extension we support.
16007 In this case arrange not to check the offset. */
16008 is_variant_part
= false;
16010 else if (attr_form_is_ref (discr
))
16012 struct dwarf2_cu
*target_cu
= cu
;
16013 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16015 discr_offset
= target_die
->sect_off
;
16019 complaint (_("DW_AT_discr does not have DIE reference form"
16020 " - DIE at %s [in module %s]"),
16021 sect_offset_str (die
->sect_off
),
16022 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16023 is_variant_part
= false;
16027 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16029 struct field_info fi
;
16030 std::vector
<struct symbol
*> template_args
;
16032 child_die
= die
->child
;
16034 while (child_die
&& child_die
->tag
)
16036 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16038 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16039 fi
.fields
.back ().variant
.is_discriminant
= true;
16041 child_die
= sibling_die (child_die
);
16044 /* Attach template arguments to type. */
16045 if (!template_args
.empty ())
16047 has_template_parameters
= true;
16048 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16049 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16050 TYPE_TEMPLATE_ARGUMENTS (type
)
16051 = XOBNEWVEC (&objfile
->objfile_obstack
,
16053 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16054 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16055 template_args
.data (),
16056 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16057 * sizeof (struct symbol
*)));
16060 /* Attach fields and member functions to the type. */
16062 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16063 if (!fi
.fnfieldlists
.empty ())
16065 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16067 /* Get the type which refers to the base class (possibly this
16068 class itself) which contains the vtable pointer for the current
16069 class from the DW_AT_containing_type attribute. This use of
16070 DW_AT_containing_type is a GNU extension. */
16072 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16074 struct type
*t
= die_containing_type (die
, cu
);
16076 set_type_vptr_basetype (type
, t
);
16081 /* Our own class provides vtbl ptr. */
16082 for (i
= TYPE_NFIELDS (t
) - 1;
16083 i
>= TYPE_N_BASECLASSES (t
);
16086 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16088 if (is_vtable_name (fieldname
, cu
))
16090 set_type_vptr_fieldno (type
, i
);
16095 /* Complain if virtual function table field not found. */
16096 if (i
< TYPE_N_BASECLASSES (t
))
16097 complaint (_("virtual function table pointer "
16098 "not found when defining class '%s'"),
16099 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16103 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16106 else if (cu
->producer
16107 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16109 /* The IBM XLC compiler does not provide direct indication
16110 of the containing type, but the vtable pointer is
16111 always named __vfp. */
16115 for (i
= TYPE_NFIELDS (type
) - 1;
16116 i
>= TYPE_N_BASECLASSES (type
);
16119 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16121 set_type_vptr_fieldno (type
, i
);
16122 set_type_vptr_basetype (type
, type
);
16129 /* Copy fi.typedef_field_list linked list elements content into the
16130 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16131 if (!fi
.typedef_field_list
.empty ())
16133 int count
= fi
.typedef_field_list
.size ();
16135 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16136 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16137 = ((struct decl_field
*)
16139 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16140 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16142 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16143 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16146 /* Copy fi.nested_types_list linked list elements content into the
16147 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16148 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16150 int count
= fi
.nested_types_list
.size ();
16152 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16153 TYPE_NESTED_TYPES_ARRAY (type
)
16154 = ((struct decl_field
*)
16155 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16156 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16158 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16159 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16163 quirk_gcc_member_function_pointer (type
, objfile
);
16164 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16165 cu
->rust_unions
.push_back (type
);
16167 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16168 snapshots) has been known to create a die giving a declaration
16169 for a class that has, as a child, a die giving a definition for a
16170 nested class. So we have to process our children even if the
16171 current die is a declaration. Normally, of course, a declaration
16172 won't have any children at all. */
16174 child_die
= die
->child
;
16176 while (child_die
!= NULL
&& child_die
->tag
)
16178 if (child_die
->tag
== DW_TAG_member
16179 || child_die
->tag
== DW_TAG_variable
16180 || child_die
->tag
== DW_TAG_inheritance
16181 || child_die
->tag
== DW_TAG_template_value_param
16182 || child_die
->tag
== DW_TAG_template_type_param
)
16187 process_die (child_die
, cu
);
16189 child_die
= sibling_die (child_die
);
16192 /* Do not consider external references. According to the DWARF standard,
16193 these DIEs are identified by the fact that they have no byte_size
16194 attribute, and a declaration attribute. */
16195 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16196 || !die_is_declaration (die
, cu
))
16198 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16200 if (has_template_parameters
)
16202 struct symtab
*symtab
;
16203 if (sym
!= nullptr)
16204 symtab
= symbol_symtab (sym
);
16205 else if (cu
->line_header
!= nullptr)
16207 /* Any related symtab will do. */
16209 = cu
->line_header
->file_name_at (file_name_index (1))->symtab
;
16214 complaint (_("could not find suitable "
16215 "symtab for template parameter"
16216 " - DIE at %s [in module %s]"),
16217 sect_offset_str (die
->sect_off
),
16218 objfile_name (objfile
));
16221 if (symtab
!= nullptr)
16223 /* Make sure that the symtab is set on the new symbols.
16224 Even though they don't appear in this symtab directly,
16225 other parts of gdb assume that symbols do, and this is
16226 reasonably true. */
16227 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16228 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16234 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16235 update TYPE using some information only available in DIE's children. */
16238 update_enumeration_type_from_children (struct die_info
*die
,
16240 struct dwarf2_cu
*cu
)
16242 struct die_info
*child_die
;
16243 int unsigned_enum
= 1;
16247 auto_obstack obstack
;
16249 for (child_die
= die
->child
;
16250 child_die
!= NULL
&& child_die
->tag
;
16251 child_die
= sibling_die (child_die
))
16253 struct attribute
*attr
;
16255 const gdb_byte
*bytes
;
16256 struct dwarf2_locexpr_baton
*baton
;
16259 if (child_die
->tag
!= DW_TAG_enumerator
)
16262 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16266 name
= dwarf2_name (child_die
, cu
);
16268 name
= "<anonymous enumerator>";
16270 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16271 &value
, &bytes
, &baton
);
16277 else if ((mask
& value
) != 0)
16282 /* If we already know that the enum type is neither unsigned, nor
16283 a flag type, no need to look at the rest of the enumerates. */
16284 if (!unsigned_enum
&& !flag_enum
)
16289 TYPE_UNSIGNED (type
) = 1;
16291 TYPE_FLAG_ENUM (type
) = 1;
16294 /* Given a DW_AT_enumeration_type die, set its type. We do not
16295 complete the type's fields yet, or create any symbols. */
16297 static struct type
*
16298 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16300 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16302 struct attribute
*attr
;
16305 /* If the definition of this type lives in .debug_types, read that type.
16306 Don't follow DW_AT_specification though, that will take us back up
16307 the chain and we want to go down. */
16308 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16311 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16313 /* The type's CU may not be the same as CU.
16314 Ensure TYPE is recorded with CU in die_type_hash. */
16315 return set_die_type (die
, type
, cu
);
16318 type
= alloc_type (objfile
);
16320 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16321 name
= dwarf2_full_name (NULL
, die
, cu
);
16323 TYPE_NAME (type
) = name
;
16325 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16328 struct type
*underlying_type
= die_type (die
, cu
);
16330 TYPE_TARGET_TYPE (type
) = underlying_type
;
16333 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16336 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16340 TYPE_LENGTH (type
) = 0;
16343 maybe_set_alignment (cu
, die
, type
);
16345 /* The enumeration DIE can be incomplete. In Ada, any type can be
16346 declared as private in the package spec, and then defined only
16347 inside the package body. Such types are known as Taft Amendment
16348 Types. When another package uses such a type, an incomplete DIE
16349 may be generated by the compiler. */
16350 if (die_is_declaration (die
, cu
))
16351 TYPE_STUB (type
) = 1;
16353 /* Finish the creation of this type by using the enum's children.
16354 We must call this even when the underlying type has been provided
16355 so that we can determine if we're looking at a "flag" enum. */
16356 update_enumeration_type_from_children (die
, type
, cu
);
16358 /* If this type has an underlying type that is not a stub, then we
16359 may use its attributes. We always use the "unsigned" attribute
16360 in this situation, because ordinarily we guess whether the type
16361 is unsigned -- but the guess can be wrong and the underlying type
16362 can tell us the reality. However, we defer to a local size
16363 attribute if one exists, because this lets the compiler override
16364 the underlying type if needed. */
16365 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16367 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16368 if (TYPE_LENGTH (type
) == 0)
16369 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16370 if (TYPE_RAW_ALIGN (type
) == 0
16371 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16372 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16375 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16377 return set_die_type (die
, type
, cu
);
16380 /* Given a pointer to a die which begins an enumeration, process all
16381 the dies that define the members of the enumeration, and create the
16382 symbol for the enumeration type.
16384 NOTE: We reverse the order of the element list. */
16387 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16389 struct type
*this_type
;
16391 this_type
= get_die_type (die
, cu
);
16392 if (this_type
== NULL
)
16393 this_type
= read_enumeration_type (die
, cu
);
16395 if (die
->child
!= NULL
)
16397 struct die_info
*child_die
;
16398 struct symbol
*sym
;
16399 struct field
*fields
= NULL
;
16400 int num_fields
= 0;
16403 child_die
= die
->child
;
16404 while (child_die
&& child_die
->tag
)
16406 if (child_die
->tag
!= DW_TAG_enumerator
)
16408 process_die (child_die
, cu
);
16412 name
= dwarf2_name (child_die
, cu
);
16415 sym
= new_symbol (child_die
, this_type
, cu
);
16417 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16419 fields
= (struct field
*)
16421 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16422 * sizeof (struct field
));
16425 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16426 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16427 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16428 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16434 child_die
= sibling_die (child_die
);
16439 TYPE_NFIELDS (this_type
) = num_fields
;
16440 TYPE_FIELDS (this_type
) = (struct field
*)
16441 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16442 memcpy (TYPE_FIELDS (this_type
), fields
,
16443 sizeof (struct field
) * num_fields
);
16448 /* If we are reading an enum from a .debug_types unit, and the enum
16449 is a declaration, and the enum is not the signatured type in the
16450 unit, then we do not want to add a symbol for it. Adding a
16451 symbol would in some cases obscure the true definition of the
16452 enum, giving users an incomplete type when the definition is
16453 actually available. Note that we do not want to do this for all
16454 enums which are just declarations, because C++0x allows forward
16455 enum declarations. */
16456 if (cu
->per_cu
->is_debug_types
16457 && die_is_declaration (die
, cu
))
16459 struct signatured_type
*sig_type
;
16461 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16462 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16463 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16467 new_symbol (die
, this_type
, cu
);
16470 /* Extract all information from a DW_TAG_array_type DIE and put it in
16471 the DIE's type field. For now, this only handles one dimensional
16474 static struct type
*
16475 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16477 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16478 struct die_info
*child_die
;
16480 struct type
*element_type
, *range_type
, *index_type
;
16481 struct attribute
*attr
;
16483 struct dynamic_prop
*byte_stride_prop
= NULL
;
16484 unsigned int bit_stride
= 0;
16486 element_type
= die_type (die
, cu
);
16488 /* The die_type call above may have already set the type for this DIE. */
16489 type
= get_die_type (die
, cu
);
16493 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16497 struct type
*prop_type
16498 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16501 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16502 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16506 complaint (_("unable to read array DW_AT_byte_stride "
16507 " - DIE at %s [in module %s]"),
16508 sect_offset_str (die
->sect_off
),
16509 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16510 /* Ignore this attribute. We will likely not be able to print
16511 arrays of this type correctly, but there is little we can do
16512 to help if we cannot read the attribute's value. */
16513 byte_stride_prop
= NULL
;
16517 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16519 bit_stride
= DW_UNSND (attr
);
16521 /* Irix 6.2 native cc creates array types without children for
16522 arrays with unspecified length. */
16523 if (die
->child
== NULL
)
16525 index_type
= objfile_type (objfile
)->builtin_int
;
16526 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16527 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16528 byte_stride_prop
, bit_stride
);
16529 return set_die_type (die
, type
, cu
);
16532 std::vector
<struct type
*> range_types
;
16533 child_die
= die
->child
;
16534 while (child_die
&& child_die
->tag
)
16536 if (child_die
->tag
== DW_TAG_subrange_type
)
16538 struct type
*child_type
= read_type_die (child_die
, cu
);
16540 if (child_type
!= NULL
)
16542 /* The range type was succesfully read. Save it for the
16543 array type creation. */
16544 range_types
.push_back (child_type
);
16547 child_die
= sibling_die (child_die
);
16550 /* Dwarf2 dimensions are output from left to right, create the
16551 necessary array types in backwards order. */
16553 type
= element_type
;
16555 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16559 while (i
< range_types
.size ())
16560 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16561 byte_stride_prop
, bit_stride
);
16565 size_t ndim
= range_types
.size ();
16567 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16568 byte_stride_prop
, bit_stride
);
16571 /* Understand Dwarf2 support for vector types (like they occur on
16572 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16573 array type. This is not part of the Dwarf2/3 standard yet, but a
16574 custom vendor extension. The main difference between a regular
16575 array and the vector variant is that vectors are passed by value
16577 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16579 make_vector_type (type
);
16581 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16582 implementation may choose to implement triple vectors using this
16584 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16587 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16588 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16590 complaint (_("DW_AT_byte_size for array type smaller "
16591 "than the total size of elements"));
16594 name
= dwarf2_name (die
, cu
);
16596 TYPE_NAME (type
) = name
;
16598 maybe_set_alignment (cu
, die
, type
);
16600 /* Install the type in the die. */
16601 set_die_type (die
, type
, cu
);
16603 /* set_die_type should be already done. */
16604 set_descriptive_type (type
, die
, cu
);
16609 static enum dwarf_array_dim_ordering
16610 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16612 struct attribute
*attr
;
16614 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16617 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16619 /* GNU F77 is a special case, as at 08/2004 array type info is the
16620 opposite order to the dwarf2 specification, but data is still
16621 laid out as per normal fortran.
16623 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16624 version checking. */
16626 if (cu
->language
== language_fortran
16627 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16629 return DW_ORD_row_major
;
16632 switch (cu
->language_defn
->la_array_ordering
)
16634 case array_column_major
:
16635 return DW_ORD_col_major
;
16636 case array_row_major
:
16638 return DW_ORD_row_major
;
16642 /* Extract all information from a DW_TAG_set_type DIE and put it in
16643 the DIE's type field. */
16645 static struct type
*
16646 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16648 struct type
*domain_type
, *set_type
;
16649 struct attribute
*attr
;
16651 domain_type
= die_type (die
, cu
);
16653 /* The die_type call above may have already set the type for this DIE. */
16654 set_type
= get_die_type (die
, cu
);
16658 set_type
= create_set_type (NULL
, domain_type
);
16660 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16662 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16664 maybe_set_alignment (cu
, die
, set_type
);
16666 return set_die_type (die
, set_type
, cu
);
16669 /* A helper for read_common_block that creates a locexpr baton.
16670 SYM is the symbol which we are marking as computed.
16671 COMMON_DIE is the DIE for the common block.
16672 COMMON_LOC is the location expression attribute for the common
16674 MEMBER_LOC is the location expression attribute for the particular
16675 member of the common block that we are processing.
16676 CU is the CU from which the above come. */
16679 mark_common_block_symbol_computed (struct symbol
*sym
,
16680 struct die_info
*common_die
,
16681 struct attribute
*common_loc
,
16682 struct attribute
*member_loc
,
16683 struct dwarf2_cu
*cu
)
16685 struct dwarf2_per_objfile
*dwarf2_per_objfile
16686 = cu
->per_cu
->dwarf2_per_objfile
;
16687 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16688 struct dwarf2_locexpr_baton
*baton
;
16690 unsigned int cu_off
;
16691 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16692 LONGEST offset
= 0;
16694 gdb_assert (common_loc
&& member_loc
);
16695 gdb_assert (attr_form_is_block (common_loc
));
16696 gdb_assert (attr_form_is_block (member_loc
)
16697 || attr_form_is_constant (member_loc
));
16699 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16700 baton
->per_cu
= cu
->per_cu
;
16701 gdb_assert (baton
->per_cu
);
16703 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16705 if (attr_form_is_constant (member_loc
))
16707 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16708 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16711 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16713 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16716 *ptr
++ = DW_OP_call4
;
16717 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16718 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16721 if (attr_form_is_constant (member_loc
))
16723 *ptr
++ = DW_OP_addr
;
16724 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16725 ptr
+= cu
->header
.addr_size
;
16729 /* We have to copy the data here, because DW_OP_call4 will only
16730 use a DW_AT_location attribute. */
16731 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16732 ptr
+= DW_BLOCK (member_loc
)->size
;
16735 *ptr
++ = DW_OP_plus
;
16736 gdb_assert (ptr
- baton
->data
== baton
->size
);
16738 SYMBOL_LOCATION_BATON (sym
) = baton
;
16739 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16742 /* Create appropriate locally-scoped variables for all the
16743 DW_TAG_common_block entries. Also create a struct common_block
16744 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16745 is used to sepate the common blocks name namespace from regular
16749 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16751 struct attribute
*attr
;
16753 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16756 /* Support the .debug_loc offsets. */
16757 if (attr_form_is_block (attr
))
16761 else if (attr_form_is_section_offset (attr
))
16763 dwarf2_complex_location_expr_complaint ();
16768 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16769 "common block member");
16774 if (die
->child
!= NULL
)
16776 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16777 struct die_info
*child_die
;
16778 size_t n_entries
= 0, size
;
16779 struct common_block
*common_block
;
16780 struct symbol
*sym
;
16782 for (child_die
= die
->child
;
16783 child_die
&& child_die
->tag
;
16784 child_die
= sibling_die (child_die
))
16787 size
= (sizeof (struct common_block
)
16788 + (n_entries
- 1) * sizeof (struct symbol
*));
16790 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16792 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16793 common_block
->n_entries
= 0;
16795 for (child_die
= die
->child
;
16796 child_die
&& child_die
->tag
;
16797 child_die
= sibling_die (child_die
))
16799 /* Create the symbol in the DW_TAG_common_block block in the current
16801 sym
= new_symbol (child_die
, NULL
, cu
);
16804 struct attribute
*member_loc
;
16806 common_block
->contents
[common_block
->n_entries
++] = sym
;
16808 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16812 /* GDB has handled this for a long time, but it is
16813 not specified by DWARF. It seems to have been
16814 emitted by gfortran at least as recently as:
16815 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16816 complaint (_("Variable in common block has "
16817 "DW_AT_data_member_location "
16818 "- DIE at %s [in module %s]"),
16819 sect_offset_str (child_die
->sect_off
),
16820 objfile_name (objfile
));
16822 if (attr_form_is_section_offset (member_loc
))
16823 dwarf2_complex_location_expr_complaint ();
16824 else if (attr_form_is_constant (member_loc
)
16825 || attr_form_is_block (member_loc
))
16828 mark_common_block_symbol_computed (sym
, die
, attr
,
16832 dwarf2_complex_location_expr_complaint ();
16837 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16838 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16842 /* Create a type for a C++ namespace. */
16844 static struct type
*
16845 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16847 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16848 const char *previous_prefix
, *name
;
16852 /* For extensions, reuse the type of the original namespace. */
16853 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16855 struct die_info
*ext_die
;
16856 struct dwarf2_cu
*ext_cu
= cu
;
16858 ext_die
= dwarf2_extension (die
, &ext_cu
);
16859 type
= read_type_die (ext_die
, ext_cu
);
16861 /* EXT_CU may not be the same as CU.
16862 Ensure TYPE is recorded with CU in die_type_hash. */
16863 return set_die_type (die
, type
, cu
);
16866 name
= namespace_name (die
, &is_anonymous
, cu
);
16868 /* Now build the name of the current namespace. */
16870 previous_prefix
= determine_prefix (die
, cu
);
16871 if (previous_prefix
[0] != '\0')
16872 name
= typename_concat (&objfile
->objfile_obstack
,
16873 previous_prefix
, name
, 0, cu
);
16875 /* Create the type. */
16876 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16878 return set_die_type (die
, type
, cu
);
16881 /* Read a namespace scope. */
16884 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16886 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16889 /* Add a symbol associated to this if we haven't seen the namespace
16890 before. Also, add a using directive if it's an anonymous
16893 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16897 type
= read_type_die (die
, cu
);
16898 new_symbol (die
, type
, cu
);
16900 namespace_name (die
, &is_anonymous
, cu
);
16903 const char *previous_prefix
= determine_prefix (die
, cu
);
16905 std::vector
<const char *> excludes
;
16906 add_using_directive (using_directives (cu
),
16907 previous_prefix
, TYPE_NAME (type
), NULL
,
16908 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16912 if (die
->child
!= NULL
)
16914 struct die_info
*child_die
= die
->child
;
16916 while (child_die
&& child_die
->tag
)
16918 process_die (child_die
, cu
);
16919 child_die
= sibling_die (child_die
);
16924 /* Read a Fortran module as type. This DIE can be only a declaration used for
16925 imported module. Still we need that type as local Fortran "use ... only"
16926 declaration imports depend on the created type in determine_prefix. */
16928 static struct type
*
16929 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16931 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16932 const char *module_name
;
16935 module_name
= dwarf2_name (die
, cu
);
16936 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16938 return set_die_type (die
, type
, cu
);
16941 /* Read a Fortran module. */
16944 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16946 struct die_info
*child_die
= die
->child
;
16949 type
= read_type_die (die
, cu
);
16950 new_symbol (die
, type
, cu
);
16952 while (child_die
&& child_die
->tag
)
16954 process_die (child_die
, cu
);
16955 child_die
= sibling_die (child_die
);
16959 /* Return the name of the namespace represented by DIE. Set
16960 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16963 static const char *
16964 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16966 struct die_info
*current_die
;
16967 const char *name
= NULL
;
16969 /* Loop through the extensions until we find a name. */
16971 for (current_die
= die
;
16972 current_die
!= NULL
;
16973 current_die
= dwarf2_extension (die
, &cu
))
16975 /* We don't use dwarf2_name here so that we can detect the absence
16976 of a name -> anonymous namespace. */
16977 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16983 /* Is it an anonymous namespace? */
16985 *is_anonymous
= (name
== NULL
);
16987 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16992 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16993 the user defined type vector. */
16995 static struct type
*
16996 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16998 struct gdbarch
*gdbarch
16999 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17000 struct comp_unit_head
*cu_header
= &cu
->header
;
17002 struct attribute
*attr_byte_size
;
17003 struct attribute
*attr_address_class
;
17004 int byte_size
, addr_class
;
17005 struct type
*target_type
;
17007 target_type
= die_type (die
, cu
);
17009 /* The die_type call above may have already set the type for this DIE. */
17010 type
= get_die_type (die
, cu
);
17014 type
= lookup_pointer_type (target_type
);
17016 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17017 if (attr_byte_size
)
17018 byte_size
= DW_UNSND (attr_byte_size
);
17020 byte_size
= cu_header
->addr_size
;
17022 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17023 if (attr_address_class
)
17024 addr_class
= DW_UNSND (attr_address_class
);
17026 addr_class
= DW_ADDR_none
;
17028 ULONGEST alignment
= get_alignment (cu
, die
);
17030 /* If the pointer size, alignment, or address class is different
17031 than the default, create a type variant marked as such and set
17032 the length accordingly. */
17033 if (TYPE_LENGTH (type
) != byte_size
17034 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17035 && alignment
!= TYPE_RAW_ALIGN (type
))
17036 || addr_class
!= DW_ADDR_none
)
17038 if (gdbarch_address_class_type_flags_p (gdbarch
))
17042 type_flags
= gdbarch_address_class_type_flags
17043 (gdbarch
, byte_size
, addr_class
);
17044 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17046 type
= make_type_with_address_space (type
, type_flags
);
17048 else if (TYPE_LENGTH (type
) != byte_size
)
17050 complaint (_("invalid pointer size %d"), byte_size
);
17052 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17054 complaint (_("Invalid DW_AT_alignment"
17055 " - DIE at %s [in module %s]"),
17056 sect_offset_str (die
->sect_off
),
17057 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17061 /* Should we also complain about unhandled address classes? */
17065 TYPE_LENGTH (type
) = byte_size
;
17066 set_type_align (type
, alignment
);
17067 return set_die_type (die
, type
, cu
);
17070 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17071 the user defined type vector. */
17073 static struct type
*
17074 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17077 struct type
*to_type
;
17078 struct type
*domain
;
17080 to_type
= die_type (die
, cu
);
17081 domain
= die_containing_type (die
, cu
);
17083 /* The calls above may have already set the type for this DIE. */
17084 type
= get_die_type (die
, cu
);
17088 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17089 type
= lookup_methodptr_type (to_type
);
17090 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17092 struct type
*new_type
17093 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17095 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17096 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17097 TYPE_VARARGS (to_type
));
17098 type
= lookup_methodptr_type (new_type
);
17101 type
= lookup_memberptr_type (to_type
, domain
);
17103 return set_die_type (die
, type
, cu
);
17106 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17107 the user defined type vector. */
17109 static struct type
*
17110 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17111 enum type_code refcode
)
17113 struct comp_unit_head
*cu_header
= &cu
->header
;
17114 struct type
*type
, *target_type
;
17115 struct attribute
*attr
;
17117 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17119 target_type
= die_type (die
, cu
);
17121 /* The die_type call above may have already set the type for this DIE. */
17122 type
= get_die_type (die
, cu
);
17126 type
= lookup_reference_type (target_type
, refcode
);
17127 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17130 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17134 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17136 maybe_set_alignment (cu
, die
, type
);
17137 return set_die_type (die
, type
, cu
);
17140 /* Add the given cv-qualifiers to the element type of the array. GCC
17141 outputs DWARF type qualifiers that apply to an array, not the
17142 element type. But GDB relies on the array element type to carry
17143 the cv-qualifiers. This mimics section 6.7.3 of the C99
17146 static struct type
*
17147 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17148 struct type
*base_type
, int cnst
, int voltl
)
17150 struct type
*el_type
, *inner_array
;
17152 base_type
= copy_type (base_type
);
17153 inner_array
= base_type
;
17155 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17157 TYPE_TARGET_TYPE (inner_array
) =
17158 copy_type (TYPE_TARGET_TYPE (inner_array
));
17159 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17162 el_type
= TYPE_TARGET_TYPE (inner_array
);
17163 cnst
|= TYPE_CONST (el_type
);
17164 voltl
|= TYPE_VOLATILE (el_type
);
17165 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17167 return set_die_type (die
, base_type
, cu
);
17170 static struct type
*
17171 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17173 struct type
*base_type
, *cv_type
;
17175 base_type
= die_type (die
, cu
);
17177 /* The die_type call above may have already set the type for this DIE. */
17178 cv_type
= get_die_type (die
, cu
);
17182 /* In case the const qualifier is applied to an array type, the element type
17183 is so qualified, not the array type (section 6.7.3 of C99). */
17184 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17185 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17187 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17188 return set_die_type (die
, cv_type
, cu
);
17191 static struct type
*
17192 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17194 struct type
*base_type
, *cv_type
;
17196 base_type
= die_type (die
, cu
);
17198 /* The die_type call above may have already set the type for this DIE. */
17199 cv_type
= get_die_type (die
, cu
);
17203 /* In case the volatile qualifier is applied to an array type, the
17204 element type is so qualified, not the array type (section 6.7.3
17206 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17207 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17209 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17210 return set_die_type (die
, cv_type
, cu
);
17213 /* Handle DW_TAG_restrict_type. */
17215 static struct type
*
17216 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17218 struct type
*base_type
, *cv_type
;
17220 base_type
= die_type (die
, cu
);
17222 /* The die_type call above may have already set the type for this DIE. */
17223 cv_type
= get_die_type (die
, cu
);
17227 cv_type
= make_restrict_type (base_type
);
17228 return set_die_type (die
, cv_type
, cu
);
17231 /* Handle DW_TAG_atomic_type. */
17233 static struct type
*
17234 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17236 struct type
*base_type
, *cv_type
;
17238 base_type
= die_type (die
, cu
);
17240 /* The die_type call above may have already set the type for this DIE. */
17241 cv_type
= get_die_type (die
, cu
);
17245 cv_type
= make_atomic_type (base_type
);
17246 return set_die_type (die
, cv_type
, cu
);
17249 /* Extract all information from a DW_TAG_string_type DIE and add to
17250 the user defined type vector. It isn't really a user defined type,
17251 but it behaves like one, with other DIE's using an AT_user_def_type
17252 attribute to reference it. */
17254 static struct type
*
17255 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17257 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17258 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17259 struct type
*type
, *range_type
, *index_type
, *char_type
;
17260 struct attribute
*attr
;
17261 unsigned int length
;
17263 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17266 length
= DW_UNSND (attr
);
17270 /* Check for the DW_AT_byte_size attribute. */
17271 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17274 length
= DW_UNSND (attr
);
17282 index_type
= objfile_type (objfile
)->builtin_int
;
17283 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17284 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17285 type
= create_string_type (NULL
, char_type
, range_type
);
17287 return set_die_type (die
, type
, cu
);
17290 /* Assuming that DIE corresponds to a function, returns nonzero
17291 if the function is prototyped. */
17294 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17296 struct attribute
*attr
;
17298 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17299 if (attr
&& (DW_UNSND (attr
) != 0))
17302 /* The DWARF standard implies that the DW_AT_prototyped attribute
17303 is only meaninful for C, but the concept also extends to other
17304 languages that allow unprototyped functions (Eg: Objective C).
17305 For all other languages, assume that functions are always
17307 if (cu
->language
!= language_c
17308 && cu
->language
!= language_objc
17309 && cu
->language
!= language_opencl
)
17312 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17313 prototyped and unprototyped functions; default to prototyped,
17314 since that is more common in modern code (and RealView warns
17315 about unprototyped functions). */
17316 if (producer_is_realview (cu
->producer
))
17322 /* Handle DIES due to C code like:
17326 int (*funcp)(int a, long l);
17330 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17332 static struct type
*
17333 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17335 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17336 struct type
*type
; /* Type that this function returns. */
17337 struct type
*ftype
; /* Function that returns above type. */
17338 struct attribute
*attr
;
17340 type
= die_type (die
, cu
);
17342 /* The die_type call above may have already set the type for this DIE. */
17343 ftype
= get_die_type (die
, cu
);
17347 ftype
= lookup_function_type (type
);
17349 if (prototyped_function_p (die
, cu
))
17350 TYPE_PROTOTYPED (ftype
) = 1;
17352 /* Store the calling convention in the type if it's available in
17353 the subroutine die. Otherwise set the calling convention to
17354 the default value DW_CC_normal. */
17355 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17357 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17358 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17359 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17361 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17363 /* Record whether the function returns normally to its caller or not
17364 if the DWARF producer set that information. */
17365 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17366 if (attr
&& (DW_UNSND (attr
) != 0))
17367 TYPE_NO_RETURN (ftype
) = 1;
17369 /* We need to add the subroutine type to the die immediately so
17370 we don't infinitely recurse when dealing with parameters
17371 declared as the same subroutine type. */
17372 set_die_type (die
, ftype
, cu
);
17374 if (die
->child
!= NULL
)
17376 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17377 struct die_info
*child_die
;
17378 int nparams
, iparams
;
17380 /* Count the number of parameters.
17381 FIXME: GDB currently ignores vararg functions, but knows about
17382 vararg member functions. */
17384 child_die
= die
->child
;
17385 while (child_die
&& child_die
->tag
)
17387 if (child_die
->tag
== DW_TAG_formal_parameter
)
17389 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17390 TYPE_VARARGS (ftype
) = 1;
17391 child_die
= sibling_die (child_die
);
17394 /* Allocate storage for parameters and fill them in. */
17395 TYPE_NFIELDS (ftype
) = nparams
;
17396 TYPE_FIELDS (ftype
) = (struct field
*)
17397 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17399 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17400 even if we error out during the parameters reading below. */
17401 for (iparams
= 0; iparams
< nparams
; iparams
++)
17402 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17405 child_die
= die
->child
;
17406 while (child_die
&& child_die
->tag
)
17408 if (child_die
->tag
== DW_TAG_formal_parameter
)
17410 struct type
*arg_type
;
17412 /* DWARF version 2 has no clean way to discern C++
17413 static and non-static member functions. G++ helps
17414 GDB by marking the first parameter for non-static
17415 member functions (which is the this pointer) as
17416 artificial. We pass this information to
17417 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17419 DWARF version 3 added DW_AT_object_pointer, which GCC
17420 4.5 does not yet generate. */
17421 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17423 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17425 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17426 arg_type
= die_type (child_die
, cu
);
17428 /* RealView does not mark THIS as const, which the testsuite
17429 expects. GCC marks THIS as const in method definitions,
17430 but not in the class specifications (GCC PR 43053). */
17431 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17432 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17435 struct dwarf2_cu
*arg_cu
= cu
;
17436 const char *name
= dwarf2_name (child_die
, cu
);
17438 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17441 /* If the compiler emits this, use it. */
17442 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17445 else if (name
&& strcmp (name
, "this") == 0)
17446 /* Function definitions will have the argument names. */
17448 else if (name
== NULL
&& iparams
== 0)
17449 /* Declarations may not have the names, so like
17450 elsewhere in GDB, assume an artificial first
17451 argument is "this". */
17455 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17459 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17462 child_die
= sibling_die (child_die
);
17469 static struct type
*
17470 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17472 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17473 const char *name
= NULL
;
17474 struct type
*this_type
, *target_type
;
17476 name
= dwarf2_full_name (NULL
, die
, cu
);
17477 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17478 TYPE_TARGET_STUB (this_type
) = 1;
17479 set_die_type (die
, this_type
, cu
);
17480 target_type
= die_type (die
, cu
);
17481 if (target_type
!= this_type
)
17482 TYPE_TARGET_TYPE (this_type
) = target_type
;
17485 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17486 spec and cause infinite loops in GDB. */
17487 complaint (_("Self-referential DW_TAG_typedef "
17488 "- DIE at %s [in module %s]"),
17489 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17490 TYPE_TARGET_TYPE (this_type
) = NULL
;
17495 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17496 (which may be different from NAME) to the architecture back-end to allow
17497 it to guess the correct format if necessary. */
17499 static struct type
*
17500 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17501 const char *name_hint
)
17503 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17504 const struct floatformat
**format
;
17507 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17509 type
= init_float_type (objfile
, bits
, name
, format
);
17511 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17516 /* Allocate an integer type of size BITS and name NAME. */
17518 static struct type
*
17519 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17520 int bits
, int unsigned_p
, const char *name
)
17524 /* Versions of Intel's C Compiler generate an integer type called "void"
17525 instead of using DW_TAG_unspecified_type. This has been seen on
17526 at least versions 14, 17, and 18. */
17527 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17528 && strcmp (name
, "void") == 0)
17529 type
= objfile_type (objfile
)->builtin_void
;
17531 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17536 /* Initialise and return a floating point type of size BITS suitable for
17537 use as a component of a complex number. The NAME_HINT is passed through
17538 when initialising the floating point type and is the name of the complex
17541 As DWARF doesn't currently provide an explicit name for the components
17542 of a complex number, but it can be helpful to have these components
17543 named, we try to select a suitable name based on the size of the
17545 static struct type
*
17546 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17547 struct objfile
*objfile
,
17548 int bits
, const char *name_hint
)
17550 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17551 struct type
*tt
= nullptr;
17553 /* Try to find a suitable floating point builtin type of size BITS.
17554 We're going to use the name of this type as the name for the complex
17555 target type that we are about to create. */
17556 switch (cu
->language
)
17558 case language_fortran
:
17562 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17565 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17567 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17569 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17577 tt
= builtin_type (gdbarch
)->builtin_float
;
17580 tt
= builtin_type (gdbarch
)->builtin_double
;
17582 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17584 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17590 /* If the type we found doesn't match the size we were looking for, then
17591 pretend we didn't find a type at all, the complex target type we
17592 create will then be nameless. */
17593 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17596 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17597 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
);
17600 /* Find a representation of a given base type and install
17601 it in the TYPE field of the die. */
17603 static struct type
*
17604 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17606 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17608 struct attribute
*attr
;
17609 int encoding
= 0, bits
= 0;
17612 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17615 encoding
= DW_UNSND (attr
);
17617 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17620 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17622 name
= dwarf2_name (die
, cu
);
17625 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17630 case DW_ATE_address
:
17631 /* Turn DW_ATE_address into a void * pointer. */
17632 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17633 type
= init_pointer_type (objfile
, bits
, name
, type
);
17635 case DW_ATE_boolean
:
17636 type
= init_boolean_type (objfile
, bits
, 1, name
);
17638 case DW_ATE_complex_float
:
17639 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
);
17640 type
= init_complex_type (objfile
, name
, type
);
17642 case DW_ATE_decimal_float
:
17643 type
= init_decfloat_type (objfile
, bits
, name
);
17646 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17648 case DW_ATE_signed
:
17649 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17651 case DW_ATE_unsigned
:
17652 if (cu
->language
== language_fortran
17654 && startswith (name
, "character("))
17655 type
= init_character_type (objfile
, bits
, 1, name
);
17657 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17659 case DW_ATE_signed_char
:
17660 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17661 || cu
->language
== language_pascal
17662 || cu
->language
== language_fortran
)
17663 type
= init_character_type (objfile
, bits
, 0, name
);
17665 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17667 case DW_ATE_unsigned_char
:
17668 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17669 || cu
->language
== language_pascal
17670 || cu
->language
== language_fortran
17671 || cu
->language
== language_rust
)
17672 type
= init_character_type (objfile
, bits
, 1, name
);
17674 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17678 gdbarch
*arch
= get_objfile_arch (objfile
);
17681 type
= builtin_type (arch
)->builtin_char16
;
17682 else if (bits
== 32)
17683 type
= builtin_type (arch
)->builtin_char32
;
17686 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17688 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17690 return set_die_type (die
, type
, cu
);
17695 complaint (_("unsupported DW_AT_encoding: '%s'"),
17696 dwarf_type_encoding_name (encoding
));
17697 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17701 if (name
&& strcmp (name
, "char") == 0)
17702 TYPE_NOSIGN (type
) = 1;
17704 maybe_set_alignment (cu
, die
, type
);
17706 return set_die_type (die
, type
, cu
);
17709 /* Parse dwarf attribute if it's a block, reference or constant and put the
17710 resulting value of the attribute into struct bound_prop.
17711 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17714 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17715 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17716 struct type
*default_type
)
17718 struct dwarf2_property_baton
*baton
;
17719 struct obstack
*obstack
17720 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17722 gdb_assert (default_type
!= NULL
);
17724 if (attr
== NULL
|| prop
== NULL
)
17727 if (attr_form_is_block (attr
))
17729 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17730 baton
->property_type
= default_type
;
17731 baton
->locexpr
.per_cu
= cu
->per_cu
;
17732 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17733 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17734 baton
->locexpr
.is_reference
= false;
17735 prop
->data
.baton
= baton
;
17736 prop
->kind
= PROP_LOCEXPR
;
17737 gdb_assert (prop
->data
.baton
!= NULL
);
17739 else if (attr_form_is_ref (attr
))
17741 struct dwarf2_cu
*target_cu
= cu
;
17742 struct die_info
*target_die
;
17743 struct attribute
*target_attr
;
17745 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17746 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17747 if (target_attr
== NULL
)
17748 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17750 if (target_attr
== NULL
)
17753 switch (target_attr
->name
)
17755 case DW_AT_location
:
17756 if (attr_form_is_section_offset (target_attr
))
17758 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17759 baton
->property_type
= die_type (target_die
, target_cu
);
17760 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17761 prop
->data
.baton
= baton
;
17762 prop
->kind
= PROP_LOCLIST
;
17763 gdb_assert (prop
->data
.baton
!= NULL
);
17765 else if (attr_form_is_block (target_attr
))
17767 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17768 baton
->property_type
= die_type (target_die
, target_cu
);
17769 baton
->locexpr
.per_cu
= cu
->per_cu
;
17770 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17771 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17772 baton
->locexpr
.is_reference
= true;
17773 prop
->data
.baton
= baton
;
17774 prop
->kind
= PROP_LOCEXPR
;
17775 gdb_assert (prop
->data
.baton
!= NULL
);
17779 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17780 "dynamic property");
17784 case DW_AT_data_member_location
:
17788 if (!handle_data_member_location (target_die
, target_cu
,
17792 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17793 baton
->property_type
= read_type_die (target_die
->parent
,
17795 baton
->offset_info
.offset
= offset
;
17796 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17797 prop
->data
.baton
= baton
;
17798 prop
->kind
= PROP_ADDR_OFFSET
;
17803 else if (attr_form_is_constant (attr
))
17805 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17806 prop
->kind
= PROP_CONST
;
17810 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17811 dwarf2_name (die
, cu
));
17818 /* Find an integer type the same size as the address size given in the
17819 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
17820 is unsigned or not. */
17822 static struct type
*
17823 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
17826 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
17827 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
17828 struct type
*int_type
;
17830 /* Helper macro to examine the various builtin types. */
17831 #define TRY_TYPE(F) \
17832 int_type = (unsigned_p \
17833 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17834 : objfile_type (objfile)->builtin_ ## F); \
17835 if (int_type != NULL && TYPE_LENGTH (int_type) == addr_size) \
17842 TRY_TYPE (long_long
);
17846 gdb_assert_not_reached ("unable to find suitable integer type");
17849 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17850 present (which is valid) then compute the default type based on the
17851 compilation units address size. */
17853 static struct type
*
17854 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17856 struct type
*index_type
= die_type (die
, cu
);
17858 /* Dwarf-2 specifications explicitly allows to create subrange types
17859 without specifying a base type.
17860 In that case, the base type must be set to the type of
17861 the lower bound, upper bound or count, in that order, if any of these
17862 three attributes references an object that has a type.
17863 If no base type is found, the Dwarf-2 specifications say that
17864 a signed integer type of size equal to the size of an address should
17866 For the following C code: `extern char gdb_int [];'
17867 GCC produces an empty range DIE.
17868 FIXME: muller/2010-05-28: Possible references to object for low bound,
17869 high bound or count are not yet handled by this code. */
17870 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17871 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
17876 /* Read the given DW_AT_subrange DIE. */
17878 static struct type
*
17879 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17881 struct type
*base_type
, *orig_base_type
;
17882 struct type
*range_type
;
17883 struct attribute
*attr
;
17884 struct dynamic_prop low
, high
;
17885 int low_default_is_valid
;
17886 int high_bound_is_count
= 0;
17888 ULONGEST negative_mask
;
17890 orig_base_type
= read_subrange_index_type (die
, cu
);
17892 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17893 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17894 creating the range type, but we use the result of check_typedef
17895 when examining properties of the type. */
17896 base_type
= check_typedef (orig_base_type
);
17898 /* The die_type call above may have already set the type for this DIE. */
17899 range_type
= get_die_type (die
, cu
);
17903 low
.kind
= PROP_CONST
;
17904 high
.kind
= PROP_CONST
;
17905 high
.data
.const_val
= 0;
17907 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17908 omitting DW_AT_lower_bound. */
17909 switch (cu
->language
)
17912 case language_cplus
:
17913 low
.data
.const_val
= 0;
17914 low_default_is_valid
= 1;
17916 case language_fortran
:
17917 low
.data
.const_val
= 1;
17918 low_default_is_valid
= 1;
17921 case language_objc
:
17922 case language_rust
:
17923 low
.data
.const_val
= 0;
17924 low_default_is_valid
= (cu
->header
.version
>= 4);
17928 case language_pascal
:
17929 low
.data
.const_val
= 1;
17930 low_default_is_valid
= (cu
->header
.version
>= 4);
17933 low
.data
.const_val
= 0;
17934 low_default_is_valid
= 0;
17938 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17940 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17941 else if (!low_default_is_valid
)
17942 complaint (_("Missing DW_AT_lower_bound "
17943 "- DIE at %s [in module %s]"),
17944 sect_offset_str (die
->sect_off
),
17945 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17947 struct attribute
*attr_ub
, *attr_count
;
17948 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17949 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17951 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17952 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17954 /* If bounds are constant do the final calculation here. */
17955 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17956 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17958 high_bound_is_count
= 1;
17962 if (attr_ub
!= NULL
)
17963 complaint (_("Unresolved DW_AT_upper_bound "
17964 "- DIE at %s [in module %s]"),
17965 sect_offset_str (die
->sect_off
),
17966 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17967 if (attr_count
!= NULL
)
17968 complaint (_("Unresolved DW_AT_count "
17969 "- DIE at %s [in module %s]"),
17970 sect_offset_str (die
->sect_off
),
17971 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17976 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17977 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
17978 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17980 /* Normally, the DWARF producers are expected to use a signed
17981 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17982 But this is unfortunately not always the case, as witnessed
17983 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17984 is used instead. To work around that ambiguity, we treat
17985 the bounds as signed, and thus sign-extend their values, when
17986 the base type is signed. */
17988 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17989 if (low
.kind
== PROP_CONST
17990 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17991 low
.data
.const_val
|= negative_mask
;
17992 if (high
.kind
== PROP_CONST
17993 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17994 high
.data
.const_val
|= negative_mask
;
17996 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17998 if (high_bound_is_count
)
17999 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18001 /* Ada expects an empty array on no boundary attributes. */
18002 if (attr
== NULL
&& cu
->language
!= language_ada
)
18003 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18005 name
= dwarf2_name (die
, cu
);
18007 TYPE_NAME (range_type
) = name
;
18009 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18011 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18013 maybe_set_alignment (cu
, die
, range_type
);
18015 set_die_type (die
, range_type
, cu
);
18017 /* set_die_type should be already done. */
18018 set_descriptive_type (range_type
, die
, cu
);
18023 static struct type
*
18024 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18028 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18030 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18032 /* In Ada, an unspecified type is typically used when the description
18033 of the type is defered to a different unit. When encountering
18034 such a type, we treat it as a stub, and try to resolve it later on,
18036 if (cu
->language
== language_ada
)
18037 TYPE_STUB (type
) = 1;
18039 return set_die_type (die
, type
, cu
);
18042 /* Read a single die and all its descendents. Set the die's sibling
18043 field to NULL; set other fields in the die correctly, and set all
18044 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18045 location of the info_ptr after reading all of those dies. PARENT
18046 is the parent of the die in question. */
18048 static struct die_info
*
18049 read_die_and_children (const struct die_reader_specs
*reader
,
18050 const gdb_byte
*info_ptr
,
18051 const gdb_byte
**new_info_ptr
,
18052 struct die_info
*parent
)
18054 struct die_info
*die
;
18055 const gdb_byte
*cur_ptr
;
18058 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18061 *new_info_ptr
= cur_ptr
;
18064 store_in_ref_table (die
, reader
->cu
);
18067 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18071 *new_info_ptr
= cur_ptr
;
18074 die
->sibling
= NULL
;
18075 die
->parent
= parent
;
18079 /* Read a die, all of its descendents, and all of its siblings; set
18080 all of the fields of all of the dies correctly. Arguments are as
18081 in read_die_and_children. */
18083 static struct die_info
*
18084 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18085 const gdb_byte
*info_ptr
,
18086 const gdb_byte
**new_info_ptr
,
18087 struct die_info
*parent
)
18089 struct die_info
*first_die
, *last_sibling
;
18090 const gdb_byte
*cur_ptr
;
18092 cur_ptr
= info_ptr
;
18093 first_die
= last_sibling
= NULL
;
18097 struct die_info
*die
18098 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18102 *new_info_ptr
= cur_ptr
;
18109 last_sibling
->sibling
= die
;
18111 last_sibling
= die
;
18115 /* Read a die, all of its descendents, and all of its siblings; set
18116 all of the fields of all of the dies correctly. Arguments are as
18117 in read_die_and_children.
18118 This the main entry point for reading a DIE and all its children. */
18120 static struct die_info
*
18121 read_die_and_siblings (const struct die_reader_specs
*reader
,
18122 const gdb_byte
*info_ptr
,
18123 const gdb_byte
**new_info_ptr
,
18124 struct die_info
*parent
)
18126 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18127 new_info_ptr
, parent
);
18129 if (dwarf_die_debug
)
18131 fprintf_unfiltered (gdb_stdlog
,
18132 "Read die from %s@0x%x of %s:\n",
18133 get_section_name (reader
->die_section
),
18134 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18135 bfd_get_filename (reader
->abfd
));
18136 dump_die (die
, dwarf_die_debug
);
18142 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18144 The caller is responsible for filling in the extra attributes
18145 and updating (*DIEP)->num_attrs.
18146 Set DIEP to point to a newly allocated die with its information,
18147 except for its child, sibling, and parent fields.
18148 Set HAS_CHILDREN to tell whether the die has children or not. */
18150 static const gdb_byte
*
18151 read_full_die_1 (const struct die_reader_specs
*reader
,
18152 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18153 int *has_children
, int num_extra_attrs
)
18155 unsigned int abbrev_number
, bytes_read
, i
;
18156 struct abbrev_info
*abbrev
;
18157 struct die_info
*die
;
18158 struct dwarf2_cu
*cu
= reader
->cu
;
18159 bfd
*abfd
= reader
->abfd
;
18161 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18162 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18163 info_ptr
+= bytes_read
;
18164 if (!abbrev_number
)
18171 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18173 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18175 bfd_get_filename (abfd
));
18177 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18178 die
->sect_off
= sect_off
;
18179 die
->tag
= abbrev
->tag
;
18180 die
->abbrev
= abbrev_number
;
18182 /* Make the result usable.
18183 The caller needs to update num_attrs after adding the extra
18185 die
->num_attrs
= abbrev
->num_attrs
;
18187 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18188 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18192 *has_children
= abbrev
->has_children
;
18196 /* Read a die and all its attributes.
18197 Set DIEP to point to a newly allocated die with its information,
18198 except for its child, sibling, and parent fields.
18199 Set HAS_CHILDREN to tell whether the die has children or not. */
18201 static const gdb_byte
*
18202 read_full_die (const struct die_reader_specs
*reader
,
18203 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18206 const gdb_byte
*result
;
18208 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18210 if (dwarf_die_debug
)
18212 fprintf_unfiltered (gdb_stdlog
,
18213 "Read die from %s@0x%x of %s:\n",
18214 get_section_name (reader
->die_section
),
18215 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18216 bfd_get_filename (reader
->abfd
));
18217 dump_die (*diep
, dwarf_die_debug
);
18223 /* Abbreviation tables.
18225 In DWARF version 2, the description of the debugging information is
18226 stored in a separate .debug_abbrev section. Before we read any
18227 dies from a section we read in all abbreviations and install them
18228 in a hash table. */
18230 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18232 struct abbrev_info
*
18233 abbrev_table::alloc_abbrev ()
18235 struct abbrev_info
*abbrev
;
18237 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18238 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18243 /* Add an abbreviation to the table. */
18246 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18247 struct abbrev_info
*abbrev
)
18249 unsigned int hash_number
;
18251 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18252 abbrev
->next
= m_abbrevs
[hash_number
];
18253 m_abbrevs
[hash_number
] = abbrev
;
18256 /* Look up an abbrev in the table.
18257 Returns NULL if the abbrev is not found. */
18259 struct abbrev_info
*
18260 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18262 unsigned int hash_number
;
18263 struct abbrev_info
*abbrev
;
18265 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18266 abbrev
= m_abbrevs
[hash_number
];
18270 if (abbrev
->number
== abbrev_number
)
18272 abbrev
= abbrev
->next
;
18277 /* Read in an abbrev table. */
18279 static abbrev_table_up
18280 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18281 struct dwarf2_section_info
*section
,
18282 sect_offset sect_off
)
18284 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18285 bfd
*abfd
= get_section_bfd_owner (section
);
18286 const gdb_byte
*abbrev_ptr
;
18287 struct abbrev_info
*cur_abbrev
;
18288 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18289 unsigned int abbrev_form
;
18290 struct attr_abbrev
*cur_attrs
;
18291 unsigned int allocated_attrs
;
18293 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18295 dwarf2_read_section (objfile
, section
);
18296 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18297 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18298 abbrev_ptr
+= bytes_read
;
18300 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18301 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18303 /* Loop until we reach an abbrev number of 0. */
18304 while (abbrev_number
)
18306 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18308 /* read in abbrev header */
18309 cur_abbrev
->number
= abbrev_number
;
18311 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18312 abbrev_ptr
+= bytes_read
;
18313 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18316 /* now read in declarations */
18319 LONGEST implicit_const
;
18321 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18322 abbrev_ptr
+= bytes_read
;
18323 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18324 abbrev_ptr
+= bytes_read
;
18325 if (abbrev_form
== DW_FORM_implicit_const
)
18327 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18329 abbrev_ptr
+= bytes_read
;
18333 /* Initialize it due to a false compiler warning. */
18334 implicit_const
= -1;
18337 if (abbrev_name
== 0)
18340 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18342 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18344 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18347 cur_attrs
[cur_abbrev
->num_attrs
].name
18348 = (enum dwarf_attribute
) abbrev_name
;
18349 cur_attrs
[cur_abbrev
->num_attrs
].form
18350 = (enum dwarf_form
) abbrev_form
;
18351 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18352 ++cur_abbrev
->num_attrs
;
18355 cur_abbrev
->attrs
=
18356 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18357 cur_abbrev
->num_attrs
);
18358 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18359 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18361 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18363 /* Get next abbreviation.
18364 Under Irix6 the abbreviations for a compilation unit are not
18365 always properly terminated with an abbrev number of 0.
18366 Exit loop if we encounter an abbreviation which we have
18367 already read (which means we are about to read the abbreviations
18368 for the next compile unit) or if the end of the abbreviation
18369 table is reached. */
18370 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18372 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18373 abbrev_ptr
+= bytes_read
;
18374 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18379 return abbrev_table
;
18382 /* Returns nonzero if TAG represents a type that we might generate a partial
18386 is_type_tag_for_partial (int tag
)
18391 /* Some types that would be reasonable to generate partial symbols for,
18392 that we don't at present. */
18393 case DW_TAG_array_type
:
18394 case DW_TAG_file_type
:
18395 case DW_TAG_ptr_to_member_type
:
18396 case DW_TAG_set_type
:
18397 case DW_TAG_string_type
:
18398 case DW_TAG_subroutine_type
:
18400 case DW_TAG_base_type
:
18401 case DW_TAG_class_type
:
18402 case DW_TAG_interface_type
:
18403 case DW_TAG_enumeration_type
:
18404 case DW_TAG_structure_type
:
18405 case DW_TAG_subrange_type
:
18406 case DW_TAG_typedef
:
18407 case DW_TAG_union_type
:
18414 /* Load all DIEs that are interesting for partial symbols into memory. */
18416 static struct partial_die_info
*
18417 load_partial_dies (const struct die_reader_specs
*reader
,
18418 const gdb_byte
*info_ptr
, int building_psymtab
)
18420 struct dwarf2_cu
*cu
= reader
->cu
;
18421 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18422 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18423 unsigned int bytes_read
;
18424 unsigned int load_all
= 0;
18425 int nesting_level
= 1;
18430 gdb_assert (cu
->per_cu
!= NULL
);
18431 if (cu
->per_cu
->load_all_dies
)
18435 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18439 &cu
->comp_unit_obstack
,
18440 hashtab_obstack_allocate
,
18441 dummy_obstack_deallocate
);
18445 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18447 /* A NULL abbrev means the end of a series of children. */
18448 if (abbrev
== NULL
)
18450 if (--nesting_level
== 0)
18453 info_ptr
+= bytes_read
;
18454 last_die
= parent_die
;
18455 parent_die
= parent_die
->die_parent
;
18459 /* Check for template arguments. We never save these; if
18460 they're seen, we just mark the parent, and go on our way. */
18461 if (parent_die
!= NULL
18462 && cu
->language
== language_cplus
18463 && (abbrev
->tag
== DW_TAG_template_type_param
18464 || abbrev
->tag
== DW_TAG_template_value_param
))
18466 parent_die
->has_template_arguments
= 1;
18470 /* We don't need a partial DIE for the template argument. */
18471 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18476 /* We only recurse into c++ subprograms looking for template arguments.
18477 Skip their other children. */
18479 && cu
->language
== language_cplus
18480 && parent_die
!= NULL
18481 && parent_die
->tag
== DW_TAG_subprogram
)
18483 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18487 /* Check whether this DIE is interesting enough to save. Normally
18488 we would not be interested in members here, but there may be
18489 later variables referencing them via DW_AT_specification (for
18490 static members). */
18492 && !is_type_tag_for_partial (abbrev
->tag
)
18493 && abbrev
->tag
!= DW_TAG_constant
18494 && abbrev
->tag
!= DW_TAG_enumerator
18495 && abbrev
->tag
!= DW_TAG_subprogram
18496 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18497 && abbrev
->tag
!= DW_TAG_lexical_block
18498 && abbrev
->tag
!= DW_TAG_variable
18499 && abbrev
->tag
!= DW_TAG_namespace
18500 && abbrev
->tag
!= DW_TAG_module
18501 && abbrev
->tag
!= DW_TAG_member
18502 && abbrev
->tag
!= DW_TAG_imported_unit
18503 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18505 /* Otherwise we skip to the next sibling, if any. */
18506 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18510 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18513 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18515 /* This two-pass algorithm for processing partial symbols has a
18516 high cost in cache pressure. Thus, handle some simple cases
18517 here which cover the majority of C partial symbols. DIEs
18518 which neither have specification tags in them, nor could have
18519 specification tags elsewhere pointing at them, can simply be
18520 processed and discarded.
18522 This segment is also optional; scan_partial_symbols and
18523 add_partial_symbol will handle these DIEs if we chain
18524 them in normally. When compilers which do not emit large
18525 quantities of duplicate debug information are more common,
18526 this code can probably be removed. */
18528 /* Any complete simple types at the top level (pretty much all
18529 of them, for a language without namespaces), can be processed
18531 if (parent_die
== NULL
18532 && pdi
.has_specification
== 0
18533 && pdi
.is_declaration
== 0
18534 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18535 || pdi
.tag
== DW_TAG_base_type
18536 || pdi
.tag
== DW_TAG_subrange_type
))
18538 if (building_psymtab
&& pdi
.name
!= NULL
)
18539 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), false,
18540 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18541 psymbol_placement::STATIC
,
18542 0, cu
->language
, objfile
);
18543 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18547 /* The exception for DW_TAG_typedef with has_children above is
18548 a workaround of GCC PR debug/47510. In the case of this complaint
18549 type_name_or_error will error on such types later.
18551 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18552 it could not find the child DIEs referenced later, this is checked
18553 above. In correct DWARF DW_TAG_typedef should have no children. */
18555 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18556 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18557 "- DIE at %s [in module %s]"),
18558 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18560 /* If we're at the second level, and we're an enumerator, and
18561 our parent has no specification (meaning possibly lives in a
18562 namespace elsewhere), then we can add the partial symbol now
18563 instead of queueing it. */
18564 if (pdi
.tag
== DW_TAG_enumerator
18565 && parent_die
!= NULL
18566 && parent_die
->die_parent
== NULL
18567 && parent_die
->tag
== DW_TAG_enumeration_type
18568 && parent_die
->has_specification
== 0)
18570 if (pdi
.name
== NULL
)
18571 complaint (_("malformed enumerator DIE ignored"));
18572 else if (building_psymtab
)
18573 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), false,
18574 VAR_DOMAIN
, LOC_CONST
, -1,
18575 cu
->language
== language_cplus
18576 ? psymbol_placement::GLOBAL
18577 : psymbol_placement::STATIC
,
18578 0, cu
->language
, objfile
);
18580 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18584 struct partial_die_info
*part_die
18585 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18587 /* We'll save this DIE so link it in. */
18588 part_die
->die_parent
= parent_die
;
18589 part_die
->die_sibling
= NULL
;
18590 part_die
->die_child
= NULL
;
18592 if (last_die
&& last_die
== parent_die
)
18593 last_die
->die_child
= part_die
;
18595 last_die
->die_sibling
= part_die
;
18597 last_die
= part_die
;
18599 if (first_die
== NULL
)
18600 first_die
= part_die
;
18602 /* Maybe add the DIE to the hash table. Not all DIEs that we
18603 find interesting need to be in the hash table, because we
18604 also have the parent/sibling/child chains; only those that we
18605 might refer to by offset later during partial symbol reading.
18607 For now this means things that might have be the target of a
18608 DW_AT_specification, DW_AT_abstract_origin, or
18609 DW_AT_extension. DW_AT_extension will refer only to
18610 namespaces; DW_AT_abstract_origin refers to functions (and
18611 many things under the function DIE, but we do not recurse
18612 into function DIEs during partial symbol reading) and
18613 possibly variables as well; DW_AT_specification refers to
18614 declarations. Declarations ought to have the DW_AT_declaration
18615 flag. It happens that GCC forgets to put it in sometimes, but
18616 only for functions, not for types.
18618 Adding more things than necessary to the hash table is harmless
18619 except for the performance cost. Adding too few will result in
18620 wasted time in find_partial_die, when we reread the compilation
18621 unit with load_all_dies set. */
18624 || abbrev
->tag
== DW_TAG_constant
18625 || abbrev
->tag
== DW_TAG_subprogram
18626 || abbrev
->tag
== DW_TAG_variable
18627 || abbrev
->tag
== DW_TAG_namespace
18628 || part_die
->is_declaration
)
18632 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18633 to_underlying (part_die
->sect_off
),
18638 /* For some DIEs we want to follow their children (if any). For C
18639 we have no reason to follow the children of structures; for other
18640 languages we have to, so that we can get at method physnames
18641 to infer fully qualified class names, for DW_AT_specification,
18642 and for C++ template arguments. For C++, we also look one level
18643 inside functions to find template arguments (if the name of the
18644 function does not already contain the template arguments).
18646 For Ada and Fortran, we need to scan the children of subprograms
18647 and lexical blocks as well because these languages allow the
18648 definition of nested entities that could be interesting for the
18649 debugger, such as nested subprograms for instance. */
18650 if (last_die
->has_children
18652 || last_die
->tag
== DW_TAG_namespace
18653 || last_die
->tag
== DW_TAG_module
18654 || last_die
->tag
== DW_TAG_enumeration_type
18655 || (cu
->language
== language_cplus
18656 && last_die
->tag
== DW_TAG_subprogram
18657 && (last_die
->name
== NULL
18658 || strchr (last_die
->name
, '<') == NULL
))
18659 || (cu
->language
!= language_c
18660 && (last_die
->tag
== DW_TAG_class_type
18661 || last_die
->tag
== DW_TAG_interface_type
18662 || last_die
->tag
== DW_TAG_structure_type
18663 || last_die
->tag
== DW_TAG_union_type
))
18664 || ((cu
->language
== language_ada
18665 || cu
->language
== language_fortran
)
18666 && (last_die
->tag
== DW_TAG_subprogram
18667 || last_die
->tag
== DW_TAG_lexical_block
))))
18670 parent_die
= last_die
;
18674 /* Otherwise we skip to the next sibling, if any. */
18675 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18677 /* Back to the top, do it again. */
18681 partial_die_info::partial_die_info (sect_offset sect_off_
,
18682 struct abbrev_info
*abbrev
)
18683 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18687 /* Read a minimal amount of information into the minimal die structure.
18688 INFO_PTR should point just after the initial uleb128 of a DIE. */
18691 partial_die_info::read (const struct die_reader_specs
*reader
,
18692 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18694 struct dwarf2_cu
*cu
= reader
->cu
;
18695 struct dwarf2_per_objfile
*dwarf2_per_objfile
18696 = cu
->per_cu
->dwarf2_per_objfile
;
18698 int has_low_pc_attr
= 0;
18699 int has_high_pc_attr
= 0;
18700 int high_pc_relative
= 0;
18702 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18704 struct attribute attr
;
18706 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18708 /* Store the data if it is of an attribute we want to keep in a
18709 partial symbol table. */
18715 case DW_TAG_compile_unit
:
18716 case DW_TAG_partial_unit
:
18717 case DW_TAG_type_unit
:
18718 /* Compilation units have a DW_AT_name that is a filename, not
18719 a source language identifier. */
18720 case DW_TAG_enumeration_type
:
18721 case DW_TAG_enumerator
:
18722 /* These tags always have simple identifiers already; no need
18723 to canonicalize them. */
18724 name
= DW_STRING (&attr
);
18728 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18731 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18732 &objfile
->per_bfd
->storage_obstack
);
18737 case DW_AT_linkage_name
:
18738 case DW_AT_MIPS_linkage_name
:
18739 /* Note that both forms of linkage name might appear. We
18740 assume they will be the same, and we only store the last
18742 linkage_name
= DW_STRING (&attr
);
18745 has_low_pc_attr
= 1;
18746 lowpc
= attr_value_as_address (&attr
);
18748 case DW_AT_high_pc
:
18749 has_high_pc_attr
= 1;
18750 highpc
= attr_value_as_address (&attr
);
18751 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18752 high_pc_relative
= 1;
18754 case DW_AT_location
:
18755 /* Support the .debug_loc offsets. */
18756 if (attr_form_is_block (&attr
))
18758 d
.locdesc
= DW_BLOCK (&attr
);
18760 else if (attr_form_is_section_offset (&attr
))
18762 dwarf2_complex_location_expr_complaint ();
18766 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18767 "partial symbol information");
18770 case DW_AT_external
:
18771 is_external
= DW_UNSND (&attr
);
18773 case DW_AT_declaration
:
18774 is_declaration
= DW_UNSND (&attr
);
18779 case DW_AT_abstract_origin
:
18780 case DW_AT_specification
:
18781 case DW_AT_extension
:
18782 has_specification
= 1;
18783 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18784 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18785 || cu
->per_cu
->is_dwz
);
18787 case DW_AT_sibling
:
18788 /* Ignore absolute siblings, they might point outside of
18789 the current compile unit. */
18790 if (attr
.form
== DW_FORM_ref_addr
)
18791 complaint (_("ignoring absolute DW_AT_sibling"));
18794 const gdb_byte
*buffer
= reader
->buffer
;
18795 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18796 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18798 if (sibling_ptr
< info_ptr
)
18799 complaint (_("DW_AT_sibling points backwards"));
18800 else if (sibling_ptr
> reader
->buffer_end
)
18801 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18803 sibling
= sibling_ptr
;
18806 case DW_AT_byte_size
:
18809 case DW_AT_const_value
:
18810 has_const_value
= 1;
18812 case DW_AT_calling_convention
:
18813 /* DWARF doesn't provide a way to identify a program's source-level
18814 entry point. DW_AT_calling_convention attributes are only meant
18815 to describe functions' calling conventions.
18817 However, because it's a necessary piece of information in
18818 Fortran, and before DWARF 4 DW_CC_program was the only
18819 piece of debugging information whose definition refers to
18820 a 'main program' at all, several compilers marked Fortran
18821 main programs with DW_CC_program --- even when those
18822 functions use the standard calling conventions.
18824 Although DWARF now specifies a way to provide this
18825 information, we support this practice for backward
18827 if (DW_UNSND (&attr
) == DW_CC_program
18828 && cu
->language
== language_fortran
)
18829 main_subprogram
= 1;
18832 if (DW_UNSND (&attr
) == DW_INL_inlined
18833 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18834 may_be_inlined
= 1;
18838 if (tag
== DW_TAG_imported_unit
)
18840 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18841 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18842 || cu
->per_cu
->is_dwz
);
18846 case DW_AT_main_subprogram
:
18847 main_subprogram
= DW_UNSND (&attr
);
18852 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18853 but that requires a full DIE, so instead we just
18855 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18856 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18857 + (need_ranges_base
18861 /* Value of the DW_AT_ranges attribute is the offset in the
18862 .debug_ranges section. */
18863 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18874 /* For Ada, if both the name and the linkage name appear, we prefer
18875 the latter. This lets "catch exception" work better, regardless
18876 of the order in which the name and linkage name were emitted.
18877 Really, though, this is just a workaround for the fact that gdb
18878 doesn't store both the name and the linkage name. */
18879 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18880 name
= linkage_name
;
18882 if (high_pc_relative
)
18885 if (has_low_pc_attr
&& has_high_pc_attr
)
18887 /* When using the GNU linker, .gnu.linkonce. sections are used to
18888 eliminate duplicate copies of functions and vtables and such.
18889 The linker will arbitrarily choose one and discard the others.
18890 The AT_*_pc values for such functions refer to local labels in
18891 these sections. If the section from that file was discarded, the
18892 labels are not in the output, so the relocs get a value of 0.
18893 If this is a discarded function, mark the pc bounds as invalid,
18894 so that GDB will ignore it. */
18895 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18897 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18898 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18900 complaint (_("DW_AT_low_pc %s is zero "
18901 "for DIE at %s [in module %s]"),
18902 paddress (gdbarch
, lowpc
),
18903 sect_offset_str (sect_off
),
18904 objfile_name (objfile
));
18906 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18907 else if (lowpc
>= highpc
)
18909 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18910 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18912 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18913 "for DIE at %s [in module %s]"),
18914 paddress (gdbarch
, lowpc
),
18915 paddress (gdbarch
, highpc
),
18916 sect_offset_str (sect_off
),
18917 objfile_name (objfile
));
18926 /* Find a cached partial DIE at OFFSET in CU. */
18928 struct partial_die_info
*
18929 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18931 struct partial_die_info
*lookup_die
= NULL
;
18932 struct partial_die_info
part_die (sect_off
);
18934 lookup_die
= ((struct partial_die_info
*)
18935 htab_find_with_hash (partial_dies
, &part_die
,
18936 to_underlying (sect_off
)));
18941 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18942 except in the case of .debug_types DIEs which do not reference
18943 outside their CU (they do however referencing other types via
18944 DW_FORM_ref_sig8). */
18946 static const struct cu_partial_die_info
18947 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18949 struct dwarf2_per_objfile
*dwarf2_per_objfile
18950 = cu
->per_cu
->dwarf2_per_objfile
;
18951 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18952 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18953 struct partial_die_info
*pd
= NULL
;
18955 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18956 && offset_in_cu_p (&cu
->header
, sect_off
))
18958 pd
= cu
->find_partial_die (sect_off
);
18961 /* We missed recording what we needed.
18962 Load all dies and try again. */
18963 per_cu
= cu
->per_cu
;
18967 /* TUs don't reference other CUs/TUs (except via type signatures). */
18968 if (cu
->per_cu
->is_debug_types
)
18970 error (_("Dwarf Error: Type Unit at offset %s contains"
18971 " external reference to offset %s [in module %s].\n"),
18972 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18973 bfd_get_filename (objfile
->obfd
));
18975 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18976 dwarf2_per_objfile
);
18978 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18979 load_partial_comp_unit (per_cu
);
18981 per_cu
->cu
->last_used
= 0;
18982 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18985 /* If we didn't find it, and not all dies have been loaded,
18986 load them all and try again. */
18988 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18990 per_cu
->load_all_dies
= 1;
18992 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18993 THIS_CU->cu may already be in use. So we can't just free it and
18994 replace its DIEs with the ones we read in. Instead, we leave those
18995 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18996 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18998 load_partial_comp_unit (per_cu
);
19000 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19004 internal_error (__FILE__
, __LINE__
,
19005 _("could not find partial DIE %s "
19006 "in cache [from module %s]\n"),
19007 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19008 return { per_cu
->cu
, pd
};
19011 /* See if we can figure out if the class lives in a namespace. We do
19012 this by looking for a member function; its demangled name will
19013 contain namespace info, if there is any. */
19016 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19017 struct dwarf2_cu
*cu
)
19019 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19020 what template types look like, because the demangler
19021 frequently doesn't give the same name as the debug info. We
19022 could fix this by only using the demangled name to get the
19023 prefix (but see comment in read_structure_type). */
19025 struct partial_die_info
*real_pdi
;
19026 struct partial_die_info
*child_pdi
;
19028 /* If this DIE (this DIE's specification, if any) has a parent, then
19029 we should not do this. We'll prepend the parent's fully qualified
19030 name when we create the partial symbol. */
19032 real_pdi
= struct_pdi
;
19033 while (real_pdi
->has_specification
)
19035 auto res
= find_partial_die (real_pdi
->spec_offset
,
19036 real_pdi
->spec_is_dwz
, cu
);
19037 real_pdi
= res
.pdi
;
19041 if (real_pdi
->die_parent
!= NULL
)
19044 for (child_pdi
= struct_pdi
->die_child
;
19046 child_pdi
= child_pdi
->die_sibling
)
19048 if (child_pdi
->tag
== DW_TAG_subprogram
19049 && child_pdi
->linkage_name
!= NULL
)
19051 char *actual_class_name
19052 = language_class_name_from_physname (cu
->language_defn
,
19053 child_pdi
->linkage_name
);
19054 if (actual_class_name
!= NULL
)
19056 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19058 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
19059 actual_class_name
);
19060 xfree (actual_class_name
);
19068 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19070 /* Once we've fixed up a die, there's no point in doing so again.
19071 This also avoids a memory leak if we were to call
19072 guess_partial_die_structure_name multiple times. */
19076 /* If we found a reference attribute and the DIE has no name, try
19077 to find a name in the referred to DIE. */
19079 if (name
== NULL
&& has_specification
)
19081 struct partial_die_info
*spec_die
;
19083 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19084 spec_die
= res
.pdi
;
19087 spec_die
->fixup (cu
);
19089 if (spec_die
->name
)
19091 name
= spec_die
->name
;
19093 /* Copy DW_AT_external attribute if it is set. */
19094 if (spec_die
->is_external
)
19095 is_external
= spec_die
->is_external
;
19099 /* Set default names for some unnamed DIEs. */
19101 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19102 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19104 /* If there is no parent die to provide a namespace, and there are
19105 children, see if we can determine the namespace from their linkage
19107 if (cu
->language
== language_cplus
19108 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
19109 && die_parent
== NULL
19111 && (tag
== DW_TAG_class_type
19112 || tag
== DW_TAG_structure_type
19113 || tag
== DW_TAG_union_type
))
19114 guess_partial_die_structure_name (this, cu
);
19116 /* GCC might emit a nameless struct or union that has a linkage
19117 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19119 && (tag
== DW_TAG_class_type
19120 || tag
== DW_TAG_interface_type
19121 || tag
== DW_TAG_structure_type
19122 || tag
== DW_TAG_union_type
)
19123 && linkage_name
!= NULL
)
19127 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
19132 /* Strip any leading namespaces/classes, keep only the base name.
19133 DW_AT_name for named DIEs does not contain the prefixes. */
19134 base
= strrchr (demangled
, ':');
19135 if (base
&& base
> demangled
&& base
[-1] == ':')
19140 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19141 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
19149 /* Read an attribute value described by an attribute form. */
19151 static const gdb_byte
*
19152 read_attribute_value (const struct die_reader_specs
*reader
,
19153 struct attribute
*attr
, unsigned form
,
19154 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19156 struct dwarf2_cu
*cu
= reader
->cu
;
19157 struct dwarf2_per_objfile
*dwarf2_per_objfile
19158 = cu
->per_cu
->dwarf2_per_objfile
;
19159 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19160 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19161 bfd
*abfd
= reader
->abfd
;
19162 struct comp_unit_head
*cu_header
= &cu
->header
;
19163 unsigned int bytes_read
;
19164 struct dwarf_block
*blk
;
19166 attr
->form
= (enum dwarf_form
) form
;
19169 case DW_FORM_ref_addr
:
19170 if (cu
->header
.version
== 2)
19171 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19173 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19174 &cu
->header
, &bytes_read
);
19175 info_ptr
+= bytes_read
;
19177 case DW_FORM_GNU_ref_alt
:
19178 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19179 info_ptr
+= bytes_read
;
19182 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19183 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19184 info_ptr
+= bytes_read
;
19186 case DW_FORM_block2
:
19187 blk
= dwarf_alloc_block (cu
);
19188 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19190 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19191 info_ptr
+= blk
->size
;
19192 DW_BLOCK (attr
) = blk
;
19194 case DW_FORM_block4
:
19195 blk
= dwarf_alloc_block (cu
);
19196 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19198 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19199 info_ptr
+= blk
->size
;
19200 DW_BLOCK (attr
) = blk
;
19202 case DW_FORM_data2
:
19203 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19206 case DW_FORM_data4
:
19207 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19210 case DW_FORM_data8
:
19211 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19214 case DW_FORM_data16
:
19215 blk
= dwarf_alloc_block (cu
);
19217 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19219 DW_BLOCK (attr
) = blk
;
19221 case DW_FORM_sec_offset
:
19222 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19223 info_ptr
+= bytes_read
;
19225 case DW_FORM_string
:
19226 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19227 DW_STRING_IS_CANONICAL (attr
) = 0;
19228 info_ptr
+= bytes_read
;
19231 if (!cu
->per_cu
->is_dwz
)
19233 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19234 abfd
, info_ptr
, cu_header
,
19236 DW_STRING_IS_CANONICAL (attr
) = 0;
19237 info_ptr
+= bytes_read
;
19241 case DW_FORM_line_strp
:
19242 if (!cu
->per_cu
->is_dwz
)
19244 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19246 cu_header
, &bytes_read
);
19247 DW_STRING_IS_CANONICAL (attr
) = 0;
19248 info_ptr
+= bytes_read
;
19252 case DW_FORM_GNU_strp_alt
:
19254 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19255 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19258 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19260 DW_STRING_IS_CANONICAL (attr
) = 0;
19261 info_ptr
+= bytes_read
;
19264 case DW_FORM_exprloc
:
19265 case DW_FORM_block
:
19266 blk
= dwarf_alloc_block (cu
);
19267 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19268 info_ptr
+= bytes_read
;
19269 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19270 info_ptr
+= blk
->size
;
19271 DW_BLOCK (attr
) = blk
;
19273 case DW_FORM_block1
:
19274 blk
= dwarf_alloc_block (cu
);
19275 blk
->size
= read_1_byte (abfd
, info_ptr
);
19277 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19278 info_ptr
+= blk
->size
;
19279 DW_BLOCK (attr
) = blk
;
19281 case DW_FORM_data1
:
19282 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19286 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19289 case DW_FORM_flag_present
:
19290 DW_UNSND (attr
) = 1;
19292 case DW_FORM_sdata
:
19293 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19294 info_ptr
+= bytes_read
;
19296 case DW_FORM_udata
:
19297 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19298 info_ptr
+= bytes_read
;
19301 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19302 + read_1_byte (abfd
, info_ptr
));
19306 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19307 + read_2_bytes (abfd
, info_ptr
));
19311 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19312 + read_4_bytes (abfd
, info_ptr
));
19316 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19317 + read_8_bytes (abfd
, info_ptr
));
19320 case DW_FORM_ref_sig8
:
19321 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19324 case DW_FORM_ref_udata
:
19325 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19326 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19327 info_ptr
+= bytes_read
;
19329 case DW_FORM_indirect
:
19330 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19331 info_ptr
+= bytes_read
;
19332 if (form
== DW_FORM_implicit_const
)
19334 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19335 info_ptr
+= bytes_read
;
19337 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19340 case DW_FORM_implicit_const
:
19341 DW_SND (attr
) = implicit_const
;
19343 case DW_FORM_addrx
:
19344 case DW_FORM_GNU_addr_index
:
19345 if (reader
->dwo_file
== NULL
)
19347 /* For now flag a hard error.
19348 Later we can turn this into a complaint. */
19349 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19350 dwarf_form_name (form
),
19351 bfd_get_filename (abfd
));
19353 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19354 info_ptr
+= bytes_read
;
19357 case DW_FORM_strx1
:
19358 case DW_FORM_strx2
:
19359 case DW_FORM_strx3
:
19360 case DW_FORM_strx4
:
19361 case DW_FORM_GNU_str_index
:
19362 if (reader
->dwo_file
== NULL
)
19364 /* For now flag a hard error.
19365 Later we can turn this into a complaint if warranted. */
19366 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19367 dwarf_form_name (form
),
19368 bfd_get_filename (abfd
));
19371 ULONGEST str_index
;
19372 if (form
== DW_FORM_strx1
)
19374 str_index
= read_1_byte (abfd
, info_ptr
);
19377 else if (form
== DW_FORM_strx2
)
19379 str_index
= read_2_bytes (abfd
, info_ptr
);
19382 else if (form
== DW_FORM_strx3
)
19384 str_index
= read_3_bytes (abfd
, info_ptr
);
19387 else if (form
== DW_FORM_strx4
)
19389 str_index
= read_4_bytes (abfd
, info_ptr
);
19394 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19395 info_ptr
+= bytes_read
;
19397 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19398 DW_STRING_IS_CANONICAL (attr
) = 0;
19402 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19403 dwarf_form_name (form
),
19404 bfd_get_filename (abfd
));
19408 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19409 attr
->form
= DW_FORM_GNU_ref_alt
;
19411 /* We have seen instances where the compiler tried to emit a byte
19412 size attribute of -1 which ended up being encoded as an unsigned
19413 0xffffffff. Although 0xffffffff is technically a valid size value,
19414 an object of this size seems pretty unlikely so we can relatively
19415 safely treat these cases as if the size attribute was invalid and
19416 treat them as zero by default. */
19417 if (attr
->name
== DW_AT_byte_size
19418 && form
== DW_FORM_data4
19419 && DW_UNSND (attr
) >= 0xffffffff)
19422 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19423 hex_string (DW_UNSND (attr
)));
19424 DW_UNSND (attr
) = 0;
19430 /* Read an attribute described by an abbreviated attribute. */
19432 static const gdb_byte
*
19433 read_attribute (const struct die_reader_specs
*reader
,
19434 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19435 const gdb_byte
*info_ptr
)
19437 attr
->name
= abbrev
->name
;
19438 return read_attribute_value (reader
, attr
, abbrev
->form
,
19439 abbrev
->implicit_const
, info_ptr
);
19442 /* Read dwarf information from a buffer. */
19444 static unsigned int
19445 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19447 return bfd_get_8 (abfd
, buf
);
19451 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19453 return bfd_get_signed_8 (abfd
, buf
);
19456 static unsigned int
19457 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19459 return bfd_get_16 (abfd
, buf
);
19463 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19465 return bfd_get_signed_16 (abfd
, buf
);
19468 static unsigned int
19469 read_3_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19471 unsigned int result
= 0;
19472 for (int i
= 0; i
< 3; ++i
)
19474 unsigned char byte
= bfd_get_8 (abfd
, buf
);
19476 result
|= ((unsigned int) byte
<< (i
* 8));
19481 static unsigned int
19482 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19484 return bfd_get_32 (abfd
, buf
);
19488 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19490 return bfd_get_signed_32 (abfd
, buf
);
19494 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19496 return bfd_get_64 (abfd
, buf
);
19500 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19501 unsigned int *bytes_read
)
19503 struct comp_unit_head
*cu_header
= &cu
->header
;
19504 CORE_ADDR retval
= 0;
19506 if (cu_header
->signed_addr_p
)
19508 switch (cu_header
->addr_size
)
19511 retval
= bfd_get_signed_16 (abfd
, buf
);
19514 retval
= bfd_get_signed_32 (abfd
, buf
);
19517 retval
= bfd_get_signed_64 (abfd
, buf
);
19520 internal_error (__FILE__
, __LINE__
,
19521 _("read_address: bad switch, signed [in module %s]"),
19522 bfd_get_filename (abfd
));
19527 switch (cu_header
->addr_size
)
19530 retval
= bfd_get_16 (abfd
, buf
);
19533 retval
= bfd_get_32 (abfd
, buf
);
19536 retval
= bfd_get_64 (abfd
, buf
);
19539 internal_error (__FILE__
, __LINE__
,
19540 _("read_address: bad switch, "
19541 "unsigned [in module %s]"),
19542 bfd_get_filename (abfd
));
19546 *bytes_read
= cu_header
->addr_size
;
19550 /* Read the initial length from a section. The (draft) DWARF 3
19551 specification allows the initial length to take up either 4 bytes
19552 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19553 bytes describe the length and all offsets will be 8 bytes in length
19556 An older, non-standard 64-bit format is also handled by this
19557 function. The older format in question stores the initial length
19558 as an 8-byte quantity without an escape value. Lengths greater
19559 than 2^32 aren't very common which means that the initial 4 bytes
19560 is almost always zero. Since a length value of zero doesn't make
19561 sense for the 32-bit format, this initial zero can be considered to
19562 be an escape value which indicates the presence of the older 64-bit
19563 format. As written, the code can't detect (old format) lengths
19564 greater than 4GB. If it becomes necessary to handle lengths
19565 somewhat larger than 4GB, we could allow other small values (such
19566 as the non-sensical values of 1, 2, and 3) to also be used as
19567 escape values indicating the presence of the old format.
19569 The value returned via bytes_read should be used to increment the
19570 relevant pointer after calling read_initial_length().
19572 [ Note: read_initial_length() and read_offset() are based on the
19573 document entitled "DWARF Debugging Information Format", revision
19574 3, draft 8, dated November 19, 2001. This document was obtained
19577 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19579 This document is only a draft and is subject to change. (So beware.)
19581 Details regarding the older, non-standard 64-bit format were
19582 determined empirically by examining 64-bit ELF files produced by
19583 the SGI toolchain on an IRIX 6.5 machine.
19585 - Kevin, July 16, 2002
19589 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19591 LONGEST length
= bfd_get_32 (abfd
, buf
);
19593 if (length
== 0xffffffff)
19595 length
= bfd_get_64 (abfd
, buf
+ 4);
19598 else if (length
== 0)
19600 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19601 length
= bfd_get_64 (abfd
, buf
);
19612 /* Cover function for read_initial_length.
19613 Returns the length of the object at BUF, and stores the size of the
19614 initial length in *BYTES_READ and stores the size that offsets will be in
19616 If the initial length size is not equivalent to that specified in
19617 CU_HEADER then issue a complaint.
19618 This is useful when reading non-comp-unit headers. */
19621 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19622 const struct comp_unit_head
*cu_header
,
19623 unsigned int *bytes_read
,
19624 unsigned int *offset_size
)
19626 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19628 gdb_assert (cu_header
->initial_length_size
== 4
19629 || cu_header
->initial_length_size
== 8
19630 || cu_header
->initial_length_size
== 12);
19632 if (cu_header
->initial_length_size
!= *bytes_read
)
19633 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19635 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19639 /* Read an offset from the data stream. The size of the offset is
19640 given by cu_header->offset_size. */
19643 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19644 const struct comp_unit_head
*cu_header
,
19645 unsigned int *bytes_read
)
19647 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19649 *bytes_read
= cu_header
->offset_size
;
19653 /* Read an offset from the data stream. */
19656 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19658 LONGEST retval
= 0;
19660 switch (offset_size
)
19663 retval
= bfd_get_32 (abfd
, buf
);
19666 retval
= bfd_get_64 (abfd
, buf
);
19669 internal_error (__FILE__
, __LINE__
,
19670 _("read_offset_1: bad switch [in module %s]"),
19671 bfd_get_filename (abfd
));
19677 static const gdb_byte
*
19678 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19680 /* If the size of a host char is 8 bits, we can return a pointer
19681 to the buffer, otherwise we have to copy the data to a buffer
19682 allocated on the temporary obstack. */
19683 gdb_assert (HOST_CHAR_BIT
== 8);
19687 static const char *
19688 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19689 unsigned int *bytes_read_ptr
)
19691 /* If the size of a host char is 8 bits, we can return a pointer
19692 to the string, otherwise we have to copy the string to a buffer
19693 allocated on the temporary obstack. */
19694 gdb_assert (HOST_CHAR_BIT
== 8);
19697 *bytes_read_ptr
= 1;
19700 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19701 return (const char *) buf
;
19704 /* Return pointer to string at section SECT offset STR_OFFSET with error
19705 reporting strings FORM_NAME and SECT_NAME. */
19707 static const char *
19708 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19709 bfd
*abfd
, LONGEST str_offset
,
19710 struct dwarf2_section_info
*sect
,
19711 const char *form_name
,
19712 const char *sect_name
)
19714 dwarf2_read_section (objfile
, sect
);
19715 if (sect
->buffer
== NULL
)
19716 error (_("%s used without %s section [in module %s]"),
19717 form_name
, sect_name
, bfd_get_filename (abfd
));
19718 if (str_offset
>= sect
->size
)
19719 error (_("%s pointing outside of %s section [in module %s]"),
19720 form_name
, sect_name
, bfd_get_filename (abfd
));
19721 gdb_assert (HOST_CHAR_BIT
== 8);
19722 if (sect
->buffer
[str_offset
] == '\0')
19724 return (const char *) (sect
->buffer
+ str_offset
);
19727 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19729 static const char *
19730 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19731 bfd
*abfd
, LONGEST str_offset
)
19733 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19735 &dwarf2_per_objfile
->str
,
19736 "DW_FORM_strp", ".debug_str");
19739 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19741 static const char *
19742 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19743 bfd
*abfd
, LONGEST str_offset
)
19745 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19747 &dwarf2_per_objfile
->line_str
,
19748 "DW_FORM_line_strp",
19749 ".debug_line_str");
19752 /* Read a string at offset STR_OFFSET in the .debug_str section from
19753 the .dwz file DWZ. Throw an error if the offset is too large. If
19754 the string consists of a single NUL byte, return NULL; otherwise
19755 return a pointer to the string. */
19757 static const char *
19758 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19759 LONGEST str_offset
)
19761 dwarf2_read_section (objfile
, &dwz
->str
);
19763 if (dwz
->str
.buffer
== NULL
)
19764 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19765 "section [in module %s]"),
19766 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19767 if (str_offset
>= dwz
->str
.size
)
19768 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19769 ".debug_str section [in module %s]"),
19770 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19771 gdb_assert (HOST_CHAR_BIT
== 8);
19772 if (dwz
->str
.buffer
[str_offset
] == '\0')
19774 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19777 /* Return pointer to string at .debug_str offset as read from BUF.
19778 BUF is assumed to be in a compilation unit described by CU_HEADER.
19779 Return *BYTES_READ_PTR count of bytes read from BUF. */
19781 static const char *
19782 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19783 const gdb_byte
*buf
,
19784 const struct comp_unit_head
*cu_header
,
19785 unsigned int *bytes_read_ptr
)
19787 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19789 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19792 /* Return pointer to string at .debug_line_str offset as read from BUF.
19793 BUF is assumed to be in a compilation unit described by CU_HEADER.
19794 Return *BYTES_READ_PTR count of bytes read from BUF. */
19796 static const char *
19797 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19798 bfd
*abfd
, const gdb_byte
*buf
,
19799 const struct comp_unit_head
*cu_header
,
19800 unsigned int *bytes_read_ptr
)
19802 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19804 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19809 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19810 unsigned int *bytes_read_ptr
)
19813 unsigned int num_read
;
19815 unsigned char byte
;
19822 byte
= bfd_get_8 (abfd
, buf
);
19825 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19826 if ((byte
& 128) == 0)
19832 *bytes_read_ptr
= num_read
;
19837 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19838 unsigned int *bytes_read_ptr
)
19841 int shift
, num_read
;
19842 unsigned char byte
;
19849 byte
= bfd_get_8 (abfd
, buf
);
19852 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19854 if ((byte
& 128) == 0)
19859 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19860 result
|= -(((ULONGEST
) 1) << shift
);
19861 *bytes_read_ptr
= num_read
;
19865 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19866 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
19867 ADDR_SIZE is the size of addresses from the CU header. */
19870 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19871 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
19873 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19874 bfd
*abfd
= objfile
->obfd
;
19875 const gdb_byte
*info_ptr
;
19877 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
19878 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19879 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19880 objfile_name (objfile
));
19881 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
19882 error (_("DW_FORM_addr_index pointing outside of "
19883 ".debug_addr section [in module %s]"),
19884 objfile_name (objfile
));
19885 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19886 + addr_base
+ addr_index
* addr_size
);
19887 if (addr_size
== 4)
19888 return bfd_get_32 (abfd
, info_ptr
);
19890 return bfd_get_64 (abfd
, info_ptr
);
19893 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19896 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19898 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19899 cu
->addr_base
, cu
->header
.addr_size
);
19902 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19905 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19906 unsigned int *bytes_read
)
19908 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19909 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19911 return read_addr_index (cu
, addr_index
);
19914 /* Data structure to pass results from dwarf2_read_addr_index_reader
19915 back to dwarf2_read_addr_index. */
19917 struct dwarf2_read_addr_index_data
19919 ULONGEST addr_base
;
19923 /* die_reader_func for dwarf2_read_addr_index. */
19926 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
19927 const gdb_byte
*info_ptr
,
19928 struct die_info
*comp_unit_die
,
19932 struct dwarf2_cu
*cu
= reader
->cu
;
19933 struct dwarf2_read_addr_index_data
*aidata
=
19934 (struct dwarf2_read_addr_index_data
*) data
;
19936 aidata
->addr_base
= cu
->addr_base
;
19937 aidata
->addr_size
= cu
->header
.addr_size
;
19940 /* Given an index in .debug_addr, fetch the value.
19941 NOTE: This can be called during dwarf expression evaluation,
19942 long after the debug information has been read, and thus per_cu->cu
19943 may no longer exist. */
19946 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19947 unsigned int addr_index
)
19949 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19950 struct dwarf2_cu
*cu
= per_cu
->cu
;
19951 ULONGEST addr_base
;
19954 /* We need addr_base and addr_size.
19955 If we don't have PER_CU->cu, we have to get it.
19956 Nasty, but the alternative is storing the needed info in PER_CU,
19957 which at this point doesn't seem justified: it's not clear how frequently
19958 it would get used and it would increase the size of every PER_CU.
19959 Entry points like dwarf2_per_cu_addr_size do a similar thing
19960 so we're not in uncharted territory here.
19961 Alas we need to be a bit more complicated as addr_base is contained
19964 We don't need to read the entire CU(/TU).
19965 We just need the header and top level die.
19967 IWBN to use the aging mechanism to let us lazily later discard the CU.
19968 For now we skip this optimization. */
19972 addr_base
= cu
->addr_base
;
19973 addr_size
= cu
->header
.addr_size
;
19977 struct dwarf2_read_addr_index_data aidata
;
19979 /* Note: We can't use init_cutu_and_read_dies_simple here,
19980 we need addr_base. */
19981 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0, false,
19982 dwarf2_read_addr_index_reader
, &aidata
);
19983 addr_base
= aidata
.addr_base
;
19984 addr_size
= aidata
.addr_size
;
19987 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19991 /* Given a DW_FORM_GNU_str_index or DW_FORM_strx, fetch the string.
19992 This is only used by the Fission support. */
19994 static const char *
19995 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19997 struct dwarf2_cu
*cu
= reader
->cu
;
19998 struct dwarf2_per_objfile
*dwarf2_per_objfile
19999 = cu
->per_cu
->dwarf2_per_objfile
;
20000 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20001 const char *objf_name
= objfile_name (objfile
);
20002 bfd
*abfd
= objfile
->obfd
;
20003 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
20004 struct dwarf2_section_info
*str_offsets_section
=
20005 &reader
->dwo_file
->sections
.str_offsets
;
20006 const gdb_byte
*info_ptr
;
20007 ULONGEST str_offset
;
20008 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20010 dwarf2_read_section (objfile
, str_section
);
20011 dwarf2_read_section (objfile
, str_offsets_section
);
20012 if (str_section
->buffer
== NULL
)
20013 error (_("%s used without .debug_str.dwo section"
20014 " in CU at offset %s [in module %s]"),
20015 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20016 if (str_offsets_section
->buffer
== NULL
)
20017 error (_("%s used without .debug_str_offsets.dwo section"
20018 " in CU at offset %s [in module %s]"),
20019 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20020 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
20021 error (_("%s pointing outside of .debug_str_offsets.dwo"
20022 " section in CU at offset %s [in module %s]"),
20023 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20024 info_ptr
= (str_offsets_section
->buffer
20025 + str_index
* cu
->header
.offset_size
);
20026 if (cu
->header
.offset_size
== 4)
20027 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20029 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20030 if (str_offset
>= str_section
->size
)
20031 error (_("Offset from %s pointing outside of"
20032 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20033 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20034 return (const char *) (str_section
->buffer
+ str_offset
);
20037 /* Return the length of an LEB128 number in BUF. */
20040 leb128_size (const gdb_byte
*buf
)
20042 const gdb_byte
*begin
= buf
;
20048 if ((byte
& 128) == 0)
20049 return buf
- begin
;
20054 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20063 cu
->language
= language_c
;
20066 case DW_LANG_C_plus_plus
:
20067 case DW_LANG_C_plus_plus_11
:
20068 case DW_LANG_C_plus_plus_14
:
20069 cu
->language
= language_cplus
;
20072 cu
->language
= language_d
;
20074 case DW_LANG_Fortran77
:
20075 case DW_LANG_Fortran90
:
20076 case DW_LANG_Fortran95
:
20077 case DW_LANG_Fortran03
:
20078 case DW_LANG_Fortran08
:
20079 cu
->language
= language_fortran
;
20082 cu
->language
= language_go
;
20084 case DW_LANG_Mips_Assembler
:
20085 cu
->language
= language_asm
;
20087 case DW_LANG_Ada83
:
20088 case DW_LANG_Ada95
:
20089 cu
->language
= language_ada
;
20091 case DW_LANG_Modula2
:
20092 cu
->language
= language_m2
;
20094 case DW_LANG_Pascal83
:
20095 cu
->language
= language_pascal
;
20098 cu
->language
= language_objc
;
20101 case DW_LANG_Rust_old
:
20102 cu
->language
= language_rust
;
20104 case DW_LANG_Cobol74
:
20105 case DW_LANG_Cobol85
:
20107 cu
->language
= language_minimal
;
20110 cu
->language_defn
= language_def (cu
->language
);
20113 /* Return the named attribute or NULL if not there. */
20115 static struct attribute
*
20116 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20121 struct attribute
*spec
= NULL
;
20123 for (i
= 0; i
< die
->num_attrs
; ++i
)
20125 if (die
->attrs
[i
].name
== name
)
20126 return &die
->attrs
[i
];
20127 if (die
->attrs
[i
].name
== DW_AT_specification
20128 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20129 spec
= &die
->attrs
[i
];
20135 die
= follow_die_ref (die
, spec
, &cu
);
20141 /* Return the named attribute or NULL if not there,
20142 but do not follow DW_AT_specification, etc.
20143 This is for use in contexts where we're reading .debug_types dies.
20144 Following DW_AT_specification, DW_AT_abstract_origin will take us
20145 back up the chain, and we want to go down. */
20147 static struct attribute
*
20148 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20152 for (i
= 0; i
< die
->num_attrs
; ++i
)
20153 if (die
->attrs
[i
].name
== name
)
20154 return &die
->attrs
[i
];
20159 /* Return the string associated with a string-typed attribute, or NULL if it
20160 is either not found or is of an incorrect type. */
20162 static const char *
20163 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20165 struct attribute
*attr
;
20166 const char *str
= NULL
;
20168 attr
= dwarf2_attr (die
, name
, cu
);
20172 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20173 || attr
->form
== DW_FORM_string
20174 || attr
->form
== DW_FORM_strx
20175 || attr
->form
== DW_FORM_strx1
20176 || attr
->form
== DW_FORM_strx2
20177 || attr
->form
== DW_FORM_strx3
20178 || attr
->form
== DW_FORM_strx4
20179 || attr
->form
== DW_FORM_GNU_str_index
20180 || attr
->form
== DW_FORM_GNU_strp_alt
)
20181 str
= DW_STRING (attr
);
20183 complaint (_("string type expected for attribute %s for "
20184 "DIE at %s in module %s"),
20185 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20186 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20192 /* Return the dwo name or NULL if not present. If present, it is in either
20193 DW_AT_GNU_dwo_name or DW_AT_dwo_name atrribute. */
20194 static const char *
20195 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20197 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20198 if (dwo_name
== nullptr)
20199 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20203 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20204 and holds a non-zero value. This function should only be used for
20205 DW_FORM_flag or DW_FORM_flag_present attributes. */
20208 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20210 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20212 return (attr
&& DW_UNSND (attr
));
20216 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20218 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20219 which value is non-zero. However, we have to be careful with
20220 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20221 (via dwarf2_flag_true_p) follows this attribute. So we may
20222 end up accidently finding a declaration attribute that belongs
20223 to a different DIE referenced by the specification attribute,
20224 even though the given DIE does not have a declaration attribute. */
20225 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20226 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20229 /* Return the die giving the specification for DIE, if there is
20230 one. *SPEC_CU is the CU containing DIE on input, and the CU
20231 containing the return value on output. If there is no
20232 specification, but there is an abstract origin, that is
20235 static struct die_info
*
20236 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20238 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20241 if (spec_attr
== NULL
)
20242 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20244 if (spec_attr
== NULL
)
20247 return follow_die_ref (die
, spec_attr
, spec_cu
);
20250 /* Stub for free_line_header to match void * callback types. */
20253 free_line_header_voidp (void *arg
)
20255 struct line_header
*lh
= (struct line_header
*) arg
;
20261 line_header::add_include_dir (const char *include_dir
)
20263 if (dwarf_line_debug
>= 2)
20264 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20265 include_dirs
.size () + 1, include_dir
);
20267 include_dirs
.push_back (include_dir
);
20271 line_header::add_file_name (const char *name
,
20273 unsigned int mod_time
,
20274 unsigned int length
)
20276 if (dwarf_line_debug
>= 2)
20277 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
20278 (unsigned) file_names
.size () + 1, name
);
20280 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20283 /* A convenience function to find the proper .debug_line section for a CU. */
20285 static struct dwarf2_section_info
*
20286 get_debug_line_section (struct dwarf2_cu
*cu
)
20288 struct dwarf2_section_info
*section
;
20289 struct dwarf2_per_objfile
*dwarf2_per_objfile
20290 = cu
->per_cu
->dwarf2_per_objfile
;
20292 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20294 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20295 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20296 else if (cu
->per_cu
->is_dwz
)
20298 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20300 section
= &dwz
->line
;
20303 section
= &dwarf2_per_objfile
->line
;
20308 /* Read directory or file name entry format, starting with byte of
20309 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20310 entries count and the entries themselves in the described entry
20314 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20315 bfd
*abfd
, const gdb_byte
**bufp
,
20316 struct line_header
*lh
,
20317 const struct comp_unit_head
*cu_header
,
20318 void (*callback
) (struct line_header
*lh
,
20321 unsigned int mod_time
,
20322 unsigned int length
))
20324 gdb_byte format_count
, formati
;
20325 ULONGEST data_count
, datai
;
20326 const gdb_byte
*buf
= *bufp
;
20327 const gdb_byte
*format_header_data
;
20328 unsigned int bytes_read
;
20330 format_count
= read_1_byte (abfd
, buf
);
20332 format_header_data
= buf
;
20333 for (formati
= 0; formati
< format_count
; formati
++)
20335 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20337 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20341 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20343 for (datai
= 0; datai
< data_count
; datai
++)
20345 const gdb_byte
*format
= format_header_data
;
20346 struct file_entry fe
;
20348 for (formati
= 0; formati
< format_count
; formati
++)
20350 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20351 format
+= bytes_read
;
20353 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20354 format
+= bytes_read
;
20356 gdb::optional
<const char *> string
;
20357 gdb::optional
<unsigned int> uint
;
20361 case DW_FORM_string
:
20362 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20366 case DW_FORM_line_strp
:
20367 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20374 case DW_FORM_data1
:
20375 uint
.emplace (read_1_byte (abfd
, buf
));
20379 case DW_FORM_data2
:
20380 uint
.emplace (read_2_bytes (abfd
, buf
));
20384 case DW_FORM_data4
:
20385 uint
.emplace (read_4_bytes (abfd
, buf
));
20389 case DW_FORM_data8
:
20390 uint
.emplace (read_8_bytes (abfd
, buf
));
20394 case DW_FORM_udata
:
20395 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20399 case DW_FORM_block
:
20400 /* It is valid only for DW_LNCT_timestamp which is ignored by
20405 switch (content_type
)
20408 if (string
.has_value ())
20411 case DW_LNCT_directory_index
:
20412 if (uint
.has_value ())
20413 fe
.d_index
= (dir_index
) *uint
;
20415 case DW_LNCT_timestamp
:
20416 if (uint
.has_value ())
20417 fe
.mod_time
= *uint
;
20420 if (uint
.has_value ())
20426 complaint (_("Unknown format content type %s"),
20427 pulongest (content_type
));
20431 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20437 /* Read the statement program header starting at OFFSET in
20438 .debug_line, or .debug_line.dwo. Return a pointer
20439 to a struct line_header, allocated using xmalloc.
20440 Returns NULL if there is a problem reading the header, e.g., if it
20441 has a version we don't understand.
20443 NOTE: the strings in the include directory and file name tables of
20444 the returned object point into the dwarf line section buffer,
20445 and must not be freed. */
20447 static line_header_up
20448 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20450 const gdb_byte
*line_ptr
;
20451 unsigned int bytes_read
, offset_size
;
20453 const char *cur_dir
, *cur_file
;
20454 struct dwarf2_section_info
*section
;
20456 struct dwarf2_per_objfile
*dwarf2_per_objfile
20457 = cu
->per_cu
->dwarf2_per_objfile
;
20459 section
= get_debug_line_section (cu
);
20460 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20461 if (section
->buffer
== NULL
)
20463 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20464 complaint (_("missing .debug_line.dwo section"));
20466 complaint (_("missing .debug_line section"));
20470 /* We can't do this until we know the section is non-empty.
20471 Only then do we know we have such a section. */
20472 abfd
= get_section_bfd_owner (section
);
20474 /* Make sure that at least there's room for the total_length field.
20475 That could be 12 bytes long, but we're just going to fudge that. */
20476 if (to_underlying (sect_off
) + 4 >= section
->size
)
20478 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20482 line_header_up
lh (new line_header ());
20484 lh
->sect_off
= sect_off
;
20485 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20487 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20489 /* Read in the header. */
20491 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20492 &bytes_read
, &offset_size
);
20493 line_ptr
+= bytes_read
;
20494 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20496 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20499 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20500 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20502 if (lh
->version
> 5)
20504 /* This is a version we don't understand. The format could have
20505 changed in ways we don't handle properly so just punt. */
20506 complaint (_("unsupported version in .debug_line section"));
20509 if (lh
->version
>= 5)
20511 gdb_byte segment_selector_size
;
20513 /* Skip address size. */
20514 read_1_byte (abfd
, line_ptr
);
20517 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20519 if (segment_selector_size
!= 0)
20521 complaint (_("unsupported segment selector size %u "
20522 "in .debug_line section"),
20523 segment_selector_size
);
20527 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20528 line_ptr
+= offset_size
;
20529 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20531 if (lh
->version
>= 4)
20533 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20537 lh
->maximum_ops_per_instruction
= 1;
20539 if (lh
->maximum_ops_per_instruction
== 0)
20541 lh
->maximum_ops_per_instruction
= 1;
20542 complaint (_("invalid maximum_ops_per_instruction "
20543 "in `.debug_line' section"));
20546 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20548 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20550 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20552 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20554 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20556 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20557 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20559 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20563 if (lh
->version
>= 5)
20565 /* Read directory table. */
20566 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20568 [] (struct line_header
*header
, const char *name
,
20569 dir_index d_index
, unsigned int mod_time
,
20570 unsigned int length
)
20572 header
->add_include_dir (name
);
20575 /* Read file name table. */
20576 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20578 [] (struct line_header
*header
, const char *name
,
20579 dir_index d_index
, unsigned int mod_time
,
20580 unsigned int length
)
20582 header
->add_file_name (name
, d_index
, mod_time
, length
);
20587 /* Read directory table. */
20588 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20590 line_ptr
+= bytes_read
;
20591 lh
->add_include_dir (cur_dir
);
20593 line_ptr
+= bytes_read
;
20595 /* Read file name table. */
20596 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20598 unsigned int mod_time
, length
;
20601 line_ptr
+= bytes_read
;
20602 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20603 line_ptr
+= bytes_read
;
20604 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20605 line_ptr
+= bytes_read
;
20606 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20607 line_ptr
+= bytes_read
;
20609 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20611 line_ptr
+= bytes_read
;
20613 lh
->statement_program_start
= line_ptr
;
20615 if (line_ptr
> (section
->buffer
+ section
->size
))
20616 complaint (_("line number info header doesn't "
20617 "fit in `.debug_line' section"));
20622 /* Subroutine of dwarf_decode_lines to simplify it.
20623 Return the file name of the psymtab for included file FILE_INDEX
20624 in line header LH of PST.
20625 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20626 If space for the result is malloc'd, *NAME_HOLDER will be set.
20627 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20629 static const char *
20630 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20631 const struct partial_symtab
*pst
,
20632 const char *comp_dir
,
20633 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20635 const file_entry
&fe
= lh
->file_names
[file_index
];
20636 const char *include_name
= fe
.name
;
20637 const char *include_name_to_compare
= include_name
;
20638 const char *pst_filename
;
20641 const char *dir_name
= fe
.include_dir (lh
);
20643 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20644 if (!IS_ABSOLUTE_PATH (include_name
)
20645 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20647 /* Avoid creating a duplicate psymtab for PST.
20648 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20649 Before we do the comparison, however, we need to account
20650 for DIR_NAME and COMP_DIR.
20651 First prepend dir_name (if non-NULL). If we still don't
20652 have an absolute path prepend comp_dir (if non-NULL).
20653 However, the directory we record in the include-file's
20654 psymtab does not contain COMP_DIR (to match the
20655 corresponding symtab(s)).
20660 bash$ gcc -g ./hello.c
20661 include_name = "hello.c"
20663 DW_AT_comp_dir = comp_dir = "/tmp"
20664 DW_AT_name = "./hello.c"
20668 if (dir_name
!= NULL
)
20670 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20671 include_name
, (char *) NULL
));
20672 include_name
= name_holder
->get ();
20673 include_name_to_compare
= include_name
;
20675 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20677 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20678 include_name
, (char *) NULL
));
20679 include_name_to_compare
= hold_compare
.get ();
20683 pst_filename
= pst
->filename
;
20684 gdb::unique_xmalloc_ptr
<char> copied_name
;
20685 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20687 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20688 pst_filename
, (char *) NULL
));
20689 pst_filename
= copied_name
.get ();
20692 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20696 return include_name
;
20699 /* State machine to track the state of the line number program. */
20701 class lnp_state_machine
20704 /* Initialize a machine state for the start of a line number
20706 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20707 bool record_lines_p
);
20709 file_entry
*current_file ()
20711 /* lh->file_names is 0-based, but the file name numbers in the
20712 statement program are 1-based. */
20713 return m_line_header
->file_name_at (m_file
);
20716 /* Record the line in the state machine. END_SEQUENCE is true if
20717 we're processing the end of a sequence. */
20718 void record_line (bool end_sequence
);
20720 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
20721 nop-out rest of the lines in this sequence. */
20722 void check_line_address (struct dwarf2_cu
*cu
,
20723 const gdb_byte
*line_ptr
,
20724 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20726 void handle_set_discriminator (unsigned int discriminator
)
20728 m_discriminator
= discriminator
;
20729 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20732 /* Handle DW_LNE_set_address. */
20733 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20736 address
+= baseaddr
;
20737 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20740 /* Handle DW_LNS_advance_pc. */
20741 void handle_advance_pc (CORE_ADDR adjust
);
20743 /* Handle a special opcode. */
20744 void handle_special_opcode (unsigned char op_code
);
20746 /* Handle DW_LNS_advance_line. */
20747 void handle_advance_line (int line_delta
)
20749 advance_line (line_delta
);
20752 /* Handle DW_LNS_set_file. */
20753 void handle_set_file (file_name_index file
);
20755 /* Handle DW_LNS_negate_stmt. */
20756 void handle_negate_stmt ()
20758 m_is_stmt
= !m_is_stmt
;
20761 /* Handle DW_LNS_const_add_pc. */
20762 void handle_const_add_pc ();
20764 /* Handle DW_LNS_fixed_advance_pc. */
20765 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20767 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20771 /* Handle DW_LNS_copy. */
20772 void handle_copy ()
20774 record_line (false);
20775 m_discriminator
= 0;
20778 /* Handle DW_LNE_end_sequence. */
20779 void handle_end_sequence ()
20781 m_currently_recording_lines
= true;
20785 /* Advance the line by LINE_DELTA. */
20786 void advance_line (int line_delta
)
20788 m_line
+= line_delta
;
20790 if (line_delta
!= 0)
20791 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20794 struct dwarf2_cu
*m_cu
;
20796 gdbarch
*m_gdbarch
;
20798 /* True if we're recording lines.
20799 Otherwise we're building partial symtabs and are just interested in
20800 finding include files mentioned by the line number program. */
20801 bool m_record_lines_p
;
20803 /* The line number header. */
20804 line_header
*m_line_header
;
20806 /* These are part of the standard DWARF line number state machine,
20807 and initialized according to the DWARF spec. */
20809 unsigned char m_op_index
= 0;
20810 /* The line table index (1-based) of the current file. */
20811 file_name_index m_file
= (file_name_index
) 1;
20812 unsigned int m_line
= 1;
20814 /* These are initialized in the constructor. */
20816 CORE_ADDR m_address
;
20818 unsigned int m_discriminator
;
20820 /* Additional bits of state we need to track. */
20822 /* The last file that we called dwarf2_start_subfile for.
20823 This is only used for TLLs. */
20824 unsigned int m_last_file
= 0;
20825 /* The last file a line number was recorded for. */
20826 struct subfile
*m_last_subfile
= NULL
;
20828 /* When true, record the lines we decode. */
20829 bool m_currently_recording_lines
= false;
20831 /* The last line number that was recorded, used to coalesce
20832 consecutive entries for the same line. This can happen, for
20833 example, when discriminators are present. PR 17276. */
20834 unsigned int m_last_line
= 0;
20835 bool m_line_has_non_zero_discriminator
= false;
20839 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20841 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20842 / m_line_header
->maximum_ops_per_instruction
)
20843 * m_line_header
->minimum_instruction_length
);
20844 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20845 m_op_index
= ((m_op_index
+ adjust
)
20846 % m_line_header
->maximum_ops_per_instruction
);
20850 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20852 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20853 CORE_ADDR addr_adj
= (((m_op_index
20854 + (adj_opcode
/ m_line_header
->line_range
))
20855 / m_line_header
->maximum_ops_per_instruction
)
20856 * m_line_header
->minimum_instruction_length
);
20857 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20858 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20859 % m_line_header
->maximum_ops_per_instruction
);
20861 int line_delta
= (m_line_header
->line_base
20862 + (adj_opcode
% m_line_header
->line_range
));
20863 advance_line (line_delta
);
20864 record_line (false);
20865 m_discriminator
= 0;
20869 lnp_state_machine::handle_set_file (file_name_index file
)
20873 const file_entry
*fe
= current_file ();
20875 dwarf2_debug_line_missing_file_complaint ();
20876 else if (m_record_lines_p
)
20878 const char *dir
= fe
->include_dir (m_line_header
);
20880 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20881 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20882 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20887 lnp_state_machine::handle_const_add_pc ()
20890 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20893 = (((m_op_index
+ adjust
)
20894 / m_line_header
->maximum_ops_per_instruction
)
20895 * m_line_header
->minimum_instruction_length
);
20897 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20898 m_op_index
= ((m_op_index
+ adjust
)
20899 % m_line_header
->maximum_ops_per_instruction
);
20902 /* Return non-zero if we should add LINE to the line number table.
20903 LINE is the line to add, LAST_LINE is the last line that was added,
20904 LAST_SUBFILE is the subfile for LAST_LINE.
20905 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20906 had a non-zero discriminator.
20908 We have to be careful in the presence of discriminators.
20909 E.g., for this line:
20911 for (i = 0; i < 100000; i++);
20913 clang can emit four line number entries for that one line,
20914 each with a different discriminator.
20915 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20917 However, we want gdb to coalesce all four entries into one.
20918 Otherwise the user could stepi into the middle of the line and
20919 gdb would get confused about whether the pc really was in the
20920 middle of the line.
20922 Things are further complicated by the fact that two consecutive
20923 line number entries for the same line is a heuristic used by gcc
20924 to denote the end of the prologue. So we can't just discard duplicate
20925 entries, we have to be selective about it. The heuristic we use is
20926 that we only collapse consecutive entries for the same line if at least
20927 one of those entries has a non-zero discriminator. PR 17276.
20929 Note: Addresses in the line number state machine can never go backwards
20930 within one sequence, thus this coalescing is ok. */
20933 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20934 unsigned int line
, unsigned int last_line
,
20935 int line_has_non_zero_discriminator
,
20936 struct subfile
*last_subfile
)
20938 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20940 if (line
!= last_line
)
20942 /* Same line for the same file that we've seen already.
20943 As a last check, for pr 17276, only record the line if the line
20944 has never had a non-zero discriminator. */
20945 if (!line_has_non_zero_discriminator
)
20950 /* Use the CU's builder to record line number LINE beginning at
20951 address ADDRESS in the line table of subfile SUBFILE. */
20954 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20955 unsigned int line
, CORE_ADDR address
,
20956 struct dwarf2_cu
*cu
)
20958 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20960 if (dwarf_line_debug
)
20962 fprintf_unfiltered (gdb_stdlog
,
20963 "Recording line %u, file %s, address %s\n",
20964 line
, lbasename (subfile
->name
),
20965 paddress (gdbarch
, address
));
20969 cu
->get_builder ()->record_line (subfile
, line
, addr
);
20972 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20973 Mark the end of a set of line number records.
20974 The arguments are the same as for dwarf_record_line_1.
20975 If SUBFILE is NULL the request is ignored. */
20978 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20979 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20981 if (subfile
== NULL
)
20984 if (dwarf_line_debug
)
20986 fprintf_unfiltered (gdb_stdlog
,
20987 "Finishing current line, file %s, address %s\n",
20988 lbasename (subfile
->name
),
20989 paddress (gdbarch
, address
));
20992 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
20996 lnp_state_machine::record_line (bool end_sequence
)
20998 if (dwarf_line_debug
)
21000 fprintf_unfiltered (gdb_stdlog
,
21001 "Processing actual line %u: file %u,"
21002 " address %s, is_stmt %u, discrim %u\n",
21003 m_line
, to_underlying (m_file
),
21004 paddress (m_gdbarch
, m_address
),
21005 m_is_stmt
, m_discriminator
);
21008 file_entry
*fe
= current_file ();
21011 dwarf2_debug_line_missing_file_complaint ();
21012 /* For now we ignore lines not starting on an instruction boundary.
21013 But not when processing end_sequence for compatibility with the
21014 previous version of the code. */
21015 else if (m_op_index
== 0 || end_sequence
)
21017 fe
->included_p
= 1;
21018 if (m_record_lines_p
&& (producer_is_codewarrior (m_cu
) || m_is_stmt
))
21020 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
21023 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21024 m_currently_recording_lines
? m_cu
: nullptr);
21029 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21030 m_line_has_non_zero_discriminator
,
21033 buildsym_compunit
*builder
= m_cu
->get_builder ();
21034 dwarf_record_line_1 (m_gdbarch
,
21035 builder
->get_current_subfile (),
21037 m_currently_recording_lines
? m_cu
: nullptr);
21039 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21040 m_last_line
= m_line
;
21046 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21047 line_header
*lh
, bool record_lines_p
)
21051 m_record_lines_p
= record_lines_p
;
21052 m_line_header
= lh
;
21054 m_currently_recording_lines
= true;
21056 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21057 was a line entry for it so that the backend has a chance to adjust it
21058 and also record it in case it needs it. This is currently used by MIPS
21059 code, cf. `mips_adjust_dwarf2_line'. */
21060 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21061 m_is_stmt
= lh
->default_is_stmt
;
21062 m_discriminator
= 0;
21066 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21067 const gdb_byte
*line_ptr
,
21068 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21070 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
21071 the pc range of the CU. However, we restrict the test to only ADDRESS
21072 values of zero to preserve GDB's previous behaviour which is to handle
21073 the specific case of a function being GC'd by the linker. */
21075 if (address
== 0 && address
< unrelocated_lowpc
)
21077 /* This line table is for a function which has been
21078 GCd by the linker. Ignore it. PR gdb/12528 */
21080 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21081 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21083 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21084 line_offset
, objfile_name (objfile
));
21085 m_currently_recording_lines
= false;
21086 /* Note: m_currently_recording_lines is left as false until we see
21087 DW_LNE_end_sequence. */
21091 /* Subroutine of dwarf_decode_lines to simplify it.
21092 Process the line number information in LH.
21093 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21094 program in order to set included_p for every referenced header. */
21097 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21098 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21100 const gdb_byte
*line_ptr
, *extended_end
;
21101 const gdb_byte
*line_end
;
21102 unsigned int bytes_read
, extended_len
;
21103 unsigned char op_code
, extended_op
;
21104 CORE_ADDR baseaddr
;
21105 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21106 bfd
*abfd
= objfile
->obfd
;
21107 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21108 /* True if we're recording line info (as opposed to building partial
21109 symtabs and just interested in finding include files mentioned by
21110 the line number program). */
21111 bool record_lines_p
= !decode_for_pst_p
;
21113 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21115 line_ptr
= lh
->statement_program_start
;
21116 line_end
= lh
->statement_program_end
;
21118 /* Read the statement sequences until there's nothing left. */
21119 while (line_ptr
< line_end
)
21121 /* The DWARF line number program state machine. Reset the state
21122 machine at the start of each sequence. */
21123 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21124 bool end_sequence
= false;
21126 if (record_lines_p
)
21128 /* Start a subfile for the current file of the state
21130 const file_entry
*fe
= state_machine
.current_file ();
21133 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21136 /* Decode the table. */
21137 while (line_ptr
< line_end
&& !end_sequence
)
21139 op_code
= read_1_byte (abfd
, line_ptr
);
21142 if (op_code
>= lh
->opcode_base
)
21144 /* Special opcode. */
21145 state_machine
.handle_special_opcode (op_code
);
21147 else switch (op_code
)
21149 case DW_LNS_extended_op
:
21150 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21152 line_ptr
+= bytes_read
;
21153 extended_end
= line_ptr
+ extended_len
;
21154 extended_op
= read_1_byte (abfd
, line_ptr
);
21156 switch (extended_op
)
21158 case DW_LNE_end_sequence
:
21159 state_machine
.handle_end_sequence ();
21160 end_sequence
= true;
21162 case DW_LNE_set_address
:
21165 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21166 line_ptr
+= bytes_read
;
21168 state_machine
.check_line_address (cu
, line_ptr
,
21169 lowpc
- baseaddr
, address
);
21170 state_machine
.handle_set_address (baseaddr
, address
);
21173 case DW_LNE_define_file
:
21175 const char *cur_file
;
21176 unsigned int mod_time
, length
;
21179 cur_file
= read_direct_string (abfd
, line_ptr
,
21181 line_ptr
+= bytes_read
;
21182 dindex
= (dir_index
)
21183 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21184 line_ptr
+= bytes_read
;
21186 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21187 line_ptr
+= bytes_read
;
21189 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21190 line_ptr
+= bytes_read
;
21191 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21194 case DW_LNE_set_discriminator
:
21196 /* The discriminator is not interesting to the
21197 debugger; just ignore it. We still need to
21198 check its value though:
21199 if there are consecutive entries for the same
21200 (non-prologue) line we want to coalesce them.
21203 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21204 line_ptr
+= bytes_read
;
21206 state_machine
.handle_set_discriminator (discr
);
21210 complaint (_("mangled .debug_line section"));
21213 /* Make sure that we parsed the extended op correctly. If e.g.
21214 we expected a different address size than the producer used,
21215 we may have read the wrong number of bytes. */
21216 if (line_ptr
!= extended_end
)
21218 complaint (_("mangled .debug_line section"));
21223 state_machine
.handle_copy ();
21225 case DW_LNS_advance_pc
:
21228 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21229 line_ptr
+= bytes_read
;
21231 state_machine
.handle_advance_pc (adjust
);
21234 case DW_LNS_advance_line
:
21237 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21238 line_ptr
+= bytes_read
;
21240 state_machine
.handle_advance_line (line_delta
);
21243 case DW_LNS_set_file
:
21245 file_name_index file
21246 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21248 line_ptr
+= bytes_read
;
21250 state_machine
.handle_set_file (file
);
21253 case DW_LNS_set_column
:
21254 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21255 line_ptr
+= bytes_read
;
21257 case DW_LNS_negate_stmt
:
21258 state_machine
.handle_negate_stmt ();
21260 case DW_LNS_set_basic_block
:
21262 /* Add to the address register of the state machine the
21263 address increment value corresponding to special opcode
21264 255. I.e., this value is scaled by the minimum
21265 instruction length since special opcode 255 would have
21266 scaled the increment. */
21267 case DW_LNS_const_add_pc
:
21268 state_machine
.handle_const_add_pc ();
21270 case DW_LNS_fixed_advance_pc
:
21272 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21275 state_machine
.handle_fixed_advance_pc (addr_adj
);
21280 /* Unknown standard opcode, ignore it. */
21283 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21285 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21286 line_ptr
+= bytes_read
;
21293 dwarf2_debug_line_missing_end_sequence_complaint ();
21295 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21296 in which case we still finish recording the last line). */
21297 state_machine
.record_line (true);
21301 /* Decode the Line Number Program (LNP) for the given line_header
21302 structure and CU. The actual information extracted and the type
21303 of structures created from the LNP depends on the value of PST.
21305 1. If PST is NULL, then this procedure uses the data from the program
21306 to create all necessary symbol tables, and their linetables.
21308 2. If PST is not NULL, this procedure reads the program to determine
21309 the list of files included by the unit represented by PST, and
21310 builds all the associated partial symbol tables.
21312 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21313 It is used for relative paths in the line table.
21314 NOTE: When processing partial symtabs (pst != NULL),
21315 comp_dir == pst->dirname.
21317 NOTE: It is important that psymtabs have the same file name (via strcmp)
21318 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21319 symtab we don't use it in the name of the psymtabs we create.
21320 E.g. expand_line_sal requires this when finding psymtabs to expand.
21321 A good testcase for this is mb-inline.exp.
21323 LOWPC is the lowest address in CU (or 0 if not known).
21325 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21326 for its PC<->lines mapping information. Otherwise only the filename
21327 table is read in. */
21330 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21331 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21332 CORE_ADDR lowpc
, int decode_mapping
)
21334 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21335 const int decode_for_pst_p
= (pst
!= NULL
);
21337 if (decode_mapping
)
21338 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21340 if (decode_for_pst_p
)
21344 /* Now that we're done scanning the Line Header Program, we can
21345 create the psymtab of each included file. */
21346 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
21347 if (lh
->file_names
[file_index
].included_p
== 1)
21349 gdb::unique_xmalloc_ptr
<char> name_holder
;
21350 const char *include_name
=
21351 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
21353 if (include_name
!= NULL
)
21354 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21359 /* Make sure a symtab is created for every file, even files
21360 which contain only variables (i.e. no code with associated
21362 buildsym_compunit
*builder
= cu
->get_builder ();
21363 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21366 for (i
= 0; i
< lh
->file_names
.size (); i
++)
21368 file_entry
&fe
= lh
->file_names
[i
];
21370 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21372 if (builder
->get_current_subfile ()->symtab
== NULL
)
21374 builder
->get_current_subfile ()->symtab
21375 = allocate_symtab (cust
,
21376 builder
->get_current_subfile ()->name
);
21378 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21383 /* Start a subfile for DWARF. FILENAME is the name of the file and
21384 DIRNAME the name of the source directory which contains FILENAME
21385 or NULL if not known.
21386 This routine tries to keep line numbers from identical absolute and
21387 relative file names in a common subfile.
21389 Using the `list' example from the GDB testsuite, which resides in
21390 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21391 of /srcdir/list0.c yields the following debugging information for list0.c:
21393 DW_AT_name: /srcdir/list0.c
21394 DW_AT_comp_dir: /compdir
21395 files.files[0].name: list0.h
21396 files.files[0].dir: /srcdir
21397 files.files[1].name: list0.c
21398 files.files[1].dir: /srcdir
21400 The line number information for list0.c has to end up in a single
21401 subfile, so that `break /srcdir/list0.c:1' works as expected.
21402 start_subfile will ensure that this happens provided that we pass the
21403 concatenation of files.files[1].dir and files.files[1].name as the
21407 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21408 const char *dirname
)
21412 /* In order not to lose the line information directory,
21413 we concatenate it to the filename when it makes sense.
21414 Note that the Dwarf3 standard says (speaking of filenames in line
21415 information): ``The directory index is ignored for file names
21416 that represent full path names''. Thus ignoring dirname in the
21417 `else' branch below isn't an issue. */
21419 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21421 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21425 cu
->get_builder ()->start_subfile (filename
);
21431 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21432 buildsym_compunit constructor. */
21434 struct compunit_symtab
*
21435 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21438 gdb_assert (m_builder
== nullptr);
21440 m_builder
.reset (new struct buildsym_compunit
21441 (per_cu
->dwarf2_per_objfile
->objfile
,
21442 name
, comp_dir
, language
, low_pc
));
21444 list_in_scope
= get_builder ()->get_file_symbols ();
21446 get_builder ()->record_debugformat ("DWARF 2");
21447 get_builder ()->record_producer (producer
);
21449 processing_has_namespace_info
= false;
21451 return get_builder ()->get_compunit_symtab ();
21455 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21456 struct dwarf2_cu
*cu
)
21458 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21459 struct comp_unit_head
*cu_header
= &cu
->header
;
21461 /* NOTE drow/2003-01-30: There used to be a comment and some special
21462 code here to turn a symbol with DW_AT_external and a
21463 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21464 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21465 with some versions of binutils) where shared libraries could have
21466 relocations against symbols in their debug information - the
21467 minimal symbol would have the right address, but the debug info
21468 would not. It's no longer necessary, because we will explicitly
21469 apply relocations when we read in the debug information now. */
21471 /* A DW_AT_location attribute with no contents indicates that a
21472 variable has been optimized away. */
21473 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21475 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21479 /* Handle one degenerate form of location expression specially, to
21480 preserve GDB's previous behavior when section offsets are
21481 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21482 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21484 if (attr_form_is_block (attr
)
21485 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21486 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21487 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21488 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21489 && (DW_BLOCK (attr
)->size
21490 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21492 unsigned int dummy
;
21494 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21495 SET_SYMBOL_VALUE_ADDRESS (sym
,
21496 read_address (objfile
->obfd
,
21497 DW_BLOCK (attr
)->data
+ 1,
21500 SET_SYMBOL_VALUE_ADDRESS
21501 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21503 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21504 fixup_symbol_section (sym
, objfile
);
21505 SET_SYMBOL_VALUE_ADDRESS (sym
,
21506 SYMBOL_VALUE_ADDRESS (sym
)
21507 + ANOFFSET (objfile
->section_offsets
,
21508 SYMBOL_SECTION (sym
)));
21512 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21513 expression evaluator, and use LOC_COMPUTED only when necessary
21514 (i.e. when the value of a register or memory location is
21515 referenced, or a thread-local block, etc.). Then again, it might
21516 not be worthwhile. I'm assuming that it isn't unless performance
21517 or memory numbers show me otherwise. */
21519 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21521 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21522 cu
->has_loclist
= true;
21525 /* Given a pointer to a DWARF information entry, figure out if we need
21526 to make a symbol table entry for it, and if so, create a new entry
21527 and return a pointer to it.
21528 If TYPE is NULL, determine symbol type from the die, otherwise
21529 used the passed type.
21530 If SPACE is not NULL, use it to hold the new symbol. If it is
21531 NULL, allocate a new symbol on the objfile's obstack. */
21533 static struct symbol
*
21534 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21535 struct symbol
*space
)
21537 struct dwarf2_per_objfile
*dwarf2_per_objfile
21538 = cu
->per_cu
->dwarf2_per_objfile
;
21539 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21540 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21541 struct symbol
*sym
= NULL
;
21543 struct attribute
*attr
= NULL
;
21544 struct attribute
*attr2
= NULL
;
21545 CORE_ADDR baseaddr
;
21546 struct pending
**list_to_add
= NULL
;
21548 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21550 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21552 name
= dwarf2_name (die
, cu
);
21555 const char *linkagename
;
21556 int suppress_add
= 0;
21561 sym
= allocate_symbol (objfile
);
21562 OBJSTAT (objfile
, n_syms
++);
21564 /* Cache this symbol's name and the name's demangled form (if any). */
21565 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21566 linkagename
= dwarf2_physname (name
, die
, cu
);
21567 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21569 /* Fortran does not have mangling standard and the mangling does differ
21570 between gfortran, iFort etc. */
21571 if (cu
->language
== language_fortran
21572 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21573 symbol_set_demangled_name (&(sym
->ginfo
),
21574 dwarf2_full_name (name
, die
, cu
),
21577 /* Default assumptions.
21578 Use the passed type or decode it from the die. */
21579 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21580 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21582 SYMBOL_TYPE (sym
) = type
;
21584 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21585 attr
= dwarf2_attr (die
,
21586 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21590 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21593 attr
= dwarf2_attr (die
,
21594 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21598 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21599 struct file_entry
*fe
;
21601 if (cu
->line_header
!= NULL
)
21602 fe
= cu
->line_header
->file_name_at (file_index
);
21607 complaint (_("file index out of range"));
21609 symbol_set_symtab (sym
, fe
->symtab
);
21615 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21620 addr
= attr_value_as_address (attr
);
21621 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21622 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21624 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21625 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21626 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21627 add_symbol_to_list (sym
, cu
->list_in_scope
);
21629 case DW_TAG_subprogram
:
21630 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21632 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21633 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21634 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21635 || cu
->language
== language_ada
21636 || cu
->language
== language_fortran
)
21638 /* Subprograms marked external are stored as a global symbol.
21639 Ada and Fortran subprograms, whether marked external or
21640 not, are always stored as a global symbol, because we want
21641 to be able to access them globally. For instance, we want
21642 to be able to break on a nested subprogram without having
21643 to specify the context. */
21644 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21648 list_to_add
= cu
->list_in_scope
;
21651 case DW_TAG_inlined_subroutine
:
21652 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21654 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21655 SYMBOL_INLINED (sym
) = 1;
21656 list_to_add
= cu
->list_in_scope
;
21658 case DW_TAG_template_value_param
:
21660 /* Fall through. */
21661 case DW_TAG_constant
:
21662 case DW_TAG_variable
:
21663 case DW_TAG_member
:
21664 /* Compilation with minimal debug info may result in
21665 variables with missing type entries. Change the
21666 misleading `void' type to something sensible. */
21667 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21668 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21670 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21671 /* In the case of DW_TAG_member, we should only be called for
21672 static const members. */
21673 if (die
->tag
== DW_TAG_member
)
21675 /* dwarf2_add_field uses die_is_declaration,
21676 so we do the same. */
21677 gdb_assert (die_is_declaration (die
, cu
));
21682 dwarf2_const_value (attr
, sym
, cu
);
21683 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21686 if (attr2
&& (DW_UNSND (attr2
) != 0))
21687 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21689 list_to_add
= cu
->list_in_scope
;
21693 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21696 var_decode_location (attr
, sym
, cu
);
21697 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21699 /* Fortran explicitly imports any global symbols to the local
21700 scope by DW_TAG_common_block. */
21701 if (cu
->language
== language_fortran
&& die
->parent
21702 && die
->parent
->tag
== DW_TAG_common_block
)
21705 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21706 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21707 && !dwarf2_per_objfile
->has_section_at_zero
)
21709 /* When a static variable is eliminated by the linker,
21710 the corresponding debug information is not stripped
21711 out, but the variable address is set to null;
21712 do not add such variables into symbol table. */
21714 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21716 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21717 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21718 && dwarf2_per_objfile
->can_copy
)
21720 /* A global static variable might be subject to
21721 copy relocation. We first check for a local
21722 minsym, though, because maybe the symbol was
21723 marked hidden, in which case this would not
21725 bound_minimal_symbol found
21726 = (lookup_minimal_symbol_linkage
21727 (SYMBOL_LINKAGE_NAME (sym
), objfile
));
21728 if (found
.minsym
!= nullptr)
21729 sym
->maybe_copied
= 1;
21732 /* A variable with DW_AT_external is never static,
21733 but it may be block-scoped. */
21735 = ((cu
->list_in_scope
21736 == cu
->get_builder ()->get_file_symbols ())
21737 ? cu
->get_builder ()->get_global_symbols ()
21738 : cu
->list_in_scope
);
21741 list_to_add
= cu
->list_in_scope
;
21745 /* We do not know the address of this symbol.
21746 If it is an external symbol and we have type information
21747 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21748 The address of the variable will then be determined from
21749 the minimal symbol table whenever the variable is
21751 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21753 /* Fortran explicitly imports any global symbols to the local
21754 scope by DW_TAG_common_block. */
21755 if (cu
->language
== language_fortran
&& die
->parent
21756 && die
->parent
->tag
== DW_TAG_common_block
)
21758 /* SYMBOL_CLASS doesn't matter here because
21759 read_common_block is going to reset it. */
21761 list_to_add
= cu
->list_in_scope
;
21763 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21764 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21766 /* A variable with DW_AT_external is never static, but it
21767 may be block-scoped. */
21769 = ((cu
->list_in_scope
21770 == cu
->get_builder ()->get_file_symbols ())
21771 ? cu
->get_builder ()->get_global_symbols ()
21772 : cu
->list_in_scope
);
21774 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21776 else if (!die_is_declaration (die
, cu
))
21778 /* Use the default LOC_OPTIMIZED_OUT class. */
21779 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21781 list_to_add
= cu
->list_in_scope
;
21785 case DW_TAG_formal_parameter
:
21787 /* If we are inside a function, mark this as an argument. If
21788 not, we might be looking at an argument to an inlined function
21789 when we do not have enough information to show inlined frames;
21790 pretend it's a local variable in that case so that the user can
21792 struct context_stack
*curr
21793 = cu
->get_builder ()->get_current_context_stack ();
21794 if (curr
!= nullptr && curr
->name
!= nullptr)
21795 SYMBOL_IS_ARGUMENT (sym
) = 1;
21796 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21799 var_decode_location (attr
, sym
, cu
);
21801 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21804 dwarf2_const_value (attr
, sym
, cu
);
21807 list_to_add
= cu
->list_in_scope
;
21810 case DW_TAG_unspecified_parameters
:
21811 /* From varargs functions; gdb doesn't seem to have any
21812 interest in this information, so just ignore it for now.
21815 case DW_TAG_template_type_param
:
21817 /* Fall through. */
21818 case DW_TAG_class_type
:
21819 case DW_TAG_interface_type
:
21820 case DW_TAG_structure_type
:
21821 case DW_TAG_union_type
:
21822 case DW_TAG_set_type
:
21823 case DW_TAG_enumeration_type
:
21824 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21825 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21828 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21829 really ever be static objects: otherwise, if you try
21830 to, say, break of a class's method and you're in a file
21831 which doesn't mention that class, it won't work unless
21832 the check for all static symbols in lookup_symbol_aux
21833 saves you. See the OtherFileClass tests in
21834 gdb.c++/namespace.exp. */
21838 buildsym_compunit
*builder
= cu
->get_builder ();
21840 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21841 && cu
->language
== language_cplus
21842 ? builder
->get_global_symbols ()
21843 : cu
->list_in_scope
);
21845 /* The semantics of C++ state that "struct foo {
21846 ... }" also defines a typedef for "foo". */
21847 if (cu
->language
== language_cplus
21848 || cu
->language
== language_ada
21849 || cu
->language
== language_d
21850 || cu
->language
== language_rust
)
21852 /* The symbol's name is already allocated along
21853 with this objfile, so we don't need to
21854 duplicate it for the type. */
21855 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21856 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21861 case DW_TAG_typedef
:
21862 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21863 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21864 list_to_add
= cu
->list_in_scope
;
21866 case DW_TAG_base_type
:
21867 case DW_TAG_subrange_type
:
21868 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21869 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21870 list_to_add
= cu
->list_in_scope
;
21872 case DW_TAG_enumerator
:
21873 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21876 dwarf2_const_value (attr
, sym
, cu
);
21879 /* NOTE: carlton/2003-11-10: See comment above in the
21880 DW_TAG_class_type, etc. block. */
21883 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21884 && cu
->language
== language_cplus
21885 ? cu
->get_builder ()->get_global_symbols ()
21886 : cu
->list_in_scope
);
21889 case DW_TAG_imported_declaration
:
21890 case DW_TAG_namespace
:
21891 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21892 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21894 case DW_TAG_module
:
21895 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21896 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21897 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21899 case DW_TAG_common_block
:
21900 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21901 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21902 add_symbol_to_list (sym
, cu
->list_in_scope
);
21905 /* Not a tag we recognize. Hopefully we aren't processing
21906 trash data, but since we must specifically ignore things
21907 we don't recognize, there is nothing else we should do at
21909 complaint (_("unsupported tag: '%s'"),
21910 dwarf_tag_name (die
->tag
));
21916 sym
->hash_next
= objfile
->template_symbols
;
21917 objfile
->template_symbols
= sym
;
21918 list_to_add
= NULL
;
21921 if (list_to_add
!= NULL
)
21922 add_symbol_to_list (sym
, list_to_add
);
21924 /* For the benefit of old versions of GCC, check for anonymous
21925 namespaces based on the demangled name. */
21926 if (!cu
->processing_has_namespace_info
21927 && cu
->language
== language_cplus
)
21928 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21933 /* Given an attr with a DW_FORM_dataN value in host byte order,
21934 zero-extend it as appropriate for the symbol's type. The DWARF
21935 standard (v4) is not entirely clear about the meaning of using
21936 DW_FORM_dataN for a constant with a signed type, where the type is
21937 wider than the data. The conclusion of a discussion on the DWARF
21938 list was that this is unspecified. We choose to always zero-extend
21939 because that is the interpretation long in use by GCC. */
21942 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21943 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21945 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21946 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21947 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21948 LONGEST l
= DW_UNSND (attr
);
21950 if (bits
< sizeof (*value
) * 8)
21952 l
&= ((LONGEST
) 1 << bits
) - 1;
21955 else if (bits
== sizeof (*value
) * 8)
21959 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21960 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21967 /* Read a constant value from an attribute. Either set *VALUE, or if
21968 the value does not fit in *VALUE, set *BYTES - either already
21969 allocated on the objfile obstack, or newly allocated on OBSTACK,
21970 or, set *BATON, if we translated the constant to a location
21974 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21975 const char *name
, struct obstack
*obstack
,
21976 struct dwarf2_cu
*cu
,
21977 LONGEST
*value
, const gdb_byte
**bytes
,
21978 struct dwarf2_locexpr_baton
**baton
)
21980 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21981 struct comp_unit_head
*cu_header
= &cu
->header
;
21982 struct dwarf_block
*blk
;
21983 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21984 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21990 switch (attr
->form
)
21993 case DW_FORM_addrx
:
21994 case DW_FORM_GNU_addr_index
:
21998 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21999 dwarf2_const_value_length_mismatch_complaint (name
,
22000 cu_header
->addr_size
,
22001 TYPE_LENGTH (type
));
22002 /* Symbols of this form are reasonably rare, so we just
22003 piggyback on the existing location code rather than writing
22004 a new implementation of symbol_computed_ops. */
22005 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22006 (*baton
)->per_cu
= cu
->per_cu
;
22007 gdb_assert ((*baton
)->per_cu
);
22009 (*baton
)->size
= 2 + cu_header
->addr_size
;
22010 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22011 (*baton
)->data
= data
;
22013 data
[0] = DW_OP_addr
;
22014 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22015 byte_order
, DW_ADDR (attr
));
22016 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22019 case DW_FORM_string
:
22022 case DW_FORM_GNU_str_index
:
22023 case DW_FORM_GNU_strp_alt
:
22024 /* DW_STRING is already allocated on the objfile obstack, point
22026 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22028 case DW_FORM_block1
:
22029 case DW_FORM_block2
:
22030 case DW_FORM_block4
:
22031 case DW_FORM_block
:
22032 case DW_FORM_exprloc
:
22033 case DW_FORM_data16
:
22034 blk
= DW_BLOCK (attr
);
22035 if (TYPE_LENGTH (type
) != blk
->size
)
22036 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22037 TYPE_LENGTH (type
));
22038 *bytes
= blk
->data
;
22041 /* The DW_AT_const_value attributes are supposed to carry the
22042 symbol's value "represented as it would be on the target
22043 architecture." By the time we get here, it's already been
22044 converted to host endianness, so we just need to sign- or
22045 zero-extend it as appropriate. */
22046 case DW_FORM_data1
:
22047 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22049 case DW_FORM_data2
:
22050 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22052 case DW_FORM_data4
:
22053 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22055 case DW_FORM_data8
:
22056 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22059 case DW_FORM_sdata
:
22060 case DW_FORM_implicit_const
:
22061 *value
= DW_SND (attr
);
22064 case DW_FORM_udata
:
22065 *value
= DW_UNSND (attr
);
22069 complaint (_("unsupported const value attribute form: '%s'"),
22070 dwarf_form_name (attr
->form
));
22077 /* Copy constant value from an attribute to a symbol. */
22080 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22081 struct dwarf2_cu
*cu
)
22083 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22085 const gdb_byte
*bytes
;
22086 struct dwarf2_locexpr_baton
*baton
;
22088 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22089 SYMBOL_PRINT_NAME (sym
),
22090 &objfile
->objfile_obstack
, cu
,
22091 &value
, &bytes
, &baton
);
22095 SYMBOL_LOCATION_BATON (sym
) = baton
;
22096 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22098 else if (bytes
!= NULL
)
22100 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22101 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22105 SYMBOL_VALUE (sym
) = value
;
22106 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22110 /* Return the type of the die in question using its DW_AT_type attribute. */
22112 static struct type
*
22113 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22115 struct attribute
*type_attr
;
22117 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22120 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22121 /* A missing DW_AT_type represents a void type. */
22122 return objfile_type (objfile
)->builtin_void
;
22125 return lookup_die_type (die
, type_attr
, cu
);
22128 /* True iff CU's producer generates GNAT Ada auxiliary information
22129 that allows to find parallel types through that information instead
22130 of having to do expensive parallel lookups by type name. */
22133 need_gnat_info (struct dwarf2_cu
*cu
)
22135 /* Assume that the Ada compiler was GNAT, which always produces
22136 the auxiliary information. */
22137 return (cu
->language
== language_ada
);
22140 /* Return the auxiliary type of the die in question using its
22141 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22142 attribute is not present. */
22144 static struct type
*
22145 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22147 struct attribute
*type_attr
;
22149 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22153 return lookup_die_type (die
, type_attr
, cu
);
22156 /* If DIE has a descriptive_type attribute, then set the TYPE's
22157 descriptive type accordingly. */
22160 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22161 struct dwarf2_cu
*cu
)
22163 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22165 if (descriptive_type
)
22167 ALLOCATE_GNAT_AUX_TYPE (type
);
22168 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22172 /* Return the containing type of the die in question using its
22173 DW_AT_containing_type attribute. */
22175 static struct type
*
22176 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22178 struct attribute
*type_attr
;
22179 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22181 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22183 error (_("Dwarf Error: Problem turning containing type into gdb type "
22184 "[in module %s]"), objfile_name (objfile
));
22186 return lookup_die_type (die
, type_attr
, cu
);
22189 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22191 static struct type
*
22192 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22194 struct dwarf2_per_objfile
*dwarf2_per_objfile
22195 = cu
->per_cu
->dwarf2_per_objfile
;
22196 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22199 std::string message
22200 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22201 objfile_name (objfile
),
22202 sect_offset_str (cu
->header
.sect_off
),
22203 sect_offset_str (die
->sect_off
));
22204 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22206 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22209 /* Look up the type of DIE in CU using its type attribute ATTR.
22210 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22211 DW_AT_containing_type.
22212 If there is no type substitute an error marker. */
22214 static struct type
*
22215 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22216 struct dwarf2_cu
*cu
)
22218 struct dwarf2_per_objfile
*dwarf2_per_objfile
22219 = cu
->per_cu
->dwarf2_per_objfile
;
22220 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22221 struct type
*this_type
;
22223 gdb_assert (attr
->name
== DW_AT_type
22224 || attr
->name
== DW_AT_GNAT_descriptive_type
22225 || attr
->name
== DW_AT_containing_type
);
22227 /* First see if we have it cached. */
22229 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22231 struct dwarf2_per_cu_data
*per_cu
;
22232 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22234 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22235 dwarf2_per_objfile
);
22236 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22238 else if (attr_form_is_ref (attr
))
22240 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22242 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22244 else if (attr
->form
== DW_FORM_ref_sig8
)
22246 ULONGEST signature
= DW_SIGNATURE (attr
);
22248 return get_signatured_type (die
, signature
, cu
);
22252 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22253 " at %s [in module %s]"),
22254 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22255 objfile_name (objfile
));
22256 return build_error_marker_type (cu
, die
);
22259 /* If not cached we need to read it in. */
22261 if (this_type
== NULL
)
22263 struct die_info
*type_die
= NULL
;
22264 struct dwarf2_cu
*type_cu
= cu
;
22266 if (attr_form_is_ref (attr
))
22267 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22268 if (type_die
== NULL
)
22269 return build_error_marker_type (cu
, die
);
22270 /* If we find the type now, it's probably because the type came
22271 from an inter-CU reference and the type's CU got expanded before
22273 this_type
= read_type_die (type_die
, type_cu
);
22276 /* If we still don't have a type use an error marker. */
22278 if (this_type
== NULL
)
22279 return build_error_marker_type (cu
, die
);
22284 /* Return the type in DIE, CU.
22285 Returns NULL for invalid types.
22287 This first does a lookup in die_type_hash,
22288 and only reads the die in if necessary.
22290 NOTE: This can be called when reading in partial or full symbols. */
22292 static struct type
*
22293 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22295 struct type
*this_type
;
22297 this_type
= get_die_type (die
, cu
);
22301 return read_type_die_1 (die
, cu
);
22304 /* Read the type in DIE, CU.
22305 Returns NULL for invalid types. */
22307 static struct type
*
22308 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22310 struct type
*this_type
= NULL
;
22314 case DW_TAG_class_type
:
22315 case DW_TAG_interface_type
:
22316 case DW_TAG_structure_type
:
22317 case DW_TAG_union_type
:
22318 this_type
= read_structure_type (die
, cu
);
22320 case DW_TAG_enumeration_type
:
22321 this_type
= read_enumeration_type (die
, cu
);
22323 case DW_TAG_subprogram
:
22324 case DW_TAG_subroutine_type
:
22325 case DW_TAG_inlined_subroutine
:
22326 this_type
= read_subroutine_type (die
, cu
);
22328 case DW_TAG_array_type
:
22329 this_type
= read_array_type (die
, cu
);
22331 case DW_TAG_set_type
:
22332 this_type
= read_set_type (die
, cu
);
22334 case DW_TAG_pointer_type
:
22335 this_type
= read_tag_pointer_type (die
, cu
);
22337 case DW_TAG_ptr_to_member_type
:
22338 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22340 case DW_TAG_reference_type
:
22341 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22343 case DW_TAG_rvalue_reference_type
:
22344 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22346 case DW_TAG_const_type
:
22347 this_type
= read_tag_const_type (die
, cu
);
22349 case DW_TAG_volatile_type
:
22350 this_type
= read_tag_volatile_type (die
, cu
);
22352 case DW_TAG_restrict_type
:
22353 this_type
= read_tag_restrict_type (die
, cu
);
22355 case DW_TAG_string_type
:
22356 this_type
= read_tag_string_type (die
, cu
);
22358 case DW_TAG_typedef
:
22359 this_type
= read_typedef (die
, cu
);
22361 case DW_TAG_subrange_type
:
22362 this_type
= read_subrange_type (die
, cu
);
22364 case DW_TAG_base_type
:
22365 this_type
= read_base_type (die
, cu
);
22367 case DW_TAG_unspecified_type
:
22368 this_type
= read_unspecified_type (die
, cu
);
22370 case DW_TAG_namespace
:
22371 this_type
= read_namespace_type (die
, cu
);
22373 case DW_TAG_module
:
22374 this_type
= read_module_type (die
, cu
);
22376 case DW_TAG_atomic_type
:
22377 this_type
= read_tag_atomic_type (die
, cu
);
22380 complaint (_("unexpected tag in read_type_die: '%s'"),
22381 dwarf_tag_name (die
->tag
));
22388 /* See if we can figure out if the class lives in a namespace. We do
22389 this by looking for a member function; its demangled name will
22390 contain namespace info, if there is any.
22391 Return the computed name or NULL.
22392 Space for the result is allocated on the objfile's obstack.
22393 This is the full-die version of guess_partial_die_structure_name.
22394 In this case we know DIE has no useful parent. */
22397 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22399 struct die_info
*spec_die
;
22400 struct dwarf2_cu
*spec_cu
;
22401 struct die_info
*child
;
22402 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22405 spec_die
= die_specification (die
, &spec_cu
);
22406 if (spec_die
!= NULL
)
22412 for (child
= die
->child
;
22414 child
= child
->sibling
)
22416 if (child
->tag
== DW_TAG_subprogram
)
22418 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22420 if (linkage_name
!= NULL
)
22423 = language_class_name_from_physname (cu
->language_defn
,
22427 if (actual_name
!= NULL
)
22429 const char *die_name
= dwarf2_name (die
, cu
);
22431 if (die_name
!= NULL
22432 && strcmp (die_name
, actual_name
) != 0)
22434 /* Strip off the class name from the full name.
22435 We want the prefix. */
22436 int die_name_len
= strlen (die_name
);
22437 int actual_name_len
= strlen (actual_name
);
22439 /* Test for '::' as a sanity check. */
22440 if (actual_name_len
> die_name_len
+ 2
22441 && actual_name
[actual_name_len
22442 - die_name_len
- 1] == ':')
22443 name
= obstack_strndup (
22444 &objfile
->per_bfd
->storage_obstack
,
22445 actual_name
, actual_name_len
- die_name_len
- 2);
22448 xfree (actual_name
);
22457 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22458 prefix part in such case. See
22459 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22461 static const char *
22462 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22464 struct attribute
*attr
;
22467 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22468 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22471 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22474 attr
= dw2_linkage_name_attr (die
, cu
);
22475 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22478 /* dwarf2_name had to be already called. */
22479 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22481 /* Strip the base name, keep any leading namespaces/classes. */
22482 base
= strrchr (DW_STRING (attr
), ':');
22483 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22486 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22487 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22489 &base
[-1] - DW_STRING (attr
));
22492 /* Return the name of the namespace/class that DIE is defined within,
22493 or "" if we can't tell. The caller should not xfree the result.
22495 For example, if we're within the method foo() in the following
22505 then determine_prefix on foo's die will return "N::C". */
22507 static const char *
22508 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22510 struct dwarf2_per_objfile
*dwarf2_per_objfile
22511 = cu
->per_cu
->dwarf2_per_objfile
;
22512 struct die_info
*parent
, *spec_die
;
22513 struct dwarf2_cu
*spec_cu
;
22514 struct type
*parent_type
;
22515 const char *retval
;
22517 if (cu
->language
!= language_cplus
22518 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22519 && cu
->language
!= language_rust
)
22522 retval
= anonymous_struct_prefix (die
, cu
);
22526 /* We have to be careful in the presence of DW_AT_specification.
22527 For example, with GCC 3.4, given the code
22531 // Definition of N::foo.
22535 then we'll have a tree of DIEs like this:
22537 1: DW_TAG_compile_unit
22538 2: DW_TAG_namespace // N
22539 3: DW_TAG_subprogram // declaration of N::foo
22540 4: DW_TAG_subprogram // definition of N::foo
22541 DW_AT_specification // refers to die #3
22543 Thus, when processing die #4, we have to pretend that we're in
22544 the context of its DW_AT_specification, namely the contex of die
22547 spec_die
= die_specification (die
, &spec_cu
);
22548 if (spec_die
== NULL
)
22549 parent
= die
->parent
;
22552 parent
= spec_die
->parent
;
22556 if (parent
== NULL
)
22558 else if (parent
->building_fullname
)
22561 const char *parent_name
;
22563 /* It has been seen on RealView 2.2 built binaries,
22564 DW_TAG_template_type_param types actually _defined_ as
22565 children of the parent class:
22568 template class <class Enum> Class{};
22569 Class<enum E> class_e;
22571 1: DW_TAG_class_type (Class)
22572 2: DW_TAG_enumeration_type (E)
22573 3: DW_TAG_enumerator (enum1:0)
22574 3: DW_TAG_enumerator (enum2:1)
22576 2: DW_TAG_template_type_param
22577 DW_AT_type DW_FORM_ref_udata (E)
22579 Besides being broken debug info, it can put GDB into an
22580 infinite loop. Consider:
22582 When we're building the full name for Class<E>, we'll start
22583 at Class, and go look over its template type parameters,
22584 finding E. We'll then try to build the full name of E, and
22585 reach here. We're now trying to build the full name of E,
22586 and look over the parent DIE for containing scope. In the
22587 broken case, if we followed the parent DIE of E, we'd again
22588 find Class, and once again go look at its template type
22589 arguments, etc., etc. Simply don't consider such parent die
22590 as source-level parent of this die (it can't be, the language
22591 doesn't allow it), and break the loop here. */
22592 name
= dwarf2_name (die
, cu
);
22593 parent_name
= dwarf2_name (parent
, cu
);
22594 complaint (_("template param type '%s' defined within parent '%s'"),
22595 name
? name
: "<unknown>",
22596 parent_name
? parent_name
: "<unknown>");
22600 switch (parent
->tag
)
22602 case DW_TAG_namespace
:
22603 parent_type
= read_type_die (parent
, cu
);
22604 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22605 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22606 Work around this problem here. */
22607 if (cu
->language
== language_cplus
22608 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22610 /* We give a name to even anonymous namespaces. */
22611 return TYPE_NAME (parent_type
);
22612 case DW_TAG_class_type
:
22613 case DW_TAG_interface_type
:
22614 case DW_TAG_structure_type
:
22615 case DW_TAG_union_type
:
22616 case DW_TAG_module
:
22617 parent_type
= read_type_die (parent
, cu
);
22618 if (TYPE_NAME (parent_type
) != NULL
)
22619 return TYPE_NAME (parent_type
);
22621 /* An anonymous structure is only allowed non-static data
22622 members; no typedefs, no member functions, et cetera.
22623 So it does not need a prefix. */
22625 case DW_TAG_compile_unit
:
22626 case DW_TAG_partial_unit
:
22627 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22628 if (cu
->language
== language_cplus
22629 && !dwarf2_per_objfile
->types
.empty ()
22630 && die
->child
!= NULL
22631 && (die
->tag
== DW_TAG_class_type
22632 || die
->tag
== DW_TAG_structure_type
22633 || die
->tag
== DW_TAG_union_type
))
22635 char *name
= guess_full_die_structure_name (die
, cu
);
22640 case DW_TAG_subprogram
:
22641 /* Nested subroutines in Fortran get a prefix with the name
22642 of the parent's subroutine. */
22643 if (cu
->language
== language_fortran
)
22645 if ((die
->tag
== DW_TAG_subprogram
)
22646 && (dwarf2_name (parent
, cu
) != NULL
))
22647 return dwarf2_name (parent
, cu
);
22649 return determine_prefix (parent
, cu
);
22650 case DW_TAG_enumeration_type
:
22651 parent_type
= read_type_die (parent
, cu
);
22652 if (TYPE_DECLARED_CLASS (parent_type
))
22654 if (TYPE_NAME (parent_type
) != NULL
)
22655 return TYPE_NAME (parent_type
);
22658 /* Fall through. */
22660 return determine_prefix (parent
, cu
);
22664 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22665 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22666 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22667 an obconcat, otherwise allocate storage for the result. The CU argument is
22668 used to determine the language and hence, the appropriate separator. */
22670 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22673 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22674 int physname
, struct dwarf2_cu
*cu
)
22676 const char *lead
= "";
22679 if (suffix
== NULL
|| suffix
[0] == '\0'
22680 || prefix
== NULL
|| prefix
[0] == '\0')
22682 else if (cu
->language
== language_d
)
22684 /* For D, the 'main' function could be defined in any module, but it
22685 should never be prefixed. */
22686 if (strcmp (suffix
, "D main") == 0)
22694 else if (cu
->language
== language_fortran
&& physname
)
22696 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22697 DW_AT_MIPS_linkage_name is preferred and used instead. */
22705 if (prefix
== NULL
)
22707 if (suffix
== NULL
)
22714 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22716 strcpy (retval
, lead
);
22717 strcat (retval
, prefix
);
22718 strcat (retval
, sep
);
22719 strcat (retval
, suffix
);
22724 /* We have an obstack. */
22725 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22729 /* Return sibling of die, NULL if no sibling. */
22731 static struct die_info
*
22732 sibling_die (struct die_info
*die
)
22734 return die
->sibling
;
22737 /* Get name of a die, return NULL if not found. */
22739 static const char *
22740 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22741 struct obstack
*obstack
)
22743 if (name
&& cu
->language
== language_cplus
)
22745 std::string canon_name
= cp_canonicalize_string (name
);
22747 if (!canon_name
.empty ())
22749 if (canon_name
!= name
)
22750 name
= obstack_strdup (obstack
, canon_name
);
22757 /* Get name of a die, return NULL if not found.
22758 Anonymous namespaces are converted to their magic string. */
22760 static const char *
22761 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22763 struct attribute
*attr
;
22764 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22766 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22767 if ((!attr
|| !DW_STRING (attr
))
22768 && die
->tag
!= DW_TAG_namespace
22769 && die
->tag
!= DW_TAG_class_type
22770 && die
->tag
!= DW_TAG_interface_type
22771 && die
->tag
!= DW_TAG_structure_type
22772 && die
->tag
!= DW_TAG_union_type
)
22777 case DW_TAG_compile_unit
:
22778 case DW_TAG_partial_unit
:
22779 /* Compilation units have a DW_AT_name that is a filename, not
22780 a source language identifier. */
22781 case DW_TAG_enumeration_type
:
22782 case DW_TAG_enumerator
:
22783 /* These tags always have simple identifiers already; no need
22784 to canonicalize them. */
22785 return DW_STRING (attr
);
22787 case DW_TAG_namespace
:
22788 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22789 return DW_STRING (attr
);
22790 return CP_ANONYMOUS_NAMESPACE_STR
;
22792 case DW_TAG_class_type
:
22793 case DW_TAG_interface_type
:
22794 case DW_TAG_structure_type
:
22795 case DW_TAG_union_type
:
22796 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22797 structures or unions. These were of the form "._%d" in GCC 4.1,
22798 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22799 and GCC 4.4. We work around this problem by ignoring these. */
22800 if (attr
&& DW_STRING (attr
)
22801 && (startswith (DW_STRING (attr
), "._")
22802 || startswith (DW_STRING (attr
), "<anonymous")))
22805 /* GCC might emit a nameless typedef that has a linkage name. See
22806 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22807 if (!attr
|| DW_STRING (attr
) == NULL
)
22809 char *demangled
= NULL
;
22811 attr
= dw2_linkage_name_attr (die
, cu
);
22812 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22815 /* Avoid demangling DW_STRING (attr) the second time on a second
22816 call for the same DIE. */
22817 if (!DW_STRING_IS_CANONICAL (attr
))
22818 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22824 /* FIXME: we already did this for the partial symbol... */
22826 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
22828 DW_STRING_IS_CANONICAL (attr
) = 1;
22831 /* Strip any leading namespaces/classes, keep only the base name.
22832 DW_AT_name for named DIEs does not contain the prefixes. */
22833 base
= strrchr (DW_STRING (attr
), ':');
22834 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22837 return DW_STRING (attr
);
22846 if (!DW_STRING_IS_CANONICAL (attr
))
22849 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22850 &objfile
->per_bfd
->storage_obstack
);
22851 DW_STRING_IS_CANONICAL (attr
) = 1;
22853 return DW_STRING (attr
);
22856 /* Return the die that this die in an extension of, or NULL if there
22857 is none. *EXT_CU is the CU containing DIE on input, and the CU
22858 containing the return value on output. */
22860 static struct die_info
*
22861 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22863 struct attribute
*attr
;
22865 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22869 return follow_die_ref (die
, attr
, ext_cu
);
22872 /* A convenience function that returns an "unknown" DWARF name,
22873 including the value of V. STR is the name of the entity being
22874 printed, e.g., "TAG". */
22876 static const char *
22877 dwarf_unknown (const char *str
, unsigned v
)
22879 char *cell
= get_print_cell ();
22880 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
22884 /* Convert a DIE tag into its string name. */
22886 static const char *
22887 dwarf_tag_name (unsigned tag
)
22889 const char *name
= get_DW_TAG_name (tag
);
22892 return dwarf_unknown ("TAG", tag
);
22897 /* Convert a DWARF attribute code into its string name. */
22899 static const char *
22900 dwarf_attr_name (unsigned attr
)
22904 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22905 if (attr
== DW_AT_MIPS_fde
)
22906 return "DW_AT_MIPS_fde";
22908 if (attr
== DW_AT_HP_block_index
)
22909 return "DW_AT_HP_block_index";
22912 name
= get_DW_AT_name (attr
);
22915 return dwarf_unknown ("AT", attr
);
22920 /* Convert a unit type to corresponding DW_UT name. */
22922 static const char *
22923 dwarf_unit_type_name (int unit_type
) {
22927 return "DW_UT_compile (0x01)";
22929 return "DW_UT_type (0x02)";
22931 return "DW_UT_partial (0x03)";
22933 return "DW_UT_skeleton (0x04)";
22935 return "DW_UT_split_compile (0x05)";
22937 return "DW_UT_split_type (0x06)";
22939 return "DW_UT_lo_user (0x80)";
22941 return "DW_UT_hi_user (0xff)";
22947 /* Convert a DWARF value form code into its string name. */
22949 static const char *
22950 dwarf_form_name (unsigned form
)
22952 const char *name
= get_DW_FORM_name (form
);
22955 return dwarf_unknown ("FORM", form
);
22960 static const char *
22961 dwarf_bool_name (unsigned mybool
)
22969 /* Convert a DWARF type code into its string name. */
22971 static const char *
22972 dwarf_type_encoding_name (unsigned enc
)
22974 const char *name
= get_DW_ATE_name (enc
);
22977 return dwarf_unknown ("ATE", enc
);
22983 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22987 print_spaces (indent
, f
);
22988 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22989 dwarf_tag_name (die
->tag
), die
->abbrev
,
22990 sect_offset_str (die
->sect_off
));
22992 if (die
->parent
!= NULL
)
22994 print_spaces (indent
, f
);
22995 fprintf_unfiltered (f
, " parent at offset: %s\n",
22996 sect_offset_str (die
->parent
->sect_off
));
22999 print_spaces (indent
, f
);
23000 fprintf_unfiltered (f
, " has children: %s\n",
23001 dwarf_bool_name (die
->child
!= NULL
));
23003 print_spaces (indent
, f
);
23004 fprintf_unfiltered (f
, " attributes:\n");
23006 for (i
= 0; i
< die
->num_attrs
; ++i
)
23008 print_spaces (indent
, f
);
23009 fprintf_unfiltered (f
, " %s (%s) ",
23010 dwarf_attr_name (die
->attrs
[i
].name
),
23011 dwarf_form_name (die
->attrs
[i
].form
));
23013 switch (die
->attrs
[i
].form
)
23016 case DW_FORM_addrx
:
23017 case DW_FORM_GNU_addr_index
:
23018 fprintf_unfiltered (f
, "address: ");
23019 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23021 case DW_FORM_block2
:
23022 case DW_FORM_block4
:
23023 case DW_FORM_block
:
23024 case DW_FORM_block1
:
23025 fprintf_unfiltered (f
, "block: size %s",
23026 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23028 case DW_FORM_exprloc
:
23029 fprintf_unfiltered (f
, "expression: size %s",
23030 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23032 case DW_FORM_data16
:
23033 fprintf_unfiltered (f
, "constant of 16 bytes");
23035 case DW_FORM_ref_addr
:
23036 fprintf_unfiltered (f
, "ref address: ");
23037 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23039 case DW_FORM_GNU_ref_alt
:
23040 fprintf_unfiltered (f
, "alt ref address: ");
23041 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23047 case DW_FORM_ref_udata
:
23048 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23049 (long) (DW_UNSND (&die
->attrs
[i
])));
23051 case DW_FORM_data1
:
23052 case DW_FORM_data2
:
23053 case DW_FORM_data4
:
23054 case DW_FORM_data8
:
23055 case DW_FORM_udata
:
23056 case DW_FORM_sdata
:
23057 fprintf_unfiltered (f
, "constant: %s",
23058 pulongest (DW_UNSND (&die
->attrs
[i
])));
23060 case DW_FORM_sec_offset
:
23061 fprintf_unfiltered (f
, "section offset: %s",
23062 pulongest (DW_UNSND (&die
->attrs
[i
])));
23064 case DW_FORM_ref_sig8
:
23065 fprintf_unfiltered (f
, "signature: %s",
23066 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23068 case DW_FORM_string
:
23070 case DW_FORM_line_strp
:
23072 case DW_FORM_GNU_str_index
:
23073 case DW_FORM_GNU_strp_alt
:
23074 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23075 DW_STRING (&die
->attrs
[i
])
23076 ? DW_STRING (&die
->attrs
[i
]) : "",
23077 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23080 if (DW_UNSND (&die
->attrs
[i
]))
23081 fprintf_unfiltered (f
, "flag: TRUE");
23083 fprintf_unfiltered (f
, "flag: FALSE");
23085 case DW_FORM_flag_present
:
23086 fprintf_unfiltered (f
, "flag: TRUE");
23088 case DW_FORM_indirect
:
23089 /* The reader will have reduced the indirect form to
23090 the "base form" so this form should not occur. */
23091 fprintf_unfiltered (f
,
23092 "unexpected attribute form: DW_FORM_indirect");
23094 case DW_FORM_implicit_const
:
23095 fprintf_unfiltered (f
, "constant: %s",
23096 plongest (DW_SND (&die
->attrs
[i
])));
23099 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23100 die
->attrs
[i
].form
);
23103 fprintf_unfiltered (f
, "\n");
23108 dump_die_for_error (struct die_info
*die
)
23110 dump_die_shallow (gdb_stderr
, 0, die
);
23114 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23116 int indent
= level
* 4;
23118 gdb_assert (die
!= NULL
);
23120 if (level
>= max_level
)
23123 dump_die_shallow (f
, indent
, die
);
23125 if (die
->child
!= NULL
)
23127 print_spaces (indent
, f
);
23128 fprintf_unfiltered (f
, " Children:");
23129 if (level
+ 1 < max_level
)
23131 fprintf_unfiltered (f
, "\n");
23132 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23136 fprintf_unfiltered (f
,
23137 " [not printed, max nesting level reached]\n");
23141 if (die
->sibling
!= NULL
&& level
> 0)
23143 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23147 /* This is called from the pdie macro in gdbinit.in.
23148 It's not static so gcc will keep a copy callable from gdb. */
23151 dump_die (struct die_info
*die
, int max_level
)
23153 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23157 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23161 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23162 to_underlying (die
->sect_off
),
23168 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23172 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23174 if (attr_form_is_ref (attr
))
23175 return (sect_offset
) DW_UNSND (attr
);
23177 complaint (_("unsupported die ref attribute form: '%s'"),
23178 dwarf_form_name (attr
->form
));
23182 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23183 * the value held by the attribute is not constant. */
23186 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23188 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23189 return DW_SND (attr
);
23190 else if (attr
->form
== DW_FORM_udata
23191 || attr
->form
== DW_FORM_data1
23192 || attr
->form
== DW_FORM_data2
23193 || attr
->form
== DW_FORM_data4
23194 || attr
->form
== DW_FORM_data8
)
23195 return DW_UNSND (attr
);
23198 /* For DW_FORM_data16 see attr_form_is_constant. */
23199 complaint (_("Attribute value is not a constant (%s)"),
23200 dwarf_form_name (attr
->form
));
23201 return default_value
;
23205 /* Follow reference or signature attribute ATTR of SRC_DIE.
23206 On entry *REF_CU is the CU of SRC_DIE.
23207 On exit *REF_CU is the CU of the result. */
23209 static struct die_info
*
23210 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23211 struct dwarf2_cu
**ref_cu
)
23213 struct die_info
*die
;
23215 if (attr_form_is_ref (attr
))
23216 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23217 else if (attr
->form
== DW_FORM_ref_sig8
)
23218 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23221 dump_die_for_error (src_die
);
23222 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23223 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23229 /* Follow reference OFFSET.
23230 On entry *REF_CU is the CU of the source die referencing OFFSET.
23231 On exit *REF_CU is the CU of the result.
23232 Returns NULL if OFFSET is invalid. */
23234 static struct die_info
*
23235 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23236 struct dwarf2_cu
**ref_cu
)
23238 struct die_info temp_die
;
23239 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23240 struct dwarf2_per_objfile
*dwarf2_per_objfile
23241 = cu
->per_cu
->dwarf2_per_objfile
;
23243 gdb_assert (cu
->per_cu
!= NULL
);
23247 if (cu
->per_cu
->is_debug_types
)
23249 /* .debug_types CUs cannot reference anything outside their CU.
23250 If they need to, they have to reference a signatured type via
23251 DW_FORM_ref_sig8. */
23252 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23255 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23256 || !offset_in_cu_p (&cu
->header
, sect_off
))
23258 struct dwarf2_per_cu_data
*per_cu
;
23260 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23261 dwarf2_per_objfile
);
23263 /* If necessary, add it to the queue and load its DIEs. */
23264 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23265 load_full_comp_unit (per_cu
, false, cu
->language
);
23267 target_cu
= per_cu
->cu
;
23269 else if (cu
->dies
== NULL
)
23271 /* We're loading full DIEs during partial symbol reading. */
23272 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23273 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23276 *ref_cu
= target_cu
;
23277 temp_die
.sect_off
= sect_off
;
23279 if (target_cu
!= cu
)
23280 target_cu
->ancestor
= cu
;
23282 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23284 to_underlying (sect_off
));
23287 /* Follow reference attribute ATTR of SRC_DIE.
23288 On entry *REF_CU is the CU of SRC_DIE.
23289 On exit *REF_CU is the CU of the result. */
23291 static struct die_info
*
23292 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23293 struct dwarf2_cu
**ref_cu
)
23295 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23296 struct dwarf2_cu
*cu
= *ref_cu
;
23297 struct die_info
*die
;
23299 die
= follow_die_offset (sect_off
,
23300 (attr
->form
== DW_FORM_GNU_ref_alt
23301 || cu
->per_cu
->is_dwz
),
23304 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23305 "at %s [in module %s]"),
23306 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23307 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23312 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23313 Returned value is intended for DW_OP_call*. Returned
23314 dwarf2_locexpr_baton->data has lifetime of
23315 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23317 struct dwarf2_locexpr_baton
23318 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23319 struct dwarf2_per_cu_data
*per_cu
,
23320 CORE_ADDR (*get_frame_pc
) (void *baton
),
23321 void *baton
, bool resolve_abstract_p
)
23323 struct dwarf2_cu
*cu
;
23324 struct die_info
*die
;
23325 struct attribute
*attr
;
23326 struct dwarf2_locexpr_baton retval
;
23327 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23328 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23330 if (per_cu
->cu
== NULL
)
23331 load_cu (per_cu
, false);
23335 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23336 Instead just throw an error, not much else we can do. */
23337 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23338 sect_offset_str (sect_off
), objfile_name (objfile
));
23341 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23343 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23344 sect_offset_str (sect_off
), objfile_name (objfile
));
23346 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23347 if (!attr
&& resolve_abstract_p
23348 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23349 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23351 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23353 = ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23354 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23356 for (const auto &cand_off
23357 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23359 struct dwarf2_cu
*cand_cu
= cu
;
23360 struct die_info
*cand
23361 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23364 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23367 CORE_ADDR pc_low
, pc_high
;
23368 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23369 if (pc_low
== ((CORE_ADDR
) -1))
23371 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23372 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23373 if (!(pc_low
<= pc
&& pc
< pc_high
))
23377 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23384 /* DWARF: "If there is no such attribute, then there is no effect.".
23385 DATA is ignored if SIZE is 0. */
23387 retval
.data
= NULL
;
23390 else if (attr_form_is_section_offset (attr
))
23392 struct dwarf2_loclist_baton loclist_baton
;
23393 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23396 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23398 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23400 retval
.size
= size
;
23404 if (!attr_form_is_block (attr
))
23405 error (_("Dwarf Error: DIE at %s referenced in module %s "
23406 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23407 sect_offset_str (sect_off
), objfile_name (objfile
));
23409 retval
.data
= DW_BLOCK (attr
)->data
;
23410 retval
.size
= DW_BLOCK (attr
)->size
;
23412 retval
.per_cu
= cu
->per_cu
;
23414 age_cached_comp_units (dwarf2_per_objfile
);
23419 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23422 struct dwarf2_locexpr_baton
23423 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23424 struct dwarf2_per_cu_data
*per_cu
,
23425 CORE_ADDR (*get_frame_pc
) (void *baton
),
23428 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23430 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23433 /* Write a constant of a given type as target-ordered bytes into
23436 static const gdb_byte
*
23437 write_constant_as_bytes (struct obstack
*obstack
,
23438 enum bfd_endian byte_order
,
23445 *len
= TYPE_LENGTH (type
);
23446 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23447 store_unsigned_integer (result
, *len
, byte_order
, value
);
23452 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23453 pointer to the constant bytes and set LEN to the length of the
23454 data. If memory is needed, allocate it on OBSTACK. If the DIE
23455 does not have a DW_AT_const_value, return NULL. */
23458 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23459 struct dwarf2_per_cu_data
*per_cu
,
23460 struct obstack
*obstack
,
23463 struct dwarf2_cu
*cu
;
23464 struct die_info
*die
;
23465 struct attribute
*attr
;
23466 const gdb_byte
*result
= NULL
;
23469 enum bfd_endian byte_order
;
23470 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23472 if (per_cu
->cu
== NULL
)
23473 load_cu (per_cu
, false);
23477 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23478 Instead just throw an error, not much else we can do. */
23479 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23480 sect_offset_str (sect_off
), objfile_name (objfile
));
23483 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23485 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23486 sect_offset_str (sect_off
), objfile_name (objfile
));
23488 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23492 byte_order
= (bfd_big_endian (objfile
->obfd
)
23493 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23495 switch (attr
->form
)
23498 case DW_FORM_addrx
:
23499 case DW_FORM_GNU_addr_index
:
23503 *len
= cu
->header
.addr_size
;
23504 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23505 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23509 case DW_FORM_string
:
23512 case DW_FORM_GNU_str_index
:
23513 case DW_FORM_GNU_strp_alt
:
23514 /* DW_STRING is already allocated on the objfile obstack, point
23516 result
= (const gdb_byte
*) DW_STRING (attr
);
23517 *len
= strlen (DW_STRING (attr
));
23519 case DW_FORM_block1
:
23520 case DW_FORM_block2
:
23521 case DW_FORM_block4
:
23522 case DW_FORM_block
:
23523 case DW_FORM_exprloc
:
23524 case DW_FORM_data16
:
23525 result
= DW_BLOCK (attr
)->data
;
23526 *len
= DW_BLOCK (attr
)->size
;
23529 /* The DW_AT_const_value attributes are supposed to carry the
23530 symbol's value "represented as it would be on the target
23531 architecture." By the time we get here, it's already been
23532 converted to host endianness, so we just need to sign- or
23533 zero-extend it as appropriate. */
23534 case DW_FORM_data1
:
23535 type
= die_type (die
, cu
);
23536 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23537 if (result
== NULL
)
23538 result
= write_constant_as_bytes (obstack
, byte_order
,
23541 case DW_FORM_data2
:
23542 type
= die_type (die
, cu
);
23543 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23544 if (result
== NULL
)
23545 result
= write_constant_as_bytes (obstack
, byte_order
,
23548 case DW_FORM_data4
:
23549 type
= die_type (die
, cu
);
23550 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23551 if (result
== NULL
)
23552 result
= write_constant_as_bytes (obstack
, byte_order
,
23555 case DW_FORM_data8
:
23556 type
= die_type (die
, cu
);
23557 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23558 if (result
== NULL
)
23559 result
= write_constant_as_bytes (obstack
, byte_order
,
23563 case DW_FORM_sdata
:
23564 case DW_FORM_implicit_const
:
23565 type
= die_type (die
, cu
);
23566 result
= write_constant_as_bytes (obstack
, byte_order
,
23567 type
, DW_SND (attr
), len
);
23570 case DW_FORM_udata
:
23571 type
= die_type (die
, cu
);
23572 result
= write_constant_as_bytes (obstack
, byte_order
,
23573 type
, DW_UNSND (attr
), len
);
23577 complaint (_("unsupported const value attribute form: '%s'"),
23578 dwarf_form_name (attr
->form
));
23585 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23586 valid type for this die is found. */
23589 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23590 struct dwarf2_per_cu_data
*per_cu
)
23592 struct dwarf2_cu
*cu
;
23593 struct die_info
*die
;
23595 if (per_cu
->cu
== NULL
)
23596 load_cu (per_cu
, false);
23601 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23605 return die_type (die
, cu
);
23608 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23612 dwarf2_get_die_type (cu_offset die_offset
,
23613 struct dwarf2_per_cu_data
*per_cu
)
23615 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23616 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23619 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23620 On entry *REF_CU is the CU of SRC_DIE.
23621 On exit *REF_CU is the CU of the result.
23622 Returns NULL if the referenced DIE isn't found. */
23624 static struct die_info
*
23625 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23626 struct dwarf2_cu
**ref_cu
)
23628 struct die_info temp_die
;
23629 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23630 struct die_info
*die
;
23632 /* While it might be nice to assert sig_type->type == NULL here,
23633 we can get here for DW_AT_imported_declaration where we need
23634 the DIE not the type. */
23636 /* If necessary, add it to the queue and load its DIEs. */
23638 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23639 read_signatured_type (sig_type
);
23641 sig_cu
= sig_type
->per_cu
.cu
;
23642 gdb_assert (sig_cu
!= NULL
);
23643 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23644 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23645 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23646 to_underlying (temp_die
.sect_off
));
23649 struct dwarf2_per_objfile
*dwarf2_per_objfile
23650 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23652 /* For .gdb_index version 7 keep track of included TUs.
23653 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23654 if (dwarf2_per_objfile
->index_table
!= NULL
23655 && dwarf2_per_objfile
->index_table
->version
<= 7)
23657 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23662 sig_cu
->ancestor
= cu
;
23670 /* Follow signatured type referenced by ATTR in SRC_DIE.
23671 On entry *REF_CU is the CU of SRC_DIE.
23672 On exit *REF_CU is the CU of the result.
23673 The result is the DIE of the type.
23674 If the referenced type cannot be found an error is thrown. */
23676 static struct die_info
*
23677 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23678 struct dwarf2_cu
**ref_cu
)
23680 ULONGEST signature
= DW_SIGNATURE (attr
);
23681 struct signatured_type
*sig_type
;
23682 struct die_info
*die
;
23684 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23686 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23687 /* sig_type will be NULL if the signatured type is missing from
23689 if (sig_type
== NULL
)
23691 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23692 " from DIE at %s [in module %s]"),
23693 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23694 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23697 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23700 dump_die_for_error (src_die
);
23701 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23702 " from DIE at %s [in module %s]"),
23703 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23704 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23710 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23711 reading in and processing the type unit if necessary. */
23713 static struct type
*
23714 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23715 struct dwarf2_cu
*cu
)
23717 struct dwarf2_per_objfile
*dwarf2_per_objfile
23718 = cu
->per_cu
->dwarf2_per_objfile
;
23719 struct signatured_type
*sig_type
;
23720 struct dwarf2_cu
*type_cu
;
23721 struct die_info
*type_die
;
23724 sig_type
= lookup_signatured_type (cu
, signature
);
23725 /* sig_type will be NULL if the signatured type is missing from
23727 if (sig_type
== NULL
)
23729 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23730 " from DIE at %s [in module %s]"),
23731 hex_string (signature
), sect_offset_str (die
->sect_off
),
23732 objfile_name (dwarf2_per_objfile
->objfile
));
23733 return build_error_marker_type (cu
, die
);
23736 /* If we already know the type we're done. */
23737 if (sig_type
->type
!= NULL
)
23738 return sig_type
->type
;
23741 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23742 if (type_die
!= NULL
)
23744 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23745 is created. This is important, for example, because for c++ classes
23746 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23747 type
= read_type_die (type_die
, type_cu
);
23750 complaint (_("Dwarf Error: Cannot build signatured type %s"
23751 " referenced from DIE at %s [in module %s]"),
23752 hex_string (signature
), sect_offset_str (die
->sect_off
),
23753 objfile_name (dwarf2_per_objfile
->objfile
));
23754 type
= build_error_marker_type (cu
, die
);
23759 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23760 " from DIE at %s [in module %s]"),
23761 hex_string (signature
), sect_offset_str (die
->sect_off
),
23762 objfile_name (dwarf2_per_objfile
->objfile
));
23763 type
= build_error_marker_type (cu
, die
);
23765 sig_type
->type
= type
;
23770 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23771 reading in and processing the type unit if necessary. */
23773 static struct type
*
23774 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23775 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23777 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23778 if (attr_form_is_ref (attr
))
23780 struct dwarf2_cu
*type_cu
= cu
;
23781 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23783 return read_type_die (type_die
, type_cu
);
23785 else if (attr
->form
== DW_FORM_ref_sig8
)
23787 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23791 struct dwarf2_per_objfile
*dwarf2_per_objfile
23792 = cu
->per_cu
->dwarf2_per_objfile
;
23794 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23795 " at %s [in module %s]"),
23796 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23797 objfile_name (dwarf2_per_objfile
->objfile
));
23798 return build_error_marker_type (cu
, die
);
23802 /* Load the DIEs associated with type unit PER_CU into memory. */
23805 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23807 struct signatured_type
*sig_type
;
23809 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23810 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23812 /* We have the per_cu, but we need the signatured_type.
23813 Fortunately this is an easy translation. */
23814 gdb_assert (per_cu
->is_debug_types
);
23815 sig_type
= (struct signatured_type
*) per_cu
;
23817 gdb_assert (per_cu
->cu
== NULL
);
23819 read_signatured_type (sig_type
);
23821 gdb_assert (per_cu
->cu
!= NULL
);
23824 /* die_reader_func for read_signatured_type.
23825 This is identical to load_full_comp_unit_reader,
23826 but is kept separate for now. */
23829 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23830 const gdb_byte
*info_ptr
,
23831 struct die_info
*comp_unit_die
,
23835 struct dwarf2_cu
*cu
= reader
->cu
;
23837 gdb_assert (cu
->die_hash
== NULL
);
23839 htab_create_alloc_ex (cu
->header
.length
/ 12,
23843 &cu
->comp_unit_obstack
,
23844 hashtab_obstack_allocate
,
23845 dummy_obstack_deallocate
);
23848 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23849 &info_ptr
, comp_unit_die
);
23850 cu
->dies
= comp_unit_die
;
23851 /* comp_unit_die is not stored in die_hash, no need. */
23853 /* We try not to read any attributes in this function, because not
23854 all CUs needed for references have been loaded yet, and symbol
23855 table processing isn't initialized. But we have to set the CU language,
23856 or we won't be able to build types correctly.
23857 Similarly, if we do not read the producer, we can not apply
23858 producer-specific interpretation. */
23859 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23862 /* Read in a signatured type and build its CU and DIEs.
23863 If the type is a stub for the real type in a DWO file,
23864 read in the real type from the DWO file as well. */
23867 read_signatured_type (struct signatured_type
*sig_type
)
23869 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23871 gdb_assert (per_cu
->is_debug_types
);
23872 gdb_assert (per_cu
->cu
== NULL
);
23874 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1, false,
23875 read_signatured_type_reader
, NULL
);
23876 sig_type
->per_cu
.tu_read
= 1;
23879 /* Decode simple location descriptions.
23880 Given a pointer to a dwarf block that defines a location, compute
23881 the location and return the value.
23883 NOTE drow/2003-11-18: This function is called in two situations
23884 now: for the address of static or global variables (partial symbols
23885 only) and for offsets into structures which are expected to be
23886 (more or less) constant. The partial symbol case should go away,
23887 and only the constant case should remain. That will let this
23888 function complain more accurately. A few special modes are allowed
23889 without complaint for global variables (for instance, global
23890 register values and thread-local values).
23892 A location description containing no operations indicates that the
23893 object is optimized out. The return value is 0 for that case.
23894 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23895 callers will only want a very basic result and this can become a
23898 Note that stack[0] is unused except as a default error return. */
23901 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23903 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23905 size_t size
= blk
->size
;
23906 const gdb_byte
*data
= blk
->data
;
23907 CORE_ADDR stack
[64];
23909 unsigned int bytes_read
, unsnd
;
23915 stack
[++stacki
] = 0;
23954 stack
[++stacki
] = op
- DW_OP_lit0
;
23989 stack
[++stacki
] = op
- DW_OP_reg0
;
23991 dwarf2_complex_location_expr_complaint ();
23995 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23997 stack
[++stacki
] = unsnd
;
23999 dwarf2_complex_location_expr_complaint ();
24003 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24008 case DW_OP_const1u
:
24009 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24013 case DW_OP_const1s
:
24014 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24018 case DW_OP_const2u
:
24019 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24023 case DW_OP_const2s
:
24024 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24028 case DW_OP_const4u
:
24029 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24033 case DW_OP_const4s
:
24034 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24038 case DW_OP_const8u
:
24039 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24044 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24050 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24055 stack
[stacki
+ 1] = stack
[stacki
];
24060 stack
[stacki
- 1] += stack
[stacki
];
24064 case DW_OP_plus_uconst
:
24065 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24071 stack
[stacki
- 1] -= stack
[stacki
];
24076 /* If we're not the last op, then we definitely can't encode
24077 this using GDB's address_class enum. This is valid for partial
24078 global symbols, although the variable's address will be bogus
24081 dwarf2_complex_location_expr_complaint ();
24084 case DW_OP_GNU_push_tls_address
:
24085 case DW_OP_form_tls_address
:
24086 /* The top of the stack has the offset from the beginning
24087 of the thread control block at which the variable is located. */
24088 /* Nothing should follow this operator, so the top of stack would
24090 /* This is valid for partial global symbols, but the variable's
24091 address will be bogus in the psymtab. Make it always at least
24092 non-zero to not look as a variable garbage collected by linker
24093 which have DW_OP_addr 0. */
24095 dwarf2_complex_location_expr_complaint ();
24099 case DW_OP_GNU_uninit
:
24103 case DW_OP_GNU_addr_index
:
24104 case DW_OP_GNU_const_index
:
24105 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24112 const char *name
= get_DW_OP_name (op
);
24115 complaint (_("unsupported stack op: '%s'"),
24118 complaint (_("unsupported stack op: '%02x'"),
24122 return (stack
[stacki
]);
24125 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24126 outside of the allocated space. Also enforce minimum>0. */
24127 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24129 complaint (_("location description stack overflow"));
24135 complaint (_("location description stack underflow"));
24139 return (stack
[stacki
]);
24142 /* memory allocation interface */
24144 static struct dwarf_block
*
24145 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24147 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24150 static struct die_info
*
24151 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24153 struct die_info
*die
;
24154 size_t size
= sizeof (struct die_info
);
24157 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24159 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24160 memset (die
, 0, sizeof (struct die_info
));
24165 /* Macro support. */
24167 /* Return file name relative to the compilation directory of file number I in
24168 *LH's file name table. The result is allocated using xmalloc; the caller is
24169 responsible for freeing it. */
24172 file_file_name (int file
, struct line_header
*lh
)
24174 /* Is the file number a valid index into the line header's file name
24175 table? Remember that file numbers start with one, not zero. */
24176 if (1 <= file
&& file
<= lh
->file_names
.size ())
24178 const file_entry
&fe
= lh
->file_names
[file
- 1];
24180 if (!IS_ABSOLUTE_PATH (fe
.name
))
24182 const char *dir
= fe
.include_dir (lh
);
24184 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
24186 return xstrdup (fe
.name
);
24190 /* The compiler produced a bogus file number. We can at least
24191 record the macro definitions made in the file, even if we
24192 won't be able to find the file by name. */
24193 char fake_name
[80];
24195 xsnprintf (fake_name
, sizeof (fake_name
),
24196 "<bad macro file number %d>", file
);
24198 complaint (_("bad file number in macro information (%d)"),
24201 return xstrdup (fake_name
);
24205 /* Return the full name of file number I in *LH's file name table.
24206 Use COMP_DIR as the name of the current directory of the
24207 compilation. The result is allocated using xmalloc; the caller is
24208 responsible for freeing it. */
24210 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24212 /* Is the file number a valid index into the line header's file name
24213 table? Remember that file numbers start with one, not zero. */
24214 if (1 <= file
&& file
<= lh
->file_names
.size ())
24216 char *relative
= file_file_name (file
, lh
);
24218 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24220 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24221 relative
, (char *) NULL
);
24224 return file_file_name (file
, lh
);
24228 static struct macro_source_file
*
24229 macro_start_file (struct dwarf2_cu
*cu
,
24230 int file
, int line
,
24231 struct macro_source_file
*current_file
,
24232 struct line_header
*lh
)
24234 /* File name relative to the compilation directory of this source file. */
24235 char *file_name
= file_file_name (file
, lh
);
24237 if (! current_file
)
24239 /* Note: We don't create a macro table for this compilation unit
24240 at all until we actually get a filename. */
24241 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24243 /* If we have no current file, then this must be the start_file
24244 directive for the compilation unit's main source file. */
24245 current_file
= macro_set_main (macro_table
, file_name
);
24246 macro_define_special (macro_table
);
24249 current_file
= macro_include (current_file
, line
, file_name
);
24253 return current_file
;
24256 static const char *
24257 consume_improper_spaces (const char *p
, const char *body
)
24261 complaint (_("macro definition contains spaces "
24262 "in formal argument list:\n`%s'"),
24274 parse_macro_definition (struct macro_source_file
*file
, int line
,
24279 /* The body string takes one of two forms. For object-like macro
24280 definitions, it should be:
24282 <macro name> " " <definition>
24284 For function-like macro definitions, it should be:
24286 <macro name> "() " <definition>
24288 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24290 Spaces may appear only where explicitly indicated, and in the
24293 The Dwarf 2 spec says that an object-like macro's name is always
24294 followed by a space, but versions of GCC around March 2002 omit
24295 the space when the macro's definition is the empty string.
24297 The Dwarf 2 spec says that there should be no spaces between the
24298 formal arguments in a function-like macro's formal argument list,
24299 but versions of GCC around March 2002 include spaces after the
24303 /* Find the extent of the macro name. The macro name is terminated
24304 by either a space or null character (for an object-like macro) or
24305 an opening paren (for a function-like macro). */
24306 for (p
= body
; *p
; p
++)
24307 if (*p
== ' ' || *p
== '(')
24310 if (*p
== ' ' || *p
== '\0')
24312 /* It's an object-like macro. */
24313 int name_len
= p
- body
;
24314 char *name
= savestring (body
, name_len
);
24315 const char *replacement
;
24318 replacement
= body
+ name_len
+ 1;
24321 dwarf2_macro_malformed_definition_complaint (body
);
24322 replacement
= body
+ name_len
;
24325 macro_define_object (file
, line
, name
, replacement
);
24329 else if (*p
== '(')
24331 /* It's a function-like macro. */
24332 char *name
= savestring (body
, p
- body
);
24335 char **argv
= XNEWVEC (char *, argv_size
);
24339 p
= consume_improper_spaces (p
, body
);
24341 /* Parse the formal argument list. */
24342 while (*p
&& *p
!= ')')
24344 /* Find the extent of the current argument name. */
24345 const char *arg_start
= p
;
24347 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24350 if (! *p
|| p
== arg_start
)
24351 dwarf2_macro_malformed_definition_complaint (body
);
24354 /* Make sure argv has room for the new argument. */
24355 if (argc
>= argv_size
)
24358 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24361 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24364 p
= consume_improper_spaces (p
, body
);
24366 /* Consume the comma, if present. */
24371 p
= consume_improper_spaces (p
, body
);
24380 /* Perfectly formed definition, no complaints. */
24381 macro_define_function (file
, line
, name
,
24382 argc
, (const char **) argv
,
24384 else if (*p
== '\0')
24386 /* Complain, but do define it. */
24387 dwarf2_macro_malformed_definition_complaint (body
);
24388 macro_define_function (file
, line
, name
,
24389 argc
, (const char **) argv
,
24393 /* Just complain. */
24394 dwarf2_macro_malformed_definition_complaint (body
);
24397 /* Just complain. */
24398 dwarf2_macro_malformed_definition_complaint (body
);
24404 for (i
= 0; i
< argc
; i
++)
24410 dwarf2_macro_malformed_definition_complaint (body
);
24413 /* Skip some bytes from BYTES according to the form given in FORM.
24414 Returns the new pointer. */
24416 static const gdb_byte
*
24417 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24418 enum dwarf_form form
,
24419 unsigned int offset_size
,
24420 struct dwarf2_section_info
*section
)
24422 unsigned int bytes_read
;
24426 case DW_FORM_data1
:
24431 case DW_FORM_data2
:
24435 case DW_FORM_data4
:
24439 case DW_FORM_data8
:
24443 case DW_FORM_data16
:
24447 case DW_FORM_string
:
24448 read_direct_string (abfd
, bytes
, &bytes_read
);
24449 bytes
+= bytes_read
;
24452 case DW_FORM_sec_offset
:
24454 case DW_FORM_GNU_strp_alt
:
24455 bytes
+= offset_size
;
24458 case DW_FORM_block
:
24459 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24460 bytes
+= bytes_read
;
24463 case DW_FORM_block1
:
24464 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24466 case DW_FORM_block2
:
24467 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24469 case DW_FORM_block4
:
24470 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24473 case DW_FORM_addrx
:
24474 case DW_FORM_sdata
:
24476 case DW_FORM_udata
:
24477 case DW_FORM_GNU_addr_index
:
24478 case DW_FORM_GNU_str_index
:
24479 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24482 dwarf2_section_buffer_overflow_complaint (section
);
24487 case DW_FORM_implicit_const
:
24492 complaint (_("invalid form 0x%x in `%s'"),
24493 form
, get_section_name (section
));
24501 /* A helper for dwarf_decode_macros that handles skipping an unknown
24502 opcode. Returns an updated pointer to the macro data buffer; or,
24503 on error, issues a complaint and returns NULL. */
24505 static const gdb_byte
*
24506 skip_unknown_opcode (unsigned int opcode
,
24507 const gdb_byte
**opcode_definitions
,
24508 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24510 unsigned int offset_size
,
24511 struct dwarf2_section_info
*section
)
24513 unsigned int bytes_read
, i
;
24515 const gdb_byte
*defn
;
24517 if (opcode_definitions
[opcode
] == NULL
)
24519 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24524 defn
= opcode_definitions
[opcode
];
24525 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24526 defn
+= bytes_read
;
24528 for (i
= 0; i
< arg
; ++i
)
24530 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24531 (enum dwarf_form
) defn
[i
], offset_size
,
24533 if (mac_ptr
== NULL
)
24535 /* skip_form_bytes already issued the complaint. */
24543 /* A helper function which parses the header of a macro section.
24544 If the macro section is the extended (for now called "GNU") type,
24545 then this updates *OFFSET_SIZE. Returns a pointer to just after
24546 the header, or issues a complaint and returns NULL on error. */
24548 static const gdb_byte
*
24549 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24551 const gdb_byte
*mac_ptr
,
24552 unsigned int *offset_size
,
24553 int section_is_gnu
)
24555 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24557 if (section_is_gnu
)
24559 unsigned int version
, flags
;
24561 version
= read_2_bytes (abfd
, mac_ptr
);
24562 if (version
!= 4 && version
!= 5)
24564 complaint (_("unrecognized version `%d' in .debug_macro section"),
24570 flags
= read_1_byte (abfd
, mac_ptr
);
24572 *offset_size
= (flags
& 1) ? 8 : 4;
24574 if ((flags
& 2) != 0)
24575 /* We don't need the line table offset. */
24576 mac_ptr
+= *offset_size
;
24578 /* Vendor opcode descriptions. */
24579 if ((flags
& 4) != 0)
24581 unsigned int i
, count
;
24583 count
= read_1_byte (abfd
, mac_ptr
);
24585 for (i
= 0; i
< count
; ++i
)
24587 unsigned int opcode
, bytes_read
;
24590 opcode
= read_1_byte (abfd
, mac_ptr
);
24592 opcode_definitions
[opcode
] = mac_ptr
;
24593 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24594 mac_ptr
+= bytes_read
;
24603 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24604 including DW_MACRO_import. */
24607 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24609 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24610 struct macro_source_file
*current_file
,
24611 struct line_header
*lh
,
24612 struct dwarf2_section_info
*section
,
24613 int section_is_gnu
, int section_is_dwz
,
24614 unsigned int offset_size
,
24615 htab_t include_hash
)
24617 struct dwarf2_per_objfile
*dwarf2_per_objfile
24618 = cu
->per_cu
->dwarf2_per_objfile
;
24619 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24620 enum dwarf_macro_record_type macinfo_type
;
24621 int at_commandline
;
24622 const gdb_byte
*opcode_definitions
[256];
24624 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24625 &offset_size
, section_is_gnu
);
24626 if (mac_ptr
== NULL
)
24628 /* We already issued a complaint. */
24632 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24633 GDB is still reading the definitions from command line. First
24634 DW_MACINFO_start_file will need to be ignored as it was already executed
24635 to create CURRENT_FILE for the main source holding also the command line
24636 definitions. On first met DW_MACINFO_start_file this flag is reset to
24637 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24639 at_commandline
= 1;
24643 /* Do we at least have room for a macinfo type byte? */
24644 if (mac_ptr
>= mac_end
)
24646 dwarf2_section_buffer_overflow_complaint (section
);
24650 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24653 /* Note that we rely on the fact that the corresponding GNU and
24654 DWARF constants are the same. */
24656 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24657 switch (macinfo_type
)
24659 /* A zero macinfo type indicates the end of the macro
24664 case DW_MACRO_define
:
24665 case DW_MACRO_undef
:
24666 case DW_MACRO_define_strp
:
24667 case DW_MACRO_undef_strp
:
24668 case DW_MACRO_define_sup
:
24669 case DW_MACRO_undef_sup
:
24671 unsigned int bytes_read
;
24676 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24677 mac_ptr
+= bytes_read
;
24679 if (macinfo_type
== DW_MACRO_define
24680 || macinfo_type
== DW_MACRO_undef
)
24682 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24683 mac_ptr
+= bytes_read
;
24687 LONGEST str_offset
;
24689 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24690 mac_ptr
+= offset_size
;
24692 if (macinfo_type
== DW_MACRO_define_sup
24693 || macinfo_type
== DW_MACRO_undef_sup
24696 struct dwz_file
*dwz
24697 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24699 body
= read_indirect_string_from_dwz (objfile
,
24703 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24707 is_define
= (macinfo_type
== DW_MACRO_define
24708 || macinfo_type
== DW_MACRO_define_strp
24709 || macinfo_type
== DW_MACRO_define_sup
);
24710 if (! current_file
)
24712 /* DWARF violation as no main source is present. */
24713 complaint (_("debug info with no main source gives macro %s "
24715 is_define
? _("definition") : _("undefinition"),
24719 if ((line
== 0 && !at_commandline
)
24720 || (line
!= 0 && at_commandline
))
24721 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
24722 at_commandline
? _("command-line") : _("in-file"),
24723 is_define
? _("definition") : _("undefinition"),
24724 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24728 /* Fedora's rpm-build's "debugedit" binary
24729 corrupted .debug_macro sections.
24732 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
24733 complaint (_("debug info gives %s invalid macro %s "
24734 "without body (corrupted?) at line %d "
24736 at_commandline
? _("command-line") : _("in-file"),
24737 is_define
? _("definition") : _("undefinition"),
24738 line
, current_file
->filename
);
24740 else if (is_define
)
24741 parse_macro_definition (current_file
, line
, body
);
24744 gdb_assert (macinfo_type
== DW_MACRO_undef
24745 || macinfo_type
== DW_MACRO_undef_strp
24746 || macinfo_type
== DW_MACRO_undef_sup
);
24747 macro_undef (current_file
, line
, body
);
24752 case DW_MACRO_start_file
:
24754 unsigned int bytes_read
;
24757 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24758 mac_ptr
+= bytes_read
;
24759 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24760 mac_ptr
+= bytes_read
;
24762 if ((line
== 0 && !at_commandline
)
24763 || (line
!= 0 && at_commandline
))
24764 complaint (_("debug info gives source %d included "
24765 "from %s at %s line %d"),
24766 file
, at_commandline
? _("command-line") : _("file"),
24767 line
== 0 ? _("zero") : _("non-zero"), line
);
24769 if (at_commandline
)
24771 /* This DW_MACRO_start_file was executed in the
24773 at_commandline
= 0;
24776 current_file
= macro_start_file (cu
, file
, line
, current_file
,
24781 case DW_MACRO_end_file
:
24782 if (! current_file
)
24783 complaint (_("macro debug info has an unmatched "
24784 "`close_file' directive"));
24787 current_file
= current_file
->included_by
;
24788 if (! current_file
)
24790 enum dwarf_macro_record_type next_type
;
24792 /* GCC circa March 2002 doesn't produce the zero
24793 type byte marking the end of the compilation
24794 unit. Complain if it's not there, but exit no
24797 /* Do we at least have room for a macinfo type byte? */
24798 if (mac_ptr
>= mac_end
)
24800 dwarf2_section_buffer_overflow_complaint (section
);
24804 /* We don't increment mac_ptr here, so this is just
24807 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24809 if (next_type
!= 0)
24810 complaint (_("no terminating 0-type entry for "
24811 "macros in `.debug_macinfo' section"));
24818 case DW_MACRO_import
:
24819 case DW_MACRO_import_sup
:
24823 bfd
*include_bfd
= abfd
;
24824 struct dwarf2_section_info
*include_section
= section
;
24825 const gdb_byte
*include_mac_end
= mac_end
;
24826 int is_dwz
= section_is_dwz
;
24827 const gdb_byte
*new_mac_ptr
;
24829 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24830 mac_ptr
+= offset_size
;
24832 if (macinfo_type
== DW_MACRO_import_sup
)
24834 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24836 dwarf2_read_section (objfile
, &dwz
->macro
);
24838 include_section
= &dwz
->macro
;
24839 include_bfd
= get_section_bfd_owner (include_section
);
24840 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24844 new_mac_ptr
= include_section
->buffer
+ offset
;
24845 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24849 /* This has actually happened; see
24850 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24851 complaint (_("recursive DW_MACRO_import in "
24852 ".debug_macro section"));
24856 *slot
= (void *) new_mac_ptr
;
24858 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
24859 include_mac_end
, current_file
, lh
,
24860 section
, section_is_gnu
, is_dwz
,
24861 offset_size
, include_hash
);
24863 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24868 case DW_MACINFO_vendor_ext
:
24869 if (!section_is_gnu
)
24871 unsigned int bytes_read
;
24873 /* This reads the constant, but since we don't recognize
24874 any vendor extensions, we ignore it. */
24875 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24876 mac_ptr
+= bytes_read
;
24877 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24878 mac_ptr
+= bytes_read
;
24880 /* We don't recognize any vendor extensions. */
24886 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24887 mac_ptr
, mac_end
, abfd
, offset_size
,
24889 if (mac_ptr
== NULL
)
24894 } while (macinfo_type
!= 0);
24898 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24899 int section_is_gnu
)
24901 struct dwarf2_per_objfile
*dwarf2_per_objfile
24902 = cu
->per_cu
->dwarf2_per_objfile
;
24903 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24904 struct line_header
*lh
= cu
->line_header
;
24906 const gdb_byte
*mac_ptr
, *mac_end
;
24907 struct macro_source_file
*current_file
= 0;
24908 enum dwarf_macro_record_type macinfo_type
;
24909 unsigned int offset_size
= cu
->header
.offset_size
;
24910 const gdb_byte
*opcode_definitions
[256];
24912 struct dwarf2_section_info
*section
;
24913 const char *section_name
;
24915 if (cu
->dwo_unit
!= NULL
)
24917 if (section_is_gnu
)
24919 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24920 section_name
= ".debug_macro.dwo";
24924 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24925 section_name
= ".debug_macinfo.dwo";
24930 if (section_is_gnu
)
24932 section
= &dwarf2_per_objfile
->macro
;
24933 section_name
= ".debug_macro";
24937 section
= &dwarf2_per_objfile
->macinfo
;
24938 section_name
= ".debug_macinfo";
24942 dwarf2_read_section (objfile
, section
);
24943 if (section
->buffer
== NULL
)
24945 complaint (_("missing %s section"), section_name
);
24948 abfd
= get_section_bfd_owner (section
);
24950 /* First pass: Find the name of the base filename.
24951 This filename is needed in order to process all macros whose definition
24952 (or undefinition) comes from the command line. These macros are defined
24953 before the first DW_MACINFO_start_file entry, and yet still need to be
24954 associated to the base file.
24956 To determine the base file name, we scan the macro definitions until we
24957 reach the first DW_MACINFO_start_file entry. We then initialize
24958 CURRENT_FILE accordingly so that any macro definition found before the
24959 first DW_MACINFO_start_file can still be associated to the base file. */
24961 mac_ptr
= section
->buffer
+ offset
;
24962 mac_end
= section
->buffer
+ section
->size
;
24964 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24965 &offset_size
, section_is_gnu
);
24966 if (mac_ptr
== NULL
)
24968 /* We already issued a complaint. */
24974 /* Do we at least have room for a macinfo type byte? */
24975 if (mac_ptr
>= mac_end
)
24977 /* Complaint is printed during the second pass as GDB will probably
24978 stop the first pass earlier upon finding
24979 DW_MACINFO_start_file. */
24983 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24986 /* Note that we rely on the fact that the corresponding GNU and
24987 DWARF constants are the same. */
24989 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24990 switch (macinfo_type
)
24992 /* A zero macinfo type indicates the end of the macro
24997 case DW_MACRO_define
:
24998 case DW_MACRO_undef
:
24999 /* Only skip the data by MAC_PTR. */
25001 unsigned int bytes_read
;
25003 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25004 mac_ptr
+= bytes_read
;
25005 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25006 mac_ptr
+= bytes_read
;
25010 case DW_MACRO_start_file
:
25012 unsigned int bytes_read
;
25015 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25016 mac_ptr
+= bytes_read
;
25017 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25018 mac_ptr
+= bytes_read
;
25020 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
25024 case DW_MACRO_end_file
:
25025 /* No data to skip by MAC_PTR. */
25028 case DW_MACRO_define_strp
:
25029 case DW_MACRO_undef_strp
:
25030 case DW_MACRO_define_sup
:
25031 case DW_MACRO_undef_sup
:
25033 unsigned int bytes_read
;
25035 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25036 mac_ptr
+= bytes_read
;
25037 mac_ptr
+= offset_size
;
25041 case DW_MACRO_import
:
25042 case DW_MACRO_import_sup
:
25043 /* Note that, according to the spec, a transparent include
25044 chain cannot call DW_MACRO_start_file. So, we can just
25045 skip this opcode. */
25046 mac_ptr
+= offset_size
;
25049 case DW_MACINFO_vendor_ext
:
25050 /* Only skip the data by MAC_PTR. */
25051 if (!section_is_gnu
)
25053 unsigned int bytes_read
;
25055 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25056 mac_ptr
+= bytes_read
;
25057 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25058 mac_ptr
+= bytes_read
;
25063 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25064 mac_ptr
, mac_end
, abfd
, offset_size
,
25066 if (mac_ptr
== NULL
)
25071 } while (macinfo_type
!= 0 && current_file
== NULL
);
25073 /* Second pass: Process all entries.
25075 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25076 command-line macro definitions/undefinitions. This flag is unset when we
25077 reach the first DW_MACINFO_start_file entry. */
25079 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25081 NULL
, xcalloc
, xfree
));
25082 mac_ptr
= section
->buffer
+ offset
;
25083 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25084 *slot
= (void *) mac_ptr
;
25085 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
25086 current_file
, lh
, section
,
25087 section_is_gnu
, 0, offset_size
,
25088 include_hash
.get ());
25091 /* Check if the attribute's form is a DW_FORM_block*
25092 if so return true else false. */
25095 attr_form_is_block (const struct attribute
*attr
)
25097 return (attr
== NULL
? 0 :
25098 attr
->form
== DW_FORM_block1
25099 || attr
->form
== DW_FORM_block2
25100 || attr
->form
== DW_FORM_block4
25101 || attr
->form
== DW_FORM_block
25102 || attr
->form
== DW_FORM_exprloc
);
25105 /* Return non-zero if ATTR's value is a section offset --- classes
25106 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25107 You may use DW_UNSND (attr) to retrieve such offsets.
25109 Section 7.5.4, "Attribute Encodings", explains that no attribute
25110 may have a value that belongs to more than one of these classes; it
25111 would be ambiguous if we did, because we use the same forms for all
25115 attr_form_is_section_offset (const struct attribute
*attr
)
25117 return (attr
->form
== DW_FORM_data4
25118 || attr
->form
== DW_FORM_data8
25119 || attr
->form
== DW_FORM_sec_offset
);
25122 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25123 zero otherwise. When this function returns true, you can apply
25124 dwarf2_get_attr_constant_value to it.
25126 However, note that for some attributes you must check
25127 attr_form_is_section_offset before using this test. DW_FORM_data4
25128 and DW_FORM_data8 are members of both the constant class, and of
25129 the classes that contain offsets into other debug sections
25130 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25131 that, if an attribute's can be either a constant or one of the
25132 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25133 taken as section offsets, not constants.
25135 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25136 cannot handle that. */
25139 attr_form_is_constant (const struct attribute
*attr
)
25141 switch (attr
->form
)
25143 case DW_FORM_sdata
:
25144 case DW_FORM_udata
:
25145 case DW_FORM_data1
:
25146 case DW_FORM_data2
:
25147 case DW_FORM_data4
:
25148 case DW_FORM_data8
:
25149 case DW_FORM_implicit_const
:
25157 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25158 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25161 attr_form_is_ref (const struct attribute
*attr
)
25163 switch (attr
->form
)
25165 case DW_FORM_ref_addr
:
25170 case DW_FORM_ref_udata
:
25171 case DW_FORM_GNU_ref_alt
:
25178 /* Return the .debug_loc section to use for CU.
25179 For DWO files use .debug_loc.dwo. */
25181 static struct dwarf2_section_info
*
25182 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25184 struct dwarf2_per_objfile
*dwarf2_per_objfile
25185 = cu
->per_cu
->dwarf2_per_objfile
;
25189 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25191 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25193 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25194 : &dwarf2_per_objfile
->loc
);
25197 /* A helper function that fills in a dwarf2_loclist_baton. */
25200 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25201 struct dwarf2_loclist_baton
*baton
,
25202 const struct attribute
*attr
)
25204 struct dwarf2_per_objfile
*dwarf2_per_objfile
25205 = cu
->per_cu
->dwarf2_per_objfile
;
25206 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25208 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25210 baton
->per_cu
= cu
->per_cu
;
25211 gdb_assert (baton
->per_cu
);
25212 /* We don't know how long the location list is, but make sure we
25213 don't run off the edge of the section. */
25214 baton
->size
= section
->size
- DW_UNSND (attr
);
25215 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25216 baton
->base_address
= cu
->base_address
;
25217 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25221 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25222 struct dwarf2_cu
*cu
, int is_block
)
25224 struct dwarf2_per_objfile
*dwarf2_per_objfile
25225 = cu
->per_cu
->dwarf2_per_objfile
;
25226 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25227 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25229 if (attr_form_is_section_offset (attr
)
25230 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25231 the section. If so, fall through to the complaint in the
25233 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25235 struct dwarf2_loclist_baton
*baton
;
25237 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25239 fill_in_loclist_baton (cu
, baton
, attr
);
25241 if (cu
->base_known
== 0)
25242 complaint (_("Location list used without "
25243 "specifying the CU base address."));
25245 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25246 ? dwarf2_loclist_block_index
25247 : dwarf2_loclist_index
);
25248 SYMBOL_LOCATION_BATON (sym
) = baton
;
25252 struct dwarf2_locexpr_baton
*baton
;
25254 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25255 baton
->per_cu
= cu
->per_cu
;
25256 gdb_assert (baton
->per_cu
);
25258 if (attr_form_is_block (attr
))
25260 /* Note that we're just copying the block's data pointer
25261 here, not the actual data. We're still pointing into the
25262 info_buffer for SYM's objfile; right now we never release
25263 that buffer, but when we do clean up properly this may
25265 baton
->size
= DW_BLOCK (attr
)->size
;
25266 baton
->data
= DW_BLOCK (attr
)->data
;
25270 dwarf2_invalid_attrib_class_complaint ("location description",
25271 SYMBOL_NATURAL_NAME (sym
));
25275 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25276 ? dwarf2_locexpr_block_index
25277 : dwarf2_locexpr_index
);
25278 SYMBOL_LOCATION_BATON (sym
) = baton
;
25282 /* Return the OBJFILE associated with the compilation unit CU. If CU
25283 came from a separate debuginfo file, then the master objfile is
25287 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25289 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25291 /* Return the master objfile, so that we can report and look up the
25292 correct file containing this variable. */
25293 if (objfile
->separate_debug_objfile_backlink
)
25294 objfile
= objfile
->separate_debug_objfile_backlink
;
25299 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25300 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25301 CU_HEADERP first. */
25303 static const struct comp_unit_head
*
25304 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25305 struct dwarf2_per_cu_data
*per_cu
)
25307 const gdb_byte
*info_ptr
;
25310 return &per_cu
->cu
->header
;
25312 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25314 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25315 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25316 rcuh_kind::COMPILE
);
25321 /* Return the address size given in the compilation unit header for CU. */
25324 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25326 struct comp_unit_head cu_header_local
;
25327 const struct comp_unit_head
*cu_headerp
;
25329 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25331 return cu_headerp
->addr_size
;
25334 /* Return the offset size given in the compilation unit header for CU. */
25337 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25339 struct comp_unit_head cu_header_local
;
25340 const struct comp_unit_head
*cu_headerp
;
25342 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25344 return cu_headerp
->offset_size
;
25347 /* See its dwarf2loc.h declaration. */
25350 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25352 struct comp_unit_head cu_header_local
;
25353 const struct comp_unit_head
*cu_headerp
;
25355 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25357 if (cu_headerp
->version
== 2)
25358 return cu_headerp
->addr_size
;
25360 return cu_headerp
->offset_size
;
25363 /* Return the text offset of the CU. The returned offset comes from
25364 this CU's objfile. If this objfile came from a separate debuginfo
25365 file, then the offset may be different from the corresponding
25366 offset in the parent objfile. */
25369 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25371 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25373 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25376 /* Return a type that is a generic pointer type, the size of which matches
25377 the address size given in the compilation unit header for PER_CU. */
25378 static struct type
*
25379 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25381 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25382 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25383 struct type
*addr_type
= lookup_pointer_type (void_type
);
25384 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25386 if (TYPE_LENGTH (addr_type
) == addr_size
)
25390 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25394 /* Return DWARF version number of PER_CU. */
25397 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25399 return per_cu
->dwarf_version
;
25402 /* Locate the .debug_info compilation unit from CU's objfile which contains
25403 the DIE at OFFSET. Raises an error on failure. */
25405 static struct dwarf2_per_cu_data
*
25406 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25407 unsigned int offset_in_dwz
,
25408 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25410 struct dwarf2_per_cu_data
*this_cu
;
25414 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25417 struct dwarf2_per_cu_data
*mid_cu
;
25418 int mid
= low
+ (high
- low
) / 2;
25420 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25421 if (mid_cu
->is_dwz
> offset_in_dwz
25422 || (mid_cu
->is_dwz
== offset_in_dwz
25423 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25428 gdb_assert (low
== high
);
25429 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25430 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25432 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25433 error (_("Dwarf Error: could not find partial DIE containing "
25434 "offset %s [in module %s]"),
25435 sect_offset_str (sect_off
),
25436 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25438 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25440 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25444 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25445 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25446 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25447 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25452 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25454 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25455 : per_cu (per_cu_
),
25457 has_loclist (false),
25458 checked_producer (false),
25459 producer_is_gxx_lt_4_6 (false),
25460 producer_is_gcc_lt_4_3 (false),
25461 producer_is_icc (false),
25462 producer_is_icc_lt_14 (false),
25463 producer_is_codewarrior (false),
25464 processing_has_namespace_info (false)
25469 /* Destroy a dwarf2_cu. */
25471 dwarf2_cu::~dwarf2_cu ()
25476 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25479 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25480 enum language pretend_language
)
25482 struct attribute
*attr
;
25484 /* Set the language we're debugging. */
25485 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25487 set_cu_language (DW_UNSND (attr
), cu
);
25490 cu
->language
= pretend_language
;
25491 cu
->language_defn
= language_def (cu
->language
);
25494 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25497 /* Increase the age counter on each cached compilation unit, and free
25498 any that are too old. */
25501 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25503 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25505 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25506 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25507 while (per_cu
!= NULL
)
25509 per_cu
->cu
->last_used
++;
25510 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25511 dwarf2_mark (per_cu
->cu
);
25512 per_cu
= per_cu
->cu
->read_in_chain
;
25515 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25516 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25517 while (per_cu
!= NULL
)
25519 struct dwarf2_per_cu_data
*next_cu
;
25521 next_cu
= per_cu
->cu
->read_in_chain
;
25523 if (!per_cu
->cu
->mark
)
25526 *last_chain
= next_cu
;
25529 last_chain
= &per_cu
->cu
->read_in_chain
;
25535 /* Remove a single compilation unit from the cache. */
25538 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25540 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25541 struct dwarf2_per_objfile
*dwarf2_per_objfile
25542 = target_per_cu
->dwarf2_per_objfile
;
25544 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25545 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25546 while (per_cu
!= NULL
)
25548 struct dwarf2_per_cu_data
*next_cu
;
25550 next_cu
= per_cu
->cu
->read_in_chain
;
25552 if (per_cu
== target_per_cu
)
25556 *last_chain
= next_cu
;
25560 last_chain
= &per_cu
->cu
->read_in_chain
;
25566 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25567 We store these in a hash table separate from the DIEs, and preserve them
25568 when the DIEs are flushed out of cache.
25570 The CU "per_cu" pointer is needed because offset alone is not enough to
25571 uniquely identify the type. A file may have multiple .debug_types sections,
25572 or the type may come from a DWO file. Furthermore, while it's more logical
25573 to use per_cu->section+offset, with Fission the section with the data is in
25574 the DWO file but we don't know that section at the point we need it.
25575 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25576 because we can enter the lookup routine, get_die_type_at_offset, from
25577 outside this file, and thus won't necessarily have PER_CU->cu.
25578 Fortunately, PER_CU is stable for the life of the objfile. */
25580 struct dwarf2_per_cu_offset_and_type
25582 const struct dwarf2_per_cu_data
*per_cu
;
25583 sect_offset sect_off
;
25587 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25590 per_cu_offset_and_type_hash (const void *item
)
25592 const struct dwarf2_per_cu_offset_and_type
*ofs
25593 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25595 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25598 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25601 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25603 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25604 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25605 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25606 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25608 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25609 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25612 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25613 table if necessary. For convenience, return TYPE.
25615 The DIEs reading must have careful ordering to:
25616 * Not cause infite loops trying to read in DIEs as a prerequisite for
25617 reading current DIE.
25618 * Not trying to dereference contents of still incompletely read in types
25619 while reading in other DIEs.
25620 * Enable referencing still incompletely read in types just by a pointer to
25621 the type without accessing its fields.
25623 Therefore caller should follow these rules:
25624 * Try to fetch any prerequisite types we may need to build this DIE type
25625 before building the type and calling set_die_type.
25626 * After building type call set_die_type for current DIE as soon as
25627 possible before fetching more types to complete the current type.
25628 * Make the type as complete as possible before fetching more types. */
25630 static struct type
*
25631 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25633 struct dwarf2_per_objfile
*dwarf2_per_objfile
25634 = cu
->per_cu
->dwarf2_per_objfile
;
25635 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25636 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25637 struct attribute
*attr
;
25638 struct dynamic_prop prop
;
25640 /* For Ada types, make sure that the gnat-specific data is always
25641 initialized (if not already set). There are a few types where
25642 we should not be doing so, because the type-specific area is
25643 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25644 where the type-specific area is used to store the floatformat).
25645 But this is not a problem, because the gnat-specific information
25646 is actually not needed for these types. */
25647 if (need_gnat_info (cu
)
25648 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25649 && TYPE_CODE (type
) != TYPE_CODE_FLT
25650 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25651 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25652 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25653 && !HAVE_GNAT_AUX_INFO (type
))
25654 INIT_GNAT_SPECIFIC (type
);
25656 /* Read DW_AT_allocated and set in type. */
25657 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25658 if (attr_form_is_block (attr
))
25660 struct type
*prop_type
25661 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25662 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25663 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25665 else if (attr
!= NULL
)
25667 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25668 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25669 sect_offset_str (die
->sect_off
));
25672 /* Read DW_AT_associated and set in type. */
25673 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25674 if (attr_form_is_block (attr
))
25676 struct type
*prop_type
25677 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25678 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25679 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25681 else if (attr
!= NULL
)
25683 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25684 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25685 sect_offset_str (die
->sect_off
));
25688 /* Read DW_AT_data_location and set in type. */
25689 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25690 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25691 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25692 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25694 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25696 dwarf2_per_objfile
->die_type_hash
=
25697 htab_create_alloc_ex (127,
25698 per_cu_offset_and_type_hash
,
25699 per_cu_offset_and_type_eq
,
25701 &objfile
->objfile_obstack
,
25702 hashtab_obstack_allocate
,
25703 dummy_obstack_deallocate
);
25706 ofs
.per_cu
= cu
->per_cu
;
25707 ofs
.sect_off
= die
->sect_off
;
25709 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25710 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25712 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25713 sect_offset_str (die
->sect_off
));
25714 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25715 struct dwarf2_per_cu_offset_and_type
);
25720 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25721 or return NULL if the die does not have a saved type. */
25723 static struct type
*
25724 get_die_type_at_offset (sect_offset sect_off
,
25725 struct dwarf2_per_cu_data
*per_cu
)
25727 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25728 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25730 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25733 ofs
.per_cu
= per_cu
;
25734 ofs
.sect_off
= sect_off
;
25735 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25736 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25743 /* Look up the type for DIE in CU in die_type_hash,
25744 or return NULL if DIE does not have a saved type. */
25746 static struct type
*
25747 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25749 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25752 /* Add a dependence relationship from CU to REF_PER_CU. */
25755 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25756 struct dwarf2_per_cu_data
*ref_per_cu
)
25760 if (cu
->dependencies
== NULL
)
25762 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25763 NULL
, &cu
->comp_unit_obstack
,
25764 hashtab_obstack_allocate
,
25765 dummy_obstack_deallocate
);
25767 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25769 *slot
= ref_per_cu
;
25772 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25773 Set the mark field in every compilation unit in the
25774 cache that we must keep because we are keeping CU. */
25777 dwarf2_mark_helper (void **slot
, void *data
)
25779 struct dwarf2_per_cu_data
*per_cu
;
25781 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25783 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25784 reading of the chain. As such dependencies remain valid it is not much
25785 useful to track and undo them during QUIT cleanups. */
25786 if (per_cu
->cu
== NULL
)
25789 if (per_cu
->cu
->mark
)
25791 per_cu
->cu
->mark
= true;
25793 if (per_cu
->cu
->dependencies
!= NULL
)
25794 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25799 /* Set the mark field in CU and in every other compilation unit in the
25800 cache that we must keep because we are keeping CU. */
25803 dwarf2_mark (struct dwarf2_cu
*cu
)
25808 if (cu
->dependencies
!= NULL
)
25809 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25813 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25817 per_cu
->cu
->mark
= false;
25818 per_cu
= per_cu
->cu
->read_in_chain
;
25822 /* Trivial hash function for partial_die_info: the hash value of a DIE
25823 is its offset in .debug_info for this objfile. */
25826 partial_die_hash (const void *item
)
25828 const struct partial_die_info
*part_die
25829 = (const struct partial_die_info
*) item
;
25831 return to_underlying (part_die
->sect_off
);
25834 /* Trivial comparison function for partial_die_info structures: two DIEs
25835 are equal if they have the same offset. */
25838 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25840 const struct partial_die_info
*part_die_lhs
25841 = (const struct partial_die_info
*) item_lhs
;
25842 const struct partial_die_info
*part_die_rhs
25843 = (const struct partial_die_info
*) item_rhs
;
25845 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25848 struct cmd_list_element
*set_dwarf_cmdlist
;
25849 struct cmd_list_element
*show_dwarf_cmdlist
;
25852 set_dwarf_cmd (const char *args
, int from_tty
)
25854 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25859 show_dwarf_cmd (const char *args
, int from_tty
)
25861 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25864 bool dwarf_always_disassemble
;
25867 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
25868 struct cmd_list_element
*c
, const char *value
)
25870 fprintf_filtered (file
,
25871 _("Whether to always disassemble "
25872 "DWARF expressions is %s.\n"),
25877 show_check_physname (struct ui_file
*file
, int from_tty
,
25878 struct cmd_list_element
*c
, const char *value
)
25880 fprintf_filtered (file
,
25881 _("Whether to check \"physname\" is %s.\n"),
25886 _initialize_dwarf2_read (void)
25888 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
25889 Set DWARF specific variables.\n\
25890 Configure DWARF variables such as the cache size."),
25891 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25892 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25894 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
25895 Show DWARF specific variables.\n\
25896 Show DWARF variables such as the cache size."),
25897 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25898 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25900 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25901 &dwarf_max_cache_age
, _("\
25902 Set the upper bound on the age of cached DWARF compilation units."), _("\
25903 Show the upper bound on the age of cached DWARF compilation units."), _("\
25904 A higher limit means that cached compilation units will be stored\n\
25905 in memory longer, and more total memory will be used. Zero disables\n\
25906 caching, which can slow down startup."),
25908 show_dwarf_max_cache_age
,
25909 &set_dwarf_cmdlist
,
25910 &show_dwarf_cmdlist
);
25912 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
25913 &dwarf_always_disassemble
, _("\
25914 Set whether `info address' always disassembles DWARF expressions."), _("\
25915 Show whether `info address' always disassembles DWARF expressions."), _("\
25916 When enabled, DWARF expressions are always printed in an assembly-like\n\
25917 syntax. When disabled, expressions will be printed in a more\n\
25918 conversational style, when possible."),
25920 show_dwarf_always_disassemble
,
25921 &set_dwarf_cmdlist
,
25922 &show_dwarf_cmdlist
);
25924 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25925 Set debugging of the DWARF reader."), _("\
25926 Show debugging of the DWARF reader."), _("\
25927 When enabled (non-zero), debugging messages are printed during DWARF\n\
25928 reading and symtab expansion. A value of 1 (one) provides basic\n\
25929 information. A value greater than 1 provides more verbose information."),
25932 &setdebuglist
, &showdebuglist
);
25934 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25935 Set debugging of the DWARF DIE reader."), _("\
25936 Show debugging of the DWARF DIE reader."), _("\
25937 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25938 The value is the maximum depth to print."),
25941 &setdebuglist
, &showdebuglist
);
25943 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25944 Set debugging of the dwarf line reader."), _("\
25945 Show debugging of the dwarf line reader."), _("\
25946 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25947 A value of 1 (one) provides basic information.\n\
25948 A value greater than 1 provides more verbose information."),
25951 &setdebuglist
, &showdebuglist
);
25953 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25954 Set cross-checking of \"physname\" code against demangler."), _("\
25955 Show cross-checking of \"physname\" code against demangler."), _("\
25956 When enabled, GDB's internal \"physname\" code is checked against\n\
25958 NULL
, show_check_physname
,
25959 &setdebuglist
, &showdebuglist
);
25961 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25962 no_class
, &use_deprecated_index_sections
, _("\
25963 Set whether to use deprecated gdb_index sections."), _("\
25964 Show whether to use deprecated gdb_index sections."), _("\
25965 When enabled, deprecated .gdb_index sections are used anyway.\n\
25966 Normally they are ignored either because of a missing feature or\n\
25967 performance issue.\n\
25968 Warning: This option must be enabled before gdb reads the file."),
25971 &setlist
, &showlist
);
25973 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25974 &dwarf2_locexpr_funcs
);
25975 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25976 &dwarf2_loclist_funcs
);
25978 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25979 &dwarf2_block_frame_base_locexpr_funcs
);
25980 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25981 &dwarf2_block_frame_base_loclist_funcs
);
25984 selftests::register_test ("dw2_expand_symtabs_matching",
25985 selftests::dw2_expand_symtabs_matching::run_test
);