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 /* dir_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 and
914 typedef int dir_index
;
916 /* file_name_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5
918 typedef int file_name_index
;
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 (0-based in DWARF 5 and 1-based before).
971 Returns NULL if INDEX is out of bounds. */
972 const char *include_dir_at (dir_index index
) const
978 vec_index
= index
- 1;
979 if (vec_index
< 0 || vec_index
>= m_include_dirs
.size ())
981 return m_include_dirs
[vec_index
];
984 bool is_valid_file_index (int file_index
)
987 return 0 <= file_index
&& file_index
< file_names_size ();
988 return 1 <= file_index
&& file_index
<= file_names_size ();
991 /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before).
992 Returns NULL if INDEX is out of bounds. */
993 file_entry
*file_name_at (file_name_index index
)
999 vec_index
= index
- 1;
1000 if (vec_index
< 0 || vec_index
>= m_file_names
.size ())
1002 return &m_file_names
[vec_index
];
1005 /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
1006 this method should only be used to iterate through all file entries in an
1007 index-agnostic manner. */
1008 std::vector
<file_entry
> &file_names ()
1009 { return m_file_names
; }
1011 /* Offset of line number information in .debug_line section. */
1012 sect_offset sect_off
{};
1014 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1015 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1017 unsigned int total_length
{};
1018 unsigned short version
{};
1019 unsigned int header_length
{};
1020 unsigned char minimum_instruction_length
{};
1021 unsigned char maximum_ops_per_instruction
{};
1022 unsigned char default_is_stmt
{};
1024 unsigned char line_range
{};
1025 unsigned char opcode_base
{};
1027 /* standard_opcode_lengths[i] is the number of operands for the
1028 standard opcode whose value is i. This means that
1029 standard_opcode_lengths[0] is unused, and the last meaningful
1030 element is standard_opcode_lengths[opcode_base - 1]. */
1031 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1033 int file_names_size ()
1034 { return m_file_names
.size(); }
1036 /* The start and end of the statement program following this
1037 header. These point into dwarf2_per_objfile->line_buffer. */
1038 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1041 /* The include_directories table. Note these are observing
1042 pointers. The memory is owned by debug_line_buffer. */
1043 std::vector
<const char *> m_include_dirs
;
1045 /* The file_names table. This is private because the meaning of indexes
1046 differs among DWARF versions (The first valid index is 1 in DWARF 4 and
1047 before, and is 0 in DWARF 5 and later). So the client should use
1048 file_name_at method for access. */
1049 std::vector
<file_entry
> m_file_names
;
1052 typedef std::unique_ptr
<line_header
> line_header_up
;
1055 file_entry::include_dir (const line_header
*lh
) const
1057 return lh
->include_dir_at (d_index
);
1060 /* When we construct a partial symbol table entry we only
1061 need this much information. */
1062 struct partial_die_info
: public allocate_on_obstack
1064 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1066 /* Disable assign but still keep copy ctor, which is needed
1067 load_partial_dies. */
1068 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1070 /* Adjust the partial die before generating a symbol for it. This
1071 function may set the is_external flag or change the DIE's
1073 void fixup (struct dwarf2_cu
*cu
);
1075 /* Read a minimal amount of information into the minimal die
1077 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1078 const struct abbrev_info
&abbrev
,
1079 const gdb_byte
*info_ptr
);
1081 /* Offset of this DIE. */
1082 const sect_offset sect_off
;
1084 /* DWARF-2 tag for this DIE. */
1085 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1087 /* Assorted flags describing the data found in this DIE. */
1088 const unsigned int has_children
: 1;
1090 unsigned int is_external
: 1;
1091 unsigned int is_declaration
: 1;
1092 unsigned int has_type
: 1;
1093 unsigned int has_specification
: 1;
1094 unsigned int has_pc_info
: 1;
1095 unsigned int may_be_inlined
: 1;
1097 /* This DIE has been marked DW_AT_main_subprogram. */
1098 unsigned int main_subprogram
: 1;
1100 /* Flag set if the SCOPE field of this structure has been
1102 unsigned int scope_set
: 1;
1104 /* Flag set if the DIE has a byte_size attribute. */
1105 unsigned int has_byte_size
: 1;
1107 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1108 unsigned int has_const_value
: 1;
1110 /* Flag set if any of the DIE's children are template arguments. */
1111 unsigned int has_template_arguments
: 1;
1113 /* Flag set if fixup has been called on this die. */
1114 unsigned int fixup_called
: 1;
1116 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1117 unsigned int is_dwz
: 1;
1119 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1120 unsigned int spec_is_dwz
: 1;
1122 /* The name of this DIE. Normally the value of DW_AT_name, but
1123 sometimes a default name for unnamed DIEs. */
1124 const char *name
= nullptr;
1126 /* The linkage name, if present. */
1127 const char *linkage_name
= nullptr;
1129 /* The scope to prepend to our children. This is generally
1130 allocated on the comp_unit_obstack, so will disappear
1131 when this compilation unit leaves the cache. */
1132 const char *scope
= nullptr;
1134 /* Some data associated with the partial DIE. The tag determines
1135 which field is live. */
1138 /* The location description associated with this DIE, if any. */
1139 struct dwarf_block
*locdesc
;
1140 /* The offset of an import, for DW_TAG_imported_unit. */
1141 sect_offset sect_off
;
1144 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1145 CORE_ADDR lowpc
= 0;
1146 CORE_ADDR highpc
= 0;
1148 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1149 DW_AT_sibling, if any. */
1150 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1151 could return DW_AT_sibling values to its caller load_partial_dies. */
1152 const gdb_byte
*sibling
= nullptr;
1154 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1155 DW_AT_specification (or DW_AT_abstract_origin or
1156 DW_AT_extension). */
1157 sect_offset spec_offset
{};
1159 /* Pointers to this DIE's parent, first child, and next sibling,
1161 struct partial_die_info
*die_parent
= nullptr;
1162 struct partial_die_info
*die_child
= nullptr;
1163 struct partial_die_info
*die_sibling
= nullptr;
1165 friend struct partial_die_info
*
1166 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1169 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1170 partial_die_info (sect_offset sect_off
)
1171 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1175 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1177 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1182 has_specification
= 0;
1185 main_subprogram
= 0;
1188 has_const_value
= 0;
1189 has_template_arguments
= 0;
1196 /* This data structure holds the information of an abbrev. */
1199 unsigned int number
; /* number identifying abbrev */
1200 enum dwarf_tag tag
; /* dwarf tag */
1201 unsigned short has_children
; /* boolean */
1202 unsigned short num_attrs
; /* number of attributes */
1203 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1204 struct abbrev_info
*next
; /* next in chain */
1209 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1210 ENUM_BITFIELD(dwarf_form
) form
: 16;
1212 /* It is valid only if FORM is DW_FORM_implicit_const. */
1213 LONGEST implicit_const
;
1216 /* Size of abbrev_table.abbrev_hash_table. */
1217 #define ABBREV_HASH_SIZE 121
1219 /* Top level data structure to contain an abbreviation table. */
1223 explicit abbrev_table (sect_offset off
)
1227 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1228 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1231 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1233 /* Allocate space for a struct abbrev_info object in
1235 struct abbrev_info
*alloc_abbrev ();
1237 /* Add an abbreviation to the table. */
1238 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1240 /* Look up an abbrev in the table.
1241 Returns NULL if the abbrev is not found. */
1243 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1246 /* Where the abbrev table came from.
1247 This is used as a sanity check when the table is used. */
1248 const sect_offset sect_off
;
1250 /* Storage for the abbrev table. */
1251 auto_obstack abbrev_obstack
;
1255 /* Hash table of abbrevs.
1256 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1257 It could be statically allocated, but the previous code didn't so we
1259 struct abbrev_info
**m_abbrevs
;
1262 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1264 /* Attributes have a name and a value. */
1267 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1268 ENUM_BITFIELD(dwarf_form
) form
: 15;
1270 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1271 field should be in u.str (existing only for DW_STRING) but it is kept
1272 here for better struct attribute alignment. */
1273 unsigned int string_is_canonical
: 1;
1278 struct dwarf_block
*blk
;
1287 /* This data structure holds a complete die structure. */
1290 /* DWARF-2 tag for this DIE. */
1291 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1293 /* Number of attributes */
1294 unsigned char num_attrs
;
1296 /* True if we're presently building the full type name for the
1297 type derived from this DIE. */
1298 unsigned char building_fullname
: 1;
1300 /* True if this die is in process. PR 16581. */
1301 unsigned char in_process
: 1;
1304 unsigned int abbrev
;
1306 /* Offset in .debug_info or .debug_types section. */
1307 sect_offset sect_off
;
1309 /* The dies in a compilation unit form an n-ary tree. PARENT
1310 points to this die's parent; CHILD points to the first child of
1311 this node; and all the children of a given node are chained
1312 together via their SIBLING fields. */
1313 struct die_info
*child
; /* Its first child, if any. */
1314 struct die_info
*sibling
; /* Its next sibling, if any. */
1315 struct die_info
*parent
; /* Its parent, if any. */
1317 /* An array of attributes, with NUM_ATTRS elements. There may be
1318 zero, but it's not common and zero-sized arrays are not
1319 sufficiently portable C. */
1320 struct attribute attrs
[1];
1323 /* Get at parts of an attribute structure. */
1325 #define DW_STRING(attr) ((attr)->u.str)
1326 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1327 #define DW_UNSND(attr) ((attr)->u.unsnd)
1328 #define DW_BLOCK(attr) ((attr)->u.blk)
1329 #define DW_SND(attr) ((attr)->u.snd)
1330 #define DW_ADDR(attr) ((attr)->u.addr)
1331 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1333 /* Blocks are a bunch of untyped bytes. */
1338 /* Valid only if SIZE is not zero. */
1339 const gdb_byte
*data
;
1342 #ifndef ATTR_ALLOC_CHUNK
1343 #define ATTR_ALLOC_CHUNK 4
1346 /* Allocate fields for structs, unions and enums in this size. */
1347 #ifndef DW_FIELD_ALLOC_CHUNK
1348 #define DW_FIELD_ALLOC_CHUNK 4
1351 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1352 but this would require a corresponding change in unpack_field_as_long
1354 static int bits_per_byte
= 8;
1356 /* When reading a variant or variant part, we track a bit more
1357 information about the field, and store it in an object of this
1360 struct variant_field
1362 /* If we see a DW_TAG_variant, then this will be the discriminant
1364 ULONGEST discriminant_value
;
1365 /* If we see a DW_TAG_variant, then this will be set if this is the
1367 bool default_branch
;
1368 /* While reading a DW_TAG_variant_part, this will be set if this
1369 field is the discriminant. */
1370 bool is_discriminant
;
1375 int accessibility
= 0;
1377 /* Extra information to describe a variant or variant part. */
1378 struct variant_field variant
{};
1379 struct field field
{};
1384 const char *name
= nullptr;
1385 std::vector
<struct fn_field
> fnfields
;
1388 /* The routines that read and process dies for a C struct or C++ class
1389 pass lists of data member fields and lists of member function fields
1390 in an instance of a field_info structure, as defined below. */
1393 /* List of data member and baseclasses fields. */
1394 std::vector
<struct nextfield
> fields
;
1395 std::vector
<struct nextfield
> baseclasses
;
1397 /* Number of fields (including baseclasses). */
1400 /* Set if the accessibility of one of the fields is not public. */
1401 int non_public_fields
= 0;
1403 /* Member function fieldlist array, contains name of possibly overloaded
1404 member function, number of overloaded member functions and a pointer
1405 to the head of the member function field chain. */
1406 std::vector
<struct fnfieldlist
> fnfieldlists
;
1408 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1409 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1410 std::vector
<struct decl_field
> typedef_field_list
;
1412 /* Nested types defined by this class and the number of elements in this
1414 std::vector
<struct decl_field
> nested_types_list
;
1417 /* One item on the queue of compilation units to read in full symbols
1419 struct dwarf2_queue_item
1421 struct dwarf2_per_cu_data
*per_cu
;
1422 enum language pretend_language
;
1423 struct dwarf2_queue_item
*next
;
1426 /* The current queue. */
1427 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1429 /* Loaded secondary compilation units are kept in memory until they
1430 have not been referenced for the processing of this many
1431 compilation units. Set this to zero to disable caching. Cache
1432 sizes of up to at least twenty will improve startup time for
1433 typical inter-CU-reference binaries, at an obvious memory cost. */
1434 static int dwarf_max_cache_age
= 5;
1436 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1437 struct cmd_list_element
*c
, const char *value
)
1439 fprintf_filtered (file
, _("The upper bound on the age of cached "
1440 "DWARF compilation units is %s.\n"),
1444 /* local function prototypes */
1446 static const char *get_section_name (const struct dwarf2_section_info
*);
1448 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1450 static void dwarf2_find_base_address (struct die_info
*die
,
1451 struct dwarf2_cu
*cu
);
1453 static struct partial_symtab
*create_partial_symtab
1454 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1456 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1457 const gdb_byte
*info_ptr
,
1458 struct die_info
*type_unit_die
,
1459 int has_children
, void *data
);
1461 static void dwarf2_build_psymtabs_hard
1462 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1464 static void scan_partial_symbols (struct partial_die_info
*,
1465 CORE_ADDR
*, CORE_ADDR
*,
1466 int, struct dwarf2_cu
*);
1468 static void add_partial_symbol (struct partial_die_info
*,
1469 struct dwarf2_cu
*);
1471 static void add_partial_namespace (struct partial_die_info
*pdi
,
1472 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1473 int set_addrmap
, struct dwarf2_cu
*cu
);
1475 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1476 CORE_ADDR
*highpc
, int set_addrmap
,
1477 struct dwarf2_cu
*cu
);
1479 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1480 struct dwarf2_cu
*cu
);
1482 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1483 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1484 int need_pc
, struct dwarf2_cu
*cu
);
1486 static void dwarf2_read_symtab (struct partial_symtab
*,
1489 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1491 static abbrev_table_up abbrev_table_read_table
1492 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1495 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1497 static struct partial_die_info
*load_partial_dies
1498 (const struct die_reader_specs
*, const gdb_byte
*, int);
1500 /* A pair of partial_die_info and compilation unit. */
1501 struct cu_partial_die_info
1503 /* The compilation unit of the partial_die_info. */
1504 struct dwarf2_cu
*cu
;
1505 /* A partial_die_info. */
1506 struct partial_die_info
*pdi
;
1508 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1514 cu_partial_die_info () = delete;
1517 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1518 struct dwarf2_cu
*);
1520 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1521 struct attribute
*, struct attr_abbrev
*,
1524 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1526 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1528 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1530 /* Read the next three bytes (little-endian order) as an unsigned integer. */
1531 static unsigned int read_3_bytes (bfd
*, const gdb_byte
*);
1533 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1535 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1537 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1540 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1542 static LONGEST read_checked_initial_length_and_offset
1543 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1544 unsigned int *, unsigned int *);
1546 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1547 const struct comp_unit_head
*,
1550 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1552 static sect_offset read_abbrev_offset
1553 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1554 struct dwarf2_section_info
*, sect_offset
);
1556 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1558 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1560 static const char *read_indirect_string
1561 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1562 const struct comp_unit_head
*, unsigned int *);
1564 static const char *read_indirect_line_string
1565 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1566 const struct comp_unit_head
*, unsigned int *);
1568 static const char *read_indirect_string_at_offset
1569 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1570 LONGEST str_offset
);
1572 static const char *read_indirect_string_from_dwz
1573 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1575 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1577 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1581 static const char *read_str_index (const struct die_reader_specs
*reader
,
1582 ULONGEST str_index
);
1584 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1586 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1587 struct dwarf2_cu
*);
1589 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1592 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1593 struct dwarf2_cu
*cu
);
1595 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1597 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1598 struct dwarf2_cu
*cu
);
1600 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1602 static struct die_info
*die_specification (struct die_info
*die
,
1603 struct dwarf2_cu
**);
1605 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1606 struct dwarf2_cu
*cu
);
1608 static void dwarf_decode_lines (struct line_header
*, const char *,
1609 struct dwarf2_cu
*, struct partial_symtab
*,
1610 CORE_ADDR
, int decode_mapping
);
1612 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1615 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1616 struct dwarf2_cu
*, struct symbol
* = NULL
);
1618 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1619 struct dwarf2_cu
*);
1621 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1624 struct obstack
*obstack
,
1625 struct dwarf2_cu
*cu
, LONGEST
*value
,
1626 const gdb_byte
**bytes
,
1627 struct dwarf2_locexpr_baton
**baton
);
1629 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1631 static int need_gnat_info (struct dwarf2_cu
*);
1633 static struct type
*die_descriptive_type (struct die_info
*,
1634 struct dwarf2_cu
*);
1636 static void set_descriptive_type (struct type
*, struct die_info
*,
1637 struct dwarf2_cu
*);
1639 static struct type
*die_containing_type (struct die_info
*,
1640 struct dwarf2_cu
*);
1642 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1643 struct dwarf2_cu
*);
1645 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1647 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1649 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1651 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1652 const char *suffix
, int physname
,
1653 struct dwarf2_cu
*cu
);
1655 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1657 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1659 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1661 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1663 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1665 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1667 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1668 struct dwarf2_cu
*, struct partial_symtab
*);
1670 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1671 values. Keep the items ordered with increasing constraints compliance. */
1674 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1675 PC_BOUNDS_NOT_PRESENT
,
1677 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1678 were present but they do not form a valid range of PC addresses. */
1681 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1684 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1688 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1689 CORE_ADDR
*, CORE_ADDR
*,
1691 struct partial_symtab
*);
1693 static void get_scope_pc_bounds (struct die_info
*,
1694 CORE_ADDR
*, CORE_ADDR
*,
1695 struct dwarf2_cu
*);
1697 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1698 CORE_ADDR
, struct dwarf2_cu
*);
1700 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1701 struct dwarf2_cu
*);
1703 static void dwarf2_attach_fields_to_type (struct field_info
*,
1704 struct type
*, struct dwarf2_cu
*);
1706 static void dwarf2_add_member_fn (struct field_info
*,
1707 struct die_info
*, struct type
*,
1708 struct dwarf2_cu
*);
1710 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1712 struct dwarf2_cu
*);
1714 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1716 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1718 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1720 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1722 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1724 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1726 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1728 static struct type
*read_module_type (struct die_info
*die
,
1729 struct dwarf2_cu
*cu
);
1731 static const char *namespace_name (struct die_info
*die
,
1732 int *is_anonymous
, struct dwarf2_cu
*);
1734 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1736 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1738 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1739 struct dwarf2_cu
*);
1741 static struct die_info
*read_die_and_siblings_1
1742 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1745 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1746 const gdb_byte
*info_ptr
,
1747 const gdb_byte
**new_info_ptr
,
1748 struct die_info
*parent
);
1750 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1751 struct die_info
**, const gdb_byte
*,
1754 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1755 struct die_info
**, const gdb_byte
*,
1758 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1760 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1763 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1765 static const char *dwarf2_full_name (const char *name
,
1766 struct die_info
*die
,
1767 struct dwarf2_cu
*cu
);
1769 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1770 struct dwarf2_cu
*cu
);
1772 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1773 struct dwarf2_cu
**);
1775 static const char *dwarf_tag_name (unsigned int);
1777 static const char *dwarf_attr_name (unsigned int);
1779 static const char *dwarf_unit_type_name (int unit_type
);
1781 static const char *dwarf_form_name (unsigned int);
1783 static const char *dwarf_bool_name (unsigned int);
1785 static const char *dwarf_type_encoding_name (unsigned int);
1787 static struct die_info
*sibling_die (struct die_info
*);
1789 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1791 static void dump_die_for_error (struct die_info
*);
1793 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1796 /*static*/ void dump_die (struct die_info
*, int max_level
);
1798 static void store_in_ref_table (struct die_info
*,
1799 struct dwarf2_cu
*);
1801 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1803 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1805 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1806 const struct attribute
*,
1807 struct dwarf2_cu
**);
1809 static struct die_info
*follow_die_ref (struct die_info
*,
1810 const struct attribute
*,
1811 struct dwarf2_cu
**);
1813 static struct die_info
*follow_die_sig (struct die_info
*,
1814 const struct attribute
*,
1815 struct dwarf2_cu
**);
1817 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1818 struct dwarf2_cu
*);
1820 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1821 const struct attribute
*,
1822 struct dwarf2_cu
*);
1824 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1826 static void read_signatured_type (struct signatured_type
*);
1828 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1829 struct die_info
*die
, struct dwarf2_cu
*cu
,
1830 struct dynamic_prop
*prop
, struct type
*type
);
1832 /* memory allocation interface */
1834 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1836 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1838 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1840 static int attr_form_is_block (const struct attribute
*);
1842 static int attr_form_is_section_offset (const struct attribute
*);
1844 static int attr_form_is_constant (const struct attribute
*);
1846 static int attr_form_is_ref (const struct attribute
*);
1848 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1849 struct dwarf2_loclist_baton
*baton
,
1850 const struct attribute
*attr
);
1852 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1854 struct dwarf2_cu
*cu
,
1857 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1858 const gdb_byte
*info_ptr
,
1859 struct abbrev_info
*abbrev
);
1861 static hashval_t
partial_die_hash (const void *item
);
1863 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1865 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1866 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1867 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1869 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1870 struct die_info
*comp_unit_die
,
1871 enum language pretend_language
);
1873 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1875 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1877 static struct type
*set_die_type (struct die_info
*, struct type
*,
1878 struct dwarf2_cu
*);
1880 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1882 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1884 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1887 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1890 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1893 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1894 struct dwarf2_per_cu_data
*);
1896 static void dwarf2_mark (struct dwarf2_cu
*);
1898 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1900 static struct type
*get_die_type_at_offset (sect_offset
,
1901 struct dwarf2_per_cu_data
*);
1903 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1905 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1906 enum language pretend_language
);
1908 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1910 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1911 static struct type
*dwarf2_per_cu_addr_sized_int_type
1912 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1914 /* Class, the destructor of which frees all allocated queue entries. This
1915 will only have work to do if an error was thrown while processing the
1916 dwarf. If no error was thrown then the queue entries should have all
1917 been processed, and freed, as we went along. */
1919 class dwarf2_queue_guard
1922 dwarf2_queue_guard () = default;
1924 /* Free any entries remaining on the queue. There should only be
1925 entries left if we hit an error while processing the dwarf. */
1926 ~dwarf2_queue_guard ()
1928 struct dwarf2_queue_item
*item
, *last
;
1930 item
= dwarf2_queue
;
1933 /* Anything still marked queued is likely to be in an
1934 inconsistent state, so discard it. */
1935 if (item
->per_cu
->queued
)
1937 if (item
->per_cu
->cu
!= NULL
)
1938 free_one_cached_comp_unit (item
->per_cu
);
1939 item
->per_cu
->queued
= 0;
1947 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1951 /* The return type of find_file_and_directory. Note, the enclosed
1952 string pointers are only valid while this object is valid. */
1954 struct file_and_directory
1956 /* The filename. This is never NULL. */
1959 /* The compilation directory. NULL if not known. If we needed to
1960 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1961 points directly to the DW_AT_comp_dir string attribute owned by
1962 the obstack that owns the DIE. */
1963 const char *comp_dir
;
1965 /* If we needed to build a new string for comp_dir, this is what
1966 owns the storage. */
1967 std::string comp_dir_storage
;
1970 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1971 struct dwarf2_cu
*cu
);
1973 static char *file_full_name (int file
, struct line_header
*lh
,
1974 const char *comp_dir
);
1976 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1977 enum class rcuh_kind
{ COMPILE
, TYPE
};
1979 static const gdb_byte
*read_and_check_comp_unit_head
1980 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1981 struct comp_unit_head
*header
,
1982 struct dwarf2_section_info
*section
,
1983 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1984 rcuh_kind section_kind
);
1986 static void init_cutu_and_read_dies
1987 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1988 int use_existing_cu
, int keep
, bool skip_partial
,
1989 die_reader_func_ftype
*die_reader_func
, void *data
);
1991 static void init_cutu_and_read_dies_simple
1992 (struct dwarf2_per_cu_data
*this_cu
,
1993 die_reader_func_ftype
*die_reader_func
, void *data
);
1995 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1997 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1999 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2000 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2001 struct dwp_file
*dwp_file
, const char *comp_dir
,
2002 ULONGEST signature
, int is_debug_types
);
2004 static struct dwp_file
*get_dwp_file
2005 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2007 static struct dwo_unit
*lookup_dwo_comp_unit
2008 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2010 static struct dwo_unit
*lookup_dwo_type_unit
2011 (struct signatured_type
*, const char *, const char *);
2013 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2015 /* A unique pointer to a dwo_file. */
2017 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
2019 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2021 static void check_producer (struct dwarf2_cu
*cu
);
2023 static void free_line_header_voidp (void *arg
);
2025 /* Various complaints about symbol reading that don't abort the process. */
2028 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2030 complaint (_("statement list doesn't fit in .debug_line section"));
2034 dwarf2_debug_line_missing_file_complaint (void)
2036 complaint (_(".debug_line section has line data without a file"));
2040 dwarf2_debug_line_missing_end_sequence_complaint (void)
2042 complaint (_(".debug_line section has line "
2043 "program sequence without an end"));
2047 dwarf2_complex_location_expr_complaint (void)
2049 complaint (_("location expression too complex"));
2053 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2056 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
2061 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2063 complaint (_("debug info runs off end of %s section"
2065 get_section_name (section
),
2066 get_section_file_name (section
));
2070 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2072 complaint (_("macro debug info contains a "
2073 "malformed macro definition:\n`%s'"),
2078 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2080 complaint (_("invalid attribute class or form for '%s' in '%s'"),
2084 /* Hash function for line_header_hash. */
2087 line_header_hash (const struct line_header
*ofs
)
2089 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2092 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2095 line_header_hash_voidp (const void *item
)
2097 const struct line_header
*ofs
= (const struct line_header
*) item
;
2099 return line_header_hash (ofs
);
2102 /* Equality function for line_header_hash. */
2105 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2107 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2108 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2110 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2111 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2116 /* Read the given attribute value as an address, taking the attribute's
2117 form into account. */
2120 attr_value_as_address (struct attribute
*attr
)
2124 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_addrx
2125 && attr
->form
!= DW_FORM_GNU_addr_index
)
2127 /* Aside from a few clearly defined exceptions, attributes that
2128 contain an address must always be in DW_FORM_addr form.
2129 Unfortunately, some compilers happen to be violating this
2130 requirement by encoding addresses using other forms, such
2131 as DW_FORM_data4 for example. For those broken compilers,
2132 we try to do our best, without any guarantee of success,
2133 to interpret the address correctly. It would also be nice
2134 to generate a complaint, but that would require us to maintain
2135 a list of legitimate cases where a non-address form is allowed,
2136 as well as update callers to pass in at least the CU's DWARF
2137 version. This is more overhead than what we're willing to
2138 expand for a pretty rare case. */
2139 addr
= DW_UNSND (attr
);
2142 addr
= DW_ADDR (attr
);
2147 /* See declaration. */
2149 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2150 const dwarf2_debug_sections
*names
,
2152 : objfile (objfile_
),
2153 can_copy (can_copy_
)
2156 names
= &dwarf2_elf_names
;
2158 bfd
*obfd
= objfile
->obfd
;
2160 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2161 locate_sections (obfd
, sec
, *names
);
2164 dwarf2_per_objfile::~dwarf2_per_objfile ()
2166 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2167 free_cached_comp_units ();
2169 if (quick_file_names_table
)
2170 htab_delete (quick_file_names_table
);
2172 if (line_header_hash
)
2173 htab_delete (line_header_hash
);
2175 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2176 per_cu
->imported_symtabs_free ();
2178 for (signatured_type
*sig_type
: all_type_units
)
2179 sig_type
->per_cu
.imported_symtabs_free ();
2181 /* Everything else should be on the objfile obstack. */
2184 /* See declaration. */
2187 dwarf2_per_objfile::free_cached_comp_units ()
2189 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2190 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2191 while (per_cu
!= NULL
)
2193 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2196 *last_chain
= next_cu
;
2201 /* A helper class that calls free_cached_comp_units on
2204 class free_cached_comp_units
2208 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2209 : m_per_objfile (per_objfile
)
2213 ~free_cached_comp_units ()
2215 m_per_objfile
->free_cached_comp_units ();
2218 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2222 dwarf2_per_objfile
*m_per_objfile
;
2225 /* Try to locate the sections we need for DWARF 2 debugging
2226 information and return true if we have enough to do something.
2227 NAMES points to the dwarf2 section names, or is NULL if the standard
2228 ELF names are used. CAN_COPY is true for formats where symbol
2229 interposition is possible and so symbol values must follow copy
2230 relocation rules. */
2233 dwarf2_has_info (struct objfile
*objfile
,
2234 const struct dwarf2_debug_sections
*names
,
2237 if (objfile
->flags
& OBJF_READNEVER
)
2240 struct dwarf2_per_objfile
*dwarf2_per_objfile
2241 = get_dwarf2_per_objfile (objfile
);
2243 if (dwarf2_per_objfile
== NULL
)
2244 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2248 return (!dwarf2_per_objfile
->info
.is_virtual
2249 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2250 && !dwarf2_per_objfile
->abbrev
.is_virtual
2251 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2254 /* Return the containing section of virtual section SECTION. */
2256 static struct dwarf2_section_info
*
2257 get_containing_section (const struct dwarf2_section_info
*section
)
2259 gdb_assert (section
->is_virtual
);
2260 return section
->s
.containing_section
;
2263 /* Return the bfd owner of SECTION. */
2266 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2268 if (section
->is_virtual
)
2270 section
= get_containing_section (section
);
2271 gdb_assert (!section
->is_virtual
);
2273 return section
->s
.section
->owner
;
2276 /* Return the bfd section of SECTION.
2277 Returns NULL if the section is not present. */
2280 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2282 if (section
->is_virtual
)
2284 section
= get_containing_section (section
);
2285 gdb_assert (!section
->is_virtual
);
2287 return section
->s
.section
;
2290 /* Return the name of SECTION. */
2293 get_section_name (const struct dwarf2_section_info
*section
)
2295 asection
*sectp
= get_section_bfd_section (section
);
2297 gdb_assert (sectp
!= NULL
);
2298 return bfd_section_name (sectp
);
2301 /* Return the name of the file SECTION is in. */
2304 get_section_file_name (const struct dwarf2_section_info
*section
)
2306 bfd
*abfd
= get_section_bfd_owner (section
);
2308 return bfd_get_filename (abfd
);
2311 /* Return the id of SECTION.
2312 Returns 0 if SECTION doesn't exist. */
2315 get_section_id (const struct dwarf2_section_info
*section
)
2317 asection
*sectp
= get_section_bfd_section (section
);
2324 /* Return the flags of SECTION.
2325 SECTION (or containing section if this is a virtual section) must exist. */
2328 get_section_flags (const struct dwarf2_section_info
*section
)
2330 asection
*sectp
= get_section_bfd_section (section
);
2332 gdb_assert (sectp
!= NULL
);
2333 return bfd_section_flags (sectp
);
2336 /* When loading sections, we look either for uncompressed section or for
2337 compressed section names. */
2340 section_is_p (const char *section_name
,
2341 const struct dwarf2_section_names
*names
)
2343 if (names
->normal
!= NULL
2344 && strcmp (section_name
, names
->normal
) == 0)
2346 if (names
->compressed
!= NULL
2347 && strcmp (section_name
, names
->compressed
) == 0)
2352 /* See declaration. */
2355 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2356 const dwarf2_debug_sections
&names
)
2358 flagword aflag
= bfd_section_flags (sectp
);
2360 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2363 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2364 > bfd_get_file_size (abfd
))
2366 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2367 warning (_("Discarding section %s which has a section size (%s"
2368 ") larger than the file size [in module %s]"),
2369 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2370 bfd_get_filename (abfd
));
2372 else if (section_is_p (sectp
->name
, &names
.info
))
2374 this->info
.s
.section
= sectp
;
2375 this->info
.size
= bfd_section_size (sectp
);
2377 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2379 this->abbrev
.s
.section
= sectp
;
2380 this->abbrev
.size
= bfd_section_size (sectp
);
2382 else if (section_is_p (sectp
->name
, &names
.line
))
2384 this->line
.s
.section
= sectp
;
2385 this->line
.size
= bfd_section_size (sectp
);
2387 else if (section_is_p (sectp
->name
, &names
.loc
))
2389 this->loc
.s
.section
= sectp
;
2390 this->loc
.size
= bfd_section_size (sectp
);
2392 else if (section_is_p (sectp
->name
, &names
.loclists
))
2394 this->loclists
.s
.section
= sectp
;
2395 this->loclists
.size
= bfd_section_size (sectp
);
2397 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2399 this->macinfo
.s
.section
= sectp
;
2400 this->macinfo
.size
= bfd_section_size (sectp
);
2402 else if (section_is_p (sectp
->name
, &names
.macro
))
2404 this->macro
.s
.section
= sectp
;
2405 this->macro
.size
= bfd_section_size (sectp
);
2407 else if (section_is_p (sectp
->name
, &names
.str
))
2409 this->str
.s
.section
= sectp
;
2410 this->str
.size
= bfd_section_size (sectp
);
2412 else if (section_is_p (sectp
->name
, &names
.line_str
))
2414 this->line_str
.s
.section
= sectp
;
2415 this->line_str
.size
= bfd_section_size (sectp
);
2417 else if (section_is_p (sectp
->name
, &names
.addr
))
2419 this->addr
.s
.section
= sectp
;
2420 this->addr
.size
= bfd_section_size (sectp
);
2422 else if (section_is_p (sectp
->name
, &names
.frame
))
2424 this->frame
.s
.section
= sectp
;
2425 this->frame
.size
= bfd_section_size (sectp
);
2427 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2429 this->eh_frame
.s
.section
= sectp
;
2430 this->eh_frame
.size
= bfd_section_size (sectp
);
2432 else if (section_is_p (sectp
->name
, &names
.ranges
))
2434 this->ranges
.s
.section
= sectp
;
2435 this->ranges
.size
= bfd_section_size (sectp
);
2437 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2439 this->rnglists
.s
.section
= sectp
;
2440 this->rnglists
.size
= bfd_section_size (sectp
);
2442 else if (section_is_p (sectp
->name
, &names
.types
))
2444 struct dwarf2_section_info type_section
;
2446 memset (&type_section
, 0, sizeof (type_section
));
2447 type_section
.s
.section
= sectp
;
2448 type_section
.size
= bfd_section_size (sectp
);
2450 this->types
.push_back (type_section
);
2452 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2454 this->gdb_index
.s
.section
= sectp
;
2455 this->gdb_index
.size
= bfd_section_size (sectp
);
2457 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2459 this->debug_names
.s
.section
= sectp
;
2460 this->debug_names
.size
= bfd_section_size (sectp
);
2462 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2464 this->debug_aranges
.s
.section
= sectp
;
2465 this->debug_aranges
.size
= bfd_section_size (sectp
);
2468 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2469 && bfd_section_vma (sectp
) == 0)
2470 this->has_section_at_zero
= true;
2473 /* A helper function that decides whether a section is empty,
2477 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2479 if (section
->is_virtual
)
2480 return section
->size
== 0;
2481 return section
->s
.section
== NULL
|| section
->size
== 0;
2484 /* See dwarf2read.h. */
2487 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2491 gdb_byte
*buf
, *retbuf
;
2495 info
->buffer
= NULL
;
2496 info
->readin
= true;
2498 if (dwarf2_section_empty_p (info
))
2501 sectp
= get_section_bfd_section (info
);
2503 /* If this is a virtual section we need to read in the real one first. */
2504 if (info
->is_virtual
)
2506 struct dwarf2_section_info
*containing_section
=
2507 get_containing_section (info
);
2509 gdb_assert (sectp
!= NULL
);
2510 if ((sectp
->flags
& SEC_RELOC
) != 0)
2512 error (_("Dwarf Error: DWP format V2 with relocations is not"
2513 " supported in section %s [in module %s]"),
2514 get_section_name (info
), get_section_file_name (info
));
2516 dwarf2_read_section (objfile
, containing_section
);
2517 /* Other code should have already caught virtual sections that don't
2519 gdb_assert (info
->virtual_offset
+ info
->size
2520 <= containing_section
->size
);
2521 /* If the real section is empty or there was a problem reading the
2522 section we shouldn't get here. */
2523 gdb_assert (containing_section
->buffer
!= NULL
);
2524 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2528 /* If the section has relocations, we must read it ourselves.
2529 Otherwise we attach it to the BFD. */
2530 if ((sectp
->flags
& SEC_RELOC
) == 0)
2532 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2536 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2539 /* When debugging .o files, we may need to apply relocations; see
2540 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2541 We never compress sections in .o files, so we only need to
2542 try this when the section is not compressed. */
2543 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2546 info
->buffer
= retbuf
;
2550 abfd
= get_section_bfd_owner (info
);
2551 gdb_assert (abfd
!= NULL
);
2553 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2554 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2556 error (_("Dwarf Error: Can't read DWARF data"
2557 " in section %s [in module %s]"),
2558 bfd_section_name (sectp
), bfd_get_filename (abfd
));
2562 /* A helper function that returns the size of a section in a safe way.
2563 If you are positive that the section has been read before using the
2564 size, then it is safe to refer to the dwarf2_section_info object's
2565 "size" field directly. In other cases, you must call this
2566 function, because for compressed sections the size field is not set
2567 correctly until the section has been read. */
2569 static bfd_size_type
2570 dwarf2_section_size (struct objfile
*objfile
,
2571 struct dwarf2_section_info
*info
)
2574 dwarf2_read_section (objfile
, info
);
2578 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2582 dwarf2_get_section_info (struct objfile
*objfile
,
2583 enum dwarf2_section_enum sect
,
2584 asection
**sectp
, const gdb_byte
**bufp
,
2585 bfd_size_type
*sizep
)
2587 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2588 struct dwarf2_section_info
*info
;
2590 /* We may see an objfile without any DWARF, in which case we just
2601 case DWARF2_DEBUG_FRAME
:
2602 info
= &data
->frame
;
2604 case DWARF2_EH_FRAME
:
2605 info
= &data
->eh_frame
;
2608 gdb_assert_not_reached ("unexpected section");
2611 dwarf2_read_section (objfile
, info
);
2613 *sectp
= get_section_bfd_section (info
);
2614 *bufp
= info
->buffer
;
2615 *sizep
= info
->size
;
2618 /* A helper function to find the sections for a .dwz file. */
2621 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2623 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2625 /* Note that we only support the standard ELF names, because .dwz
2626 is ELF-only (at the time of writing). */
2627 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2629 dwz_file
->abbrev
.s
.section
= sectp
;
2630 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2632 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2634 dwz_file
->info
.s
.section
= sectp
;
2635 dwz_file
->info
.size
= bfd_section_size (sectp
);
2637 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2639 dwz_file
->str
.s
.section
= sectp
;
2640 dwz_file
->str
.size
= bfd_section_size (sectp
);
2642 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2644 dwz_file
->line
.s
.section
= sectp
;
2645 dwz_file
->line
.size
= bfd_section_size (sectp
);
2647 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2649 dwz_file
->macro
.s
.section
= sectp
;
2650 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2652 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2654 dwz_file
->gdb_index
.s
.section
= sectp
;
2655 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2657 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2659 dwz_file
->debug_names
.s
.section
= sectp
;
2660 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2664 /* See dwarf2read.h. */
2667 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2669 const char *filename
;
2670 bfd_size_type buildid_len_arg
;
2674 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2675 return dwarf2_per_objfile
->dwz_file
.get ();
2677 bfd_set_error (bfd_error_no_error
);
2678 gdb::unique_xmalloc_ptr
<char> data
2679 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2680 &buildid_len_arg
, &buildid
));
2683 if (bfd_get_error () == bfd_error_no_error
)
2685 error (_("could not read '.gnu_debugaltlink' section: %s"),
2686 bfd_errmsg (bfd_get_error ()));
2689 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2691 buildid_len
= (size_t) buildid_len_arg
;
2693 filename
= data
.get ();
2695 std::string abs_storage
;
2696 if (!IS_ABSOLUTE_PATH (filename
))
2698 gdb::unique_xmalloc_ptr
<char> abs
2699 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2701 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2702 filename
= abs_storage
.c_str ();
2705 /* First try the file name given in the section. If that doesn't
2706 work, try to use the build-id instead. */
2707 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2708 if (dwz_bfd
!= NULL
)
2710 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2711 dwz_bfd
.reset (nullptr);
2714 if (dwz_bfd
== NULL
)
2715 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2717 if (dwz_bfd
== NULL
)
2718 error (_("could not find '.gnu_debugaltlink' file for %s"),
2719 objfile_name (dwarf2_per_objfile
->objfile
));
2721 std::unique_ptr
<struct dwz_file
> result
2722 (new struct dwz_file (std::move (dwz_bfd
)));
2724 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2727 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2728 result
->dwz_bfd
.get ());
2729 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2730 return dwarf2_per_objfile
->dwz_file
.get ();
2733 /* DWARF quick_symbols_functions support. */
2735 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2736 unique line tables, so we maintain a separate table of all .debug_line
2737 derived entries to support the sharing.
2738 All the quick functions need is the list of file names. We discard the
2739 line_header when we're done and don't need to record it here. */
2740 struct quick_file_names
2742 /* The data used to construct the hash key. */
2743 struct stmt_list_hash hash
;
2745 /* The number of entries in file_names, real_names. */
2746 unsigned int num_file_names
;
2748 /* The file names from the line table, after being run through
2750 const char **file_names
;
2752 /* The file names from the line table after being run through
2753 gdb_realpath. These are computed lazily. */
2754 const char **real_names
;
2757 /* When using the index (and thus not using psymtabs), each CU has an
2758 object of this type. This is used to hold information needed by
2759 the various "quick" methods. */
2760 struct dwarf2_per_cu_quick_data
2762 /* The file table. This can be NULL if there was no file table
2763 or it's currently not read in.
2764 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2765 struct quick_file_names
*file_names
;
2767 /* The corresponding symbol table. This is NULL if symbols for this
2768 CU have not yet been read. */
2769 struct compunit_symtab
*compunit_symtab
;
2771 /* A temporary mark bit used when iterating over all CUs in
2772 expand_symtabs_matching. */
2773 unsigned int mark
: 1;
2775 /* True if we've tried to read the file table and found there isn't one.
2776 There will be no point in trying to read it again next time. */
2777 unsigned int no_file_data
: 1;
2780 /* Utility hash function for a stmt_list_hash. */
2783 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2787 if (stmt_list_hash
->dwo_unit
!= NULL
)
2788 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2789 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2793 /* Utility equality function for a stmt_list_hash. */
2796 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2797 const struct stmt_list_hash
*rhs
)
2799 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2801 if (lhs
->dwo_unit
!= NULL
2802 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2805 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2808 /* Hash function for a quick_file_names. */
2811 hash_file_name_entry (const void *e
)
2813 const struct quick_file_names
*file_data
2814 = (const struct quick_file_names
*) e
;
2816 return hash_stmt_list_entry (&file_data
->hash
);
2819 /* Equality function for a quick_file_names. */
2822 eq_file_name_entry (const void *a
, const void *b
)
2824 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2825 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2827 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2830 /* Delete function for a quick_file_names. */
2833 delete_file_name_entry (void *e
)
2835 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2838 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2840 xfree ((void*) file_data
->file_names
[i
]);
2841 if (file_data
->real_names
)
2842 xfree ((void*) file_data
->real_names
[i
]);
2845 /* The space for the struct itself lives on objfile_obstack,
2846 so we don't free it here. */
2849 /* Create a quick_file_names hash table. */
2852 create_quick_file_names_table (unsigned int nr_initial_entries
)
2854 return htab_create_alloc (nr_initial_entries
,
2855 hash_file_name_entry
, eq_file_name_entry
,
2856 delete_file_name_entry
, xcalloc
, xfree
);
2859 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2860 have to be created afterwards. You should call age_cached_comp_units after
2861 processing PER_CU->CU. dw2_setup must have been already called. */
2864 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2866 if (per_cu
->is_debug_types
)
2867 load_full_type_unit (per_cu
);
2869 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2871 if (per_cu
->cu
== NULL
)
2872 return; /* Dummy CU. */
2874 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2877 /* Read in the symbols for PER_CU. */
2880 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2882 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2884 /* Skip type_unit_groups, reading the type units they contain
2885 is handled elsewhere. */
2886 if (IS_TYPE_UNIT_GROUP (per_cu
))
2889 /* The destructor of dwarf2_queue_guard frees any entries left on
2890 the queue. After this point we're guaranteed to leave this function
2891 with the dwarf queue empty. */
2892 dwarf2_queue_guard q_guard
;
2894 if (dwarf2_per_objfile
->using_index
2895 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2896 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2898 queue_comp_unit (per_cu
, language_minimal
);
2899 load_cu (per_cu
, skip_partial
);
2901 /* If we just loaded a CU from a DWO, and we're working with an index
2902 that may badly handle TUs, load all the TUs in that DWO as well.
2903 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2904 if (!per_cu
->is_debug_types
2905 && per_cu
->cu
!= NULL
2906 && per_cu
->cu
->dwo_unit
!= NULL
2907 && dwarf2_per_objfile
->index_table
!= NULL
2908 && dwarf2_per_objfile
->index_table
->version
<= 7
2909 /* DWP files aren't supported yet. */
2910 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2911 queue_and_load_all_dwo_tus (per_cu
);
2914 process_queue (dwarf2_per_objfile
);
2916 /* Age the cache, releasing compilation units that have not
2917 been used recently. */
2918 age_cached_comp_units (dwarf2_per_objfile
);
2921 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2922 the objfile from which this CU came. Returns the resulting symbol
2925 static struct compunit_symtab
*
2926 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2928 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2930 gdb_assert (dwarf2_per_objfile
->using_index
);
2931 if (!per_cu
->v
.quick
->compunit_symtab
)
2933 free_cached_comp_units
freer (dwarf2_per_objfile
);
2934 scoped_restore decrementer
= increment_reading_symtab ();
2935 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2936 process_cu_includes (dwarf2_per_objfile
);
2939 return per_cu
->v
.quick
->compunit_symtab
;
2942 /* See declaration. */
2944 dwarf2_per_cu_data
*
2945 dwarf2_per_objfile::get_cutu (int index
)
2947 if (index
>= this->all_comp_units
.size ())
2949 index
-= this->all_comp_units
.size ();
2950 gdb_assert (index
< this->all_type_units
.size ());
2951 return &this->all_type_units
[index
]->per_cu
;
2954 return this->all_comp_units
[index
];
2957 /* See declaration. */
2959 dwarf2_per_cu_data
*
2960 dwarf2_per_objfile::get_cu (int index
)
2962 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2964 return this->all_comp_units
[index
];
2967 /* See declaration. */
2970 dwarf2_per_objfile::get_tu (int index
)
2972 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2974 return this->all_type_units
[index
];
2977 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2978 objfile_obstack, and constructed with the specified field
2981 static dwarf2_per_cu_data
*
2982 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2983 struct dwarf2_section_info
*section
,
2985 sect_offset sect_off
, ULONGEST length
)
2987 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2988 dwarf2_per_cu_data
*the_cu
2989 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2990 struct dwarf2_per_cu_data
);
2991 the_cu
->sect_off
= sect_off
;
2992 the_cu
->length
= length
;
2993 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2994 the_cu
->section
= section
;
2995 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2996 struct dwarf2_per_cu_quick_data
);
2997 the_cu
->is_dwz
= is_dwz
;
3001 /* A helper for create_cus_from_index that handles a given list of
3005 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3006 const gdb_byte
*cu_list
, offset_type n_elements
,
3007 struct dwarf2_section_info
*section
,
3010 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
3012 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3014 sect_offset sect_off
3015 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3016 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3019 dwarf2_per_cu_data
*per_cu
3020 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3022 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
3026 /* Read the CU list from the mapped index, and use it to create all
3027 the CU objects for this objfile. */
3030 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3031 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3032 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3034 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3035 dwarf2_per_objfile
->all_comp_units
.reserve
3036 ((cu_list_elements
+ dwz_elements
) / 2);
3038 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3039 &dwarf2_per_objfile
->info
, 0);
3041 if (dwz_elements
== 0)
3044 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3045 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3049 /* Create the signatured type hash table from the index. */
3052 create_signatured_type_table_from_index
3053 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3054 struct dwarf2_section_info
*section
,
3055 const gdb_byte
*bytes
,
3056 offset_type elements
)
3058 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3060 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3061 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3063 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3065 for (offset_type i
= 0; i
< elements
; i
+= 3)
3067 struct signatured_type
*sig_type
;
3070 cu_offset type_offset_in_tu
;
3072 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3073 sect_offset sect_off
3074 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3076 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3078 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3081 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3082 struct signatured_type
);
3083 sig_type
->signature
= signature
;
3084 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3085 sig_type
->per_cu
.is_debug_types
= 1;
3086 sig_type
->per_cu
.section
= section
;
3087 sig_type
->per_cu
.sect_off
= sect_off
;
3088 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3089 sig_type
->per_cu
.v
.quick
3090 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3091 struct dwarf2_per_cu_quick_data
);
3093 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3096 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3099 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3102 /* Create the signatured type hash table from .debug_names. */
3105 create_signatured_type_table_from_debug_names
3106 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3107 const mapped_debug_names
&map
,
3108 struct dwarf2_section_info
*section
,
3109 struct dwarf2_section_info
*abbrev_section
)
3111 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3113 dwarf2_read_section (objfile
, section
);
3114 dwarf2_read_section (objfile
, abbrev_section
);
3116 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3117 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3119 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3121 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3123 struct signatured_type
*sig_type
;
3126 sect_offset sect_off
3127 = (sect_offset
) (extract_unsigned_integer
3128 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3130 map
.dwarf5_byte_order
));
3132 comp_unit_head cu_header
;
3133 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3135 section
->buffer
+ to_underlying (sect_off
),
3138 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3139 struct signatured_type
);
3140 sig_type
->signature
= cu_header
.signature
;
3141 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3142 sig_type
->per_cu
.is_debug_types
= 1;
3143 sig_type
->per_cu
.section
= section
;
3144 sig_type
->per_cu
.sect_off
= sect_off
;
3145 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3146 sig_type
->per_cu
.v
.quick
3147 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3148 struct dwarf2_per_cu_quick_data
);
3150 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3153 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3156 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3159 /* Read the address map data from the mapped index, and use it to
3160 populate the objfile's psymtabs_addrmap. */
3163 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3164 struct mapped_index
*index
)
3166 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3167 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3168 const gdb_byte
*iter
, *end
;
3169 struct addrmap
*mutable_map
;
3172 auto_obstack temp_obstack
;
3174 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3176 iter
= index
->address_table
.data ();
3177 end
= iter
+ index
->address_table
.size ();
3179 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3183 ULONGEST hi
, lo
, cu_index
;
3184 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3186 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3188 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3193 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
3194 hex_string (lo
), hex_string (hi
));
3198 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3200 complaint (_(".gdb_index address table has invalid CU number %u"),
3201 (unsigned) cu_index
);
3205 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
3206 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
3207 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3208 dwarf2_per_objfile
->get_cu (cu_index
));
3211 objfile
->partial_symtabs
->psymtabs_addrmap
3212 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3215 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3216 populate the objfile's psymtabs_addrmap. */
3219 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3220 struct dwarf2_section_info
*section
)
3222 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3223 bfd
*abfd
= objfile
->obfd
;
3224 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3225 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3226 SECT_OFF_TEXT (objfile
));
3228 auto_obstack temp_obstack
;
3229 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3231 std::unordered_map
<sect_offset
,
3232 dwarf2_per_cu_data
*,
3233 gdb::hash_enum
<sect_offset
>>
3234 debug_info_offset_to_per_cu
;
3235 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3237 const auto insertpair
3238 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3239 if (!insertpair
.second
)
3241 warning (_("Section .debug_aranges in %s has duplicate "
3242 "debug_info_offset %s, ignoring .debug_aranges."),
3243 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3248 dwarf2_read_section (objfile
, section
);
3250 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3252 const gdb_byte
*addr
= section
->buffer
;
3254 while (addr
< section
->buffer
+ section
->size
)
3256 const gdb_byte
*const entry_addr
= addr
;
3257 unsigned int bytes_read
;
3259 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3263 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3264 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3265 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3266 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3268 warning (_("Section .debug_aranges in %s entry at offset %s "
3269 "length %s exceeds section length %s, "
3270 "ignoring .debug_aranges."),
3271 objfile_name (objfile
),
3272 plongest (entry_addr
- section
->buffer
),
3273 plongest (bytes_read
+ entry_length
),
3274 pulongest (section
->size
));
3278 /* The version number. */
3279 const uint16_t version
= read_2_bytes (abfd
, addr
);
3283 warning (_("Section .debug_aranges in %s entry at offset %s "
3284 "has unsupported version %d, ignoring .debug_aranges."),
3285 objfile_name (objfile
),
3286 plongest (entry_addr
- section
->buffer
), version
);
3290 const uint64_t debug_info_offset
3291 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3292 addr
+= offset_size
;
3293 const auto per_cu_it
3294 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3295 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3297 warning (_("Section .debug_aranges in %s entry at offset %s "
3298 "debug_info_offset %s does not exists, "
3299 "ignoring .debug_aranges."),
3300 objfile_name (objfile
),
3301 plongest (entry_addr
- section
->buffer
),
3302 pulongest (debug_info_offset
));
3305 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3307 const uint8_t address_size
= *addr
++;
3308 if (address_size
< 1 || address_size
> 8)
3310 warning (_("Section .debug_aranges in %s entry at offset %s "
3311 "address_size %u is invalid, ignoring .debug_aranges."),
3312 objfile_name (objfile
),
3313 plongest (entry_addr
- section
->buffer
), address_size
);
3317 const uint8_t segment_selector_size
= *addr
++;
3318 if (segment_selector_size
!= 0)
3320 warning (_("Section .debug_aranges in %s entry at offset %s "
3321 "segment_selector_size %u is not supported, "
3322 "ignoring .debug_aranges."),
3323 objfile_name (objfile
),
3324 plongest (entry_addr
- section
->buffer
),
3325 segment_selector_size
);
3329 /* Must pad to an alignment boundary that is twice the address
3330 size. It is undocumented by the DWARF standard but GCC does
3332 for (size_t padding
= ((-(addr
- section
->buffer
))
3333 & (2 * address_size
- 1));
3334 padding
> 0; padding
--)
3337 warning (_("Section .debug_aranges in %s entry at offset %s "
3338 "padding is not zero, ignoring .debug_aranges."),
3339 objfile_name (objfile
),
3340 plongest (entry_addr
- section
->buffer
));
3346 if (addr
+ 2 * address_size
> entry_end
)
3348 warning (_("Section .debug_aranges in %s entry at offset %s "
3349 "address list is not properly terminated, "
3350 "ignoring .debug_aranges."),
3351 objfile_name (objfile
),
3352 plongest (entry_addr
- section
->buffer
));
3355 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3357 addr
+= address_size
;
3358 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3360 addr
+= address_size
;
3361 if (start
== 0 && length
== 0)
3363 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3365 /* Symbol was eliminated due to a COMDAT group. */
3368 ULONGEST end
= start
+ length
;
3369 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3371 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3373 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3377 objfile
->partial_symtabs
->psymtabs_addrmap
3378 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3381 /* Find a slot in the mapped index INDEX for the object named NAME.
3382 If NAME is found, set *VEC_OUT to point to the CU vector in the
3383 constant pool and return true. If NAME cannot be found, return
3387 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3388 offset_type
**vec_out
)
3391 offset_type slot
, step
;
3392 int (*cmp
) (const char *, const char *);
3394 gdb::unique_xmalloc_ptr
<char> without_params
;
3395 if (current_language
->la_language
== language_cplus
3396 || current_language
->la_language
== language_fortran
3397 || current_language
->la_language
== language_d
)
3399 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3402 if (strchr (name
, '(') != NULL
)
3404 without_params
= cp_remove_params (name
);
3406 if (without_params
!= NULL
)
3407 name
= without_params
.get ();
3411 /* Index version 4 did not support case insensitive searches. But the
3412 indices for case insensitive languages are built in lowercase, therefore
3413 simulate our NAME being searched is also lowercased. */
3414 hash
= mapped_index_string_hash ((index
->version
== 4
3415 && case_sensitivity
== case_sensitive_off
3416 ? 5 : index
->version
),
3419 slot
= hash
& (index
->symbol_table
.size () - 1);
3420 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3421 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3427 const auto &bucket
= index
->symbol_table
[slot
];
3428 if (bucket
.name
== 0 && bucket
.vec
== 0)
3431 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3432 if (!cmp (name
, str
))
3434 *vec_out
= (offset_type
*) (index
->constant_pool
3435 + MAYBE_SWAP (bucket
.vec
));
3439 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3443 /* A helper function that reads the .gdb_index from BUFFER and fills
3444 in MAP. FILENAME is the name of the file containing the data;
3445 it is used for error reporting. DEPRECATED_OK is true if it is
3446 ok to use deprecated sections.
3448 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3449 out parameters that are filled in with information about the CU and
3450 TU lists in the section.
3452 Returns true if all went well, false otherwise. */
3455 read_gdb_index_from_buffer (struct objfile
*objfile
,
3456 const char *filename
,
3458 gdb::array_view
<const gdb_byte
> buffer
,
3459 struct mapped_index
*map
,
3460 const gdb_byte
**cu_list
,
3461 offset_type
*cu_list_elements
,
3462 const gdb_byte
**types_list
,
3463 offset_type
*types_list_elements
)
3465 const gdb_byte
*addr
= &buffer
[0];
3467 /* Version check. */
3468 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3469 /* Versions earlier than 3 emitted every copy of a psymbol. This
3470 causes the index to behave very poorly for certain requests. Version 3
3471 contained incomplete addrmap. So, it seems better to just ignore such
3475 static int warning_printed
= 0;
3476 if (!warning_printed
)
3478 warning (_("Skipping obsolete .gdb_index section in %s."),
3480 warning_printed
= 1;
3484 /* Index version 4 uses a different hash function than index version
3487 Versions earlier than 6 did not emit psymbols for inlined
3488 functions. Using these files will cause GDB not to be able to
3489 set breakpoints on inlined functions by name, so we ignore these
3490 indices unless the user has done
3491 "set use-deprecated-index-sections on". */
3492 if (version
< 6 && !deprecated_ok
)
3494 static int warning_printed
= 0;
3495 if (!warning_printed
)
3498 Skipping deprecated .gdb_index section in %s.\n\
3499 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3500 to use the section anyway."),
3502 warning_printed
= 1;
3506 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3507 of the TU (for symbols coming from TUs),
3508 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3509 Plus gold-generated indices can have duplicate entries for global symbols,
3510 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3511 These are just performance bugs, and we can't distinguish gdb-generated
3512 indices from gold-generated ones, so issue no warning here. */
3514 /* Indexes with higher version than the one supported by GDB may be no
3515 longer backward compatible. */
3519 map
->version
= version
;
3521 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3524 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3525 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3529 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3530 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3531 - MAYBE_SWAP (metadata
[i
]))
3535 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3536 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3538 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3541 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3542 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3544 = gdb::array_view
<mapped_index::symbol_table_slot
>
3545 ((mapped_index::symbol_table_slot
*) symbol_table
,
3546 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3549 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3554 /* Callback types for dwarf2_read_gdb_index. */
3556 typedef gdb::function_view
3557 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3558 get_gdb_index_contents_ftype
;
3559 typedef gdb::function_view
3560 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3561 get_gdb_index_contents_dwz_ftype
;
3563 /* Read .gdb_index. If everything went ok, initialize the "quick"
3564 elements of all the CUs and return 1. Otherwise, return 0. */
3567 dwarf2_read_gdb_index
3568 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3569 get_gdb_index_contents_ftype get_gdb_index_contents
,
3570 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3572 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3573 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3574 struct dwz_file
*dwz
;
3575 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3577 gdb::array_view
<const gdb_byte
> main_index_contents
3578 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3580 if (main_index_contents
.empty ())
3583 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3584 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3585 use_deprecated_index_sections
,
3586 main_index_contents
, map
.get (), &cu_list
,
3587 &cu_list_elements
, &types_list
,
3588 &types_list_elements
))
3591 /* Don't use the index if it's empty. */
3592 if (map
->symbol_table
.empty ())
3595 /* If there is a .dwz file, read it so we can get its CU list as
3597 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3600 struct mapped_index dwz_map
;
3601 const gdb_byte
*dwz_types_ignore
;
3602 offset_type dwz_types_elements_ignore
;
3604 gdb::array_view
<const gdb_byte
> dwz_index_content
3605 = get_gdb_index_contents_dwz (objfile
, dwz
);
3607 if (dwz_index_content
.empty ())
3610 if (!read_gdb_index_from_buffer (objfile
,
3611 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3612 1, dwz_index_content
, &dwz_map
,
3613 &dwz_list
, &dwz_list_elements
,
3615 &dwz_types_elements_ignore
))
3617 warning (_("could not read '.gdb_index' section from %s; skipping"),
3618 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3623 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3624 dwz_list
, dwz_list_elements
);
3626 if (types_list_elements
)
3628 /* We can only handle a single .debug_types when we have an
3630 if (dwarf2_per_objfile
->types
.size () != 1)
3633 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3635 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3636 types_list
, types_list_elements
);
3639 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3641 dwarf2_per_objfile
->index_table
= std::move (map
);
3642 dwarf2_per_objfile
->using_index
= 1;
3643 dwarf2_per_objfile
->quick_file_names_table
=
3644 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3649 /* die_reader_func for dw2_get_file_names. */
3652 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3653 const gdb_byte
*info_ptr
,
3654 struct die_info
*comp_unit_die
,
3658 struct dwarf2_cu
*cu
= reader
->cu
;
3659 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3660 struct dwarf2_per_objfile
*dwarf2_per_objfile
3661 = cu
->per_cu
->dwarf2_per_objfile
;
3662 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3663 struct dwarf2_per_cu_data
*lh_cu
;
3664 struct attribute
*attr
;
3666 struct quick_file_names
*qfn
;
3668 gdb_assert (! this_cu
->is_debug_types
);
3670 /* Our callers never want to match partial units -- instead they
3671 will match the enclosing full CU. */
3672 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3674 this_cu
->v
.quick
->no_file_data
= 1;
3682 sect_offset line_offset
{};
3684 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3685 if (attr
!= nullptr)
3687 struct quick_file_names find_entry
;
3689 line_offset
= (sect_offset
) DW_UNSND (attr
);
3691 /* We may have already read in this line header (TU line header sharing).
3692 If we have we're done. */
3693 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3694 find_entry
.hash
.line_sect_off
= line_offset
;
3695 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3696 &find_entry
, INSERT
);
3699 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3703 lh
= dwarf_decode_line_header (line_offset
, cu
);
3707 lh_cu
->v
.quick
->no_file_data
= 1;
3711 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3712 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3713 qfn
->hash
.line_sect_off
= line_offset
;
3714 gdb_assert (slot
!= NULL
);
3717 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3720 if (strcmp (fnd
.name
, "<unknown>") != 0)
3723 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3725 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3727 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3728 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3729 qfn
->file_names
[i
+ offset
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3730 qfn
->real_names
= NULL
;
3732 lh_cu
->v
.quick
->file_names
= qfn
;
3735 /* A helper for the "quick" functions which attempts to read the line
3736 table for THIS_CU. */
3738 static struct quick_file_names
*
3739 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3741 /* This should never be called for TUs. */
3742 gdb_assert (! this_cu
->is_debug_types
);
3743 /* Nor type unit groups. */
3744 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3746 if (this_cu
->v
.quick
->file_names
!= NULL
)
3747 return this_cu
->v
.quick
->file_names
;
3748 /* If we know there is no line data, no point in looking again. */
3749 if (this_cu
->v
.quick
->no_file_data
)
3752 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3754 if (this_cu
->v
.quick
->no_file_data
)
3756 return this_cu
->v
.quick
->file_names
;
3759 /* A helper for the "quick" functions which computes and caches the
3760 real path for a given file name from the line table. */
3763 dw2_get_real_path (struct objfile
*objfile
,
3764 struct quick_file_names
*qfn
, int index
)
3766 if (qfn
->real_names
== NULL
)
3767 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3768 qfn
->num_file_names
, const char *);
3770 if (qfn
->real_names
[index
] == NULL
)
3771 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3773 return qfn
->real_names
[index
];
3776 static struct symtab
*
3777 dw2_find_last_source_symtab (struct objfile
*objfile
)
3779 struct dwarf2_per_objfile
*dwarf2_per_objfile
3780 = get_dwarf2_per_objfile (objfile
);
3781 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3782 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3787 return compunit_primary_filetab (cust
);
3790 /* Traversal function for dw2_forget_cached_source_info. */
3793 dw2_free_cached_file_names (void **slot
, void *info
)
3795 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3797 if (file_data
->real_names
)
3801 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3803 xfree ((void*) file_data
->real_names
[i
]);
3804 file_data
->real_names
[i
] = NULL
;
3812 dw2_forget_cached_source_info (struct objfile
*objfile
)
3814 struct dwarf2_per_objfile
*dwarf2_per_objfile
3815 = get_dwarf2_per_objfile (objfile
);
3817 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3818 dw2_free_cached_file_names
, NULL
);
3821 /* Helper function for dw2_map_symtabs_matching_filename that expands
3822 the symtabs and calls the iterator. */
3825 dw2_map_expand_apply (struct objfile
*objfile
,
3826 struct dwarf2_per_cu_data
*per_cu
,
3827 const char *name
, const char *real_path
,
3828 gdb::function_view
<bool (symtab
*)> callback
)
3830 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3832 /* Don't visit already-expanded CUs. */
3833 if (per_cu
->v
.quick
->compunit_symtab
)
3836 /* This may expand more than one symtab, and we want to iterate over
3838 dw2_instantiate_symtab (per_cu
, false);
3840 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3841 last_made
, callback
);
3844 /* Implementation of the map_symtabs_matching_filename method. */
3847 dw2_map_symtabs_matching_filename
3848 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3849 gdb::function_view
<bool (symtab
*)> callback
)
3851 const char *name_basename
= lbasename (name
);
3852 struct dwarf2_per_objfile
*dwarf2_per_objfile
3853 = get_dwarf2_per_objfile (objfile
);
3855 /* The rule is CUs specify all the files, including those used by
3856 any TU, so there's no need to scan TUs here. */
3858 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3860 /* We only need to look at symtabs not already expanded. */
3861 if (per_cu
->v
.quick
->compunit_symtab
)
3864 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3865 if (file_data
== NULL
)
3868 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3870 const char *this_name
= file_data
->file_names
[j
];
3871 const char *this_real_name
;
3873 if (compare_filenames_for_search (this_name
, name
))
3875 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3881 /* Before we invoke realpath, which can get expensive when many
3882 files are involved, do a quick comparison of the basenames. */
3883 if (! basenames_may_differ
3884 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3887 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3888 if (compare_filenames_for_search (this_real_name
, name
))
3890 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3896 if (real_path
!= NULL
)
3898 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3899 gdb_assert (IS_ABSOLUTE_PATH (name
));
3900 if (this_real_name
!= NULL
3901 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3903 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3915 /* Struct used to manage iterating over all CUs looking for a symbol. */
3917 struct dw2_symtab_iterator
3919 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3920 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3921 /* If set, only look for symbols that match that block. Valid values are
3922 GLOBAL_BLOCK and STATIC_BLOCK. */
3923 gdb::optional
<block_enum
> block_index
;
3924 /* The kind of symbol we're looking for. */
3926 /* The list of CUs from the index entry of the symbol,
3927 or NULL if not found. */
3929 /* The next element in VEC to look at. */
3931 /* The number of elements in VEC, or zero if there is no match. */
3933 /* Have we seen a global version of the symbol?
3934 If so we can ignore all further global instances.
3935 This is to work around gold/15646, inefficient gold-generated
3940 /* Initialize the index symtab iterator ITER. */
3943 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3944 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3945 gdb::optional
<block_enum
> block_index
,
3949 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3950 iter
->block_index
= block_index
;
3951 iter
->domain
= domain
;
3953 iter
->global_seen
= 0;
3955 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3957 /* index is NULL if OBJF_READNOW. */
3958 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3959 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3967 /* Return the next matching CU or NULL if there are no more. */
3969 static struct dwarf2_per_cu_data
*
3970 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3972 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3974 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3976 offset_type cu_index_and_attrs
=
3977 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3978 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3979 gdb_index_symbol_kind symbol_kind
=
3980 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3981 /* Only check the symbol attributes if they're present.
3982 Indices prior to version 7 don't record them,
3983 and indices >= 7 may elide them for certain symbols
3984 (gold does this). */
3986 (dwarf2_per_objfile
->index_table
->version
>= 7
3987 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3989 /* Don't crash on bad data. */
3990 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3991 + dwarf2_per_objfile
->all_type_units
.size ()))
3993 complaint (_(".gdb_index entry has bad CU index"
3995 objfile_name (dwarf2_per_objfile
->objfile
));
3999 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4001 /* Skip if already read in. */
4002 if (per_cu
->v
.quick
->compunit_symtab
)
4005 /* Check static vs global. */
4008 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4010 if (iter
->block_index
.has_value ())
4012 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
4014 if (is_static
!= want_static
)
4018 /* Work around gold/15646. */
4019 if (!is_static
&& iter
->global_seen
)
4022 iter
->global_seen
= 1;
4025 /* Only check the symbol's kind if it has one. */
4028 switch (iter
->domain
)
4031 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4032 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4033 /* Some types are also in VAR_DOMAIN. */
4034 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4038 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4042 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4046 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4061 static struct compunit_symtab
*
4062 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
4063 const char *name
, domain_enum domain
)
4065 struct compunit_symtab
*stab_best
= NULL
;
4066 struct dwarf2_per_objfile
*dwarf2_per_objfile
4067 = get_dwarf2_per_objfile (objfile
);
4069 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4071 struct dw2_symtab_iterator iter
;
4072 struct dwarf2_per_cu_data
*per_cu
;
4074 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
4076 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4078 struct symbol
*sym
, *with_opaque
= NULL
;
4079 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4080 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4081 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4083 sym
= block_find_symbol (block
, name
, domain
,
4084 block_find_non_opaque_type_preferred
,
4087 /* Some caution must be observed with overloaded functions
4088 and methods, since the index will not contain any overload
4089 information (but NAME might contain it). */
4092 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4094 if (with_opaque
!= NULL
4095 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4098 /* Keep looking through other CUs. */
4105 dw2_print_stats (struct objfile
*objfile
)
4107 struct dwarf2_per_objfile
*dwarf2_per_objfile
4108 = get_dwarf2_per_objfile (objfile
);
4109 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4110 + dwarf2_per_objfile
->all_type_units
.size ());
4113 for (int i
= 0; i
< total
; ++i
)
4115 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4117 if (!per_cu
->v
.quick
->compunit_symtab
)
4120 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4121 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4124 /* This dumps minimal information about the index.
4125 It is called via "mt print objfiles".
4126 One use is to verify .gdb_index has been loaded by the
4127 gdb.dwarf2/gdb-index.exp testcase. */
4130 dw2_dump (struct objfile
*objfile
)
4132 struct dwarf2_per_objfile
*dwarf2_per_objfile
4133 = get_dwarf2_per_objfile (objfile
);
4135 gdb_assert (dwarf2_per_objfile
->using_index
);
4136 printf_filtered (".gdb_index:");
4137 if (dwarf2_per_objfile
->index_table
!= NULL
)
4139 printf_filtered (" version %d\n",
4140 dwarf2_per_objfile
->index_table
->version
);
4143 printf_filtered (" faked for \"readnow\"\n");
4144 printf_filtered ("\n");
4148 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4149 const char *func_name
)
4151 struct dwarf2_per_objfile
*dwarf2_per_objfile
4152 = get_dwarf2_per_objfile (objfile
);
4154 struct dw2_symtab_iterator iter
;
4155 struct dwarf2_per_cu_data
*per_cu
;
4157 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
4159 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4160 dw2_instantiate_symtab (per_cu
, false);
4165 dw2_expand_all_symtabs (struct objfile
*objfile
)
4167 struct dwarf2_per_objfile
*dwarf2_per_objfile
4168 = get_dwarf2_per_objfile (objfile
);
4169 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4170 + dwarf2_per_objfile
->all_type_units
.size ());
4172 for (int i
= 0; i
< total_units
; ++i
)
4174 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4176 /* We don't want to directly expand a partial CU, because if we
4177 read it with the wrong language, then assertion failures can
4178 be triggered later on. See PR symtab/23010. So, tell
4179 dw2_instantiate_symtab to skip partial CUs -- any important
4180 partial CU will be read via DW_TAG_imported_unit anyway. */
4181 dw2_instantiate_symtab (per_cu
, true);
4186 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4187 const char *fullname
)
4189 struct dwarf2_per_objfile
*dwarf2_per_objfile
4190 = get_dwarf2_per_objfile (objfile
);
4192 /* We don't need to consider type units here.
4193 This is only called for examining code, e.g. expand_line_sal.
4194 There can be an order of magnitude (or more) more type units
4195 than comp units, and we avoid them if we can. */
4197 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4199 /* We only need to look at symtabs not already expanded. */
4200 if (per_cu
->v
.quick
->compunit_symtab
)
4203 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4204 if (file_data
== NULL
)
4207 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4209 const char *this_fullname
= file_data
->file_names
[j
];
4211 if (filename_cmp (this_fullname
, fullname
) == 0)
4213 dw2_instantiate_symtab (per_cu
, false);
4221 dw2_map_matching_symbols
4222 (struct objfile
*objfile
,
4223 const lookup_name_info
&name
, domain_enum domain
,
4225 gdb::function_view
<symbol_found_callback_ftype
> callback
,
4226 symbol_compare_ftype
*ordered_compare
)
4228 /* Currently unimplemented; used for Ada. The function can be called if the
4229 current language is Ada for a non-Ada objfile using GNU index. As Ada
4230 does not look for non-Ada symbols this function should just return. */
4233 /* Starting from a search name, return the string that finds the upper
4234 bound of all strings that start with SEARCH_NAME in a sorted name
4235 list. Returns the empty string to indicate that the upper bound is
4236 the end of the list. */
4239 make_sort_after_prefix_name (const char *search_name
)
4241 /* When looking to complete "func", we find the upper bound of all
4242 symbols that start with "func" by looking for where we'd insert
4243 the closest string that would follow "func" in lexicographical
4244 order. Usually, that's "func"-with-last-character-incremented,
4245 i.e. "fund". Mind non-ASCII characters, though. Usually those
4246 will be UTF-8 multi-byte sequences, but we can't be certain.
4247 Especially mind the 0xff character, which is a valid character in
4248 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4249 rule out compilers allowing it in identifiers. Note that
4250 conveniently, strcmp/strcasecmp are specified to compare
4251 characters interpreted as unsigned char. So what we do is treat
4252 the whole string as a base 256 number composed of a sequence of
4253 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4254 to 0, and carries 1 to the following more-significant position.
4255 If the very first character in SEARCH_NAME ends up incremented
4256 and carries/overflows, then the upper bound is the end of the
4257 list. The string after the empty string is also the empty
4260 Some examples of this operation:
4262 SEARCH_NAME => "+1" RESULT
4266 "\xff" "a" "\xff" => "\xff" "b"
4271 Then, with these symbols for example:
4277 completing "func" looks for symbols between "func" and
4278 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4279 which finds "func" and "func1", but not "fund".
4283 funcÿ (Latin1 'ÿ' [0xff])
4287 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4288 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4292 ÿÿ (Latin1 'ÿ' [0xff])
4295 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4296 the end of the list.
4298 std::string after
= search_name
;
4299 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4301 if (!after
.empty ())
4302 after
.back () = (unsigned char) after
.back () + 1;
4306 /* See declaration. */
4308 std::pair
<std::vector
<name_component
>::const_iterator
,
4309 std::vector
<name_component
>::const_iterator
>
4310 mapped_index_base::find_name_components_bounds
4311 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
4314 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4316 const char *lang_name
4317 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4319 /* Comparison function object for lower_bound that matches against a
4320 given symbol name. */
4321 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4324 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4325 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4326 return name_cmp (elem_name
, name
) < 0;
4329 /* Comparison function object for upper_bound that matches against a
4330 given symbol name. */
4331 auto lookup_compare_upper
= [&] (const char *name
,
4332 const name_component
&elem
)
4334 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4335 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4336 return name_cmp (name
, elem_name
) < 0;
4339 auto begin
= this->name_components
.begin ();
4340 auto end
= this->name_components
.end ();
4342 /* Find the lower bound. */
4345 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4348 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4351 /* Find the upper bound. */
4354 if (lookup_name_without_params
.completion_mode ())
4356 /* In completion mode, we want UPPER to point past all
4357 symbols names that have the same prefix. I.e., with
4358 these symbols, and completing "func":
4360 function << lower bound
4362 other_function << upper bound
4364 We find the upper bound by looking for the insertion
4365 point of "func"-with-last-character-incremented,
4367 std::string after
= make_sort_after_prefix_name (lang_name
);
4370 return std::lower_bound (lower
, end
, after
.c_str (),
4371 lookup_compare_lower
);
4374 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4377 return {lower
, upper
};
4380 /* See declaration. */
4383 mapped_index_base::build_name_components ()
4385 if (!this->name_components
.empty ())
4388 this->name_components_casing
= case_sensitivity
;
4390 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4392 /* The code below only knows how to break apart components of C++
4393 symbol names (and other languages that use '::' as
4394 namespace/module separator) and Ada symbol names. */
4395 auto count
= this->symbol_name_count ();
4396 for (offset_type idx
= 0; idx
< count
; idx
++)
4398 if (this->symbol_name_slot_invalid (idx
))
4401 const char *name
= this->symbol_name_at (idx
);
4403 /* Add each name component to the name component table. */
4404 unsigned int previous_len
= 0;
4406 if (strstr (name
, "::") != nullptr)
4408 for (unsigned int current_len
= cp_find_first_component (name
);
4409 name
[current_len
] != '\0';
4410 current_len
+= cp_find_first_component (name
+ current_len
))
4412 gdb_assert (name
[current_len
] == ':');
4413 this->name_components
.push_back ({previous_len
, idx
});
4414 /* Skip the '::'. */
4416 previous_len
= current_len
;
4421 /* Handle the Ada encoded (aka mangled) form here. */
4422 for (const char *iter
= strstr (name
, "__");
4424 iter
= strstr (iter
, "__"))
4426 this->name_components
.push_back ({previous_len
, idx
});
4428 previous_len
= iter
- name
;
4432 this->name_components
.push_back ({previous_len
, idx
});
4435 /* Sort name_components elements by name. */
4436 auto name_comp_compare
= [&] (const name_component
&left
,
4437 const name_component
&right
)
4439 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4440 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4442 const char *left_name
= left_qualified
+ left
.name_offset
;
4443 const char *right_name
= right_qualified
+ right
.name_offset
;
4445 return name_cmp (left_name
, right_name
) < 0;
4448 std::sort (this->name_components
.begin (),
4449 this->name_components
.end (),
4453 /* Helper for dw2_expand_symtabs_matching that works with a
4454 mapped_index_base instead of the containing objfile. This is split
4455 to a separate function in order to be able to unit test the
4456 name_components matching using a mock mapped_index_base. For each
4457 symbol name that matches, calls MATCH_CALLBACK, passing it the
4458 symbol's index in the mapped_index_base symbol table. */
4461 dw2_expand_symtabs_matching_symbol
4462 (mapped_index_base
&index
,
4463 const lookup_name_info
&lookup_name_in
,
4464 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4465 enum search_domain kind
,
4466 gdb::function_view
<bool (offset_type
)> match_callback
)
4468 lookup_name_info lookup_name_without_params
4469 = lookup_name_in
.make_ignore_params ();
4471 /* Build the symbol name component sorted vector, if we haven't
4473 index
.build_name_components ();
4475 /* The same symbol may appear more than once in the range though.
4476 E.g., if we're looking for symbols that complete "w", and we have
4477 a symbol named "w1::w2", we'll find the two name components for
4478 that same symbol in the range. To be sure we only call the
4479 callback once per symbol, we first collect the symbol name
4480 indexes that matched in a temporary vector and ignore
4482 std::vector
<offset_type
> matches
;
4484 struct name_and_matcher
4486 symbol_name_matcher_ftype
*matcher
;
4487 const std::string
&name
;
4489 bool operator== (const name_and_matcher
&other
) const
4491 return matcher
== other
.matcher
&& name
== other
.name
;
4495 /* A vector holding all the different symbol name matchers, for all
4497 std::vector
<name_and_matcher
> matchers
;
4499 for (int i
= 0; i
< nr_languages
; i
++)
4501 enum language lang_e
= (enum language
) i
;
4503 const language_defn
*lang
= language_def (lang_e
);
4504 symbol_name_matcher_ftype
*name_matcher
4505 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4507 name_and_matcher key
{
4509 lookup_name_without_params
.language_lookup_name (lang_e
)
4512 /* Don't insert the same comparison routine more than once.
4513 Note that we do this linear walk. This is not a problem in
4514 practice because the number of supported languages is
4516 if (std::find (matchers
.begin (), matchers
.end (), key
)
4519 matchers
.push_back (std::move (key
));
4522 = index
.find_name_components_bounds (lookup_name_without_params
,
4525 /* Now for each symbol name in range, check to see if we have a name
4526 match, and if so, call the MATCH_CALLBACK callback. */
4528 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4530 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4532 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4533 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4536 matches
.push_back (bounds
.first
->idx
);
4540 std::sort (matches
.begin (), matches
.end ());
4542 /* Finally call the callback, once per match. */
4544 for (offset_type idx
: matches
)
4548 if (!match_callback (idx
))
4554 /* Above we use a type wider than idx's for 'prev', since 0 and
4555 (offset_type)-1 are both possible values. */
4556 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4561 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4563 /* A mock .gdb_index/.debug_names-like name index table, enough to
4564 exercise dw2_expand_symtabs_matching_symbol, which works with the
4565 mapped_index_base interface. Builds an index from the symbol list
4566 passed as parameter to the constructor. */
4567 class mock_mapped_index
: public mapped_index_base
4570 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4571 : m_symbol_table (symbols
)
4574 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4576 /* Return the number of names in the symbol table. */
4577 size_t symbol_name_count () const override
4579 return m_symbol_table
.size ();
4582 /* Get the name of the symbol at IDX in the symbol table. */
4583 const char *symbol_name_at (offset_type idx
) const override
4585 return m_symbol_table
[idx
];
4589 gdb::array_view
<const char *> m_symbol_table
;
4592 /* Convenience function that converts a NULL pointer to a "<null>"
4593 string, to pass to print routines. */
4596 string_or_null (const char *str
)
4598 return str
!= NULL
? str
: "<null>";
4601 /* Check if a lookup_name_info built from
4602 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4603 index. EXPECTED_LIST is the list of expected matches, in expected
4604 matching order. If no match expected, then an empty list is
4605 specified. Returns true on success. On failure prints a warning
4606 indicating the file:line that failed, and returns false. */
4609 check_match (const char *file
, int line
,
4610 mock_mapped_index
&mock_index
,
4611 const char *name
, symbol_name_match_type match_type
,
4612 bool completion_mode
,
4613 std::initializer_list
<const char *> expected_list
)
4615 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4617 bool matched
= true;
4619 auto mismatch
= [&] (const char *expected_str
,
4622 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4623 "expected=\"%s\", got=\"%s\"\n"),
4625 (match_type
== symbol_name_match_type::FULL
4627 name
, string_or_null (expected_str
), string_or_null (got
));
4631 auto expected_it
= expected_list
.begin ();
4632 auto expected_end
= expected_list
.end ();
4634 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4636 [&] (offset_type idx
)
4638 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4639 const char *expected_str
4640 = expected_it
== expected_end
? NULL
: *expected_it
++;
4642 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4643 mismatch (expected_str
, matched_name
);
4647 const char *expected_str
4648 = expected_it
== expected_end
? NULL
: *expected_it
++;
4649 if (expected_str
!= NULL
)
4650 mismatch (expected_str
, NULL
);
4655 /* The symbols added to the mock mapped_index for testing (in
4657 static const char *test_symbols
[] = {
4666 "ns2::tmpl<int>::foo2",
4667 "(anonymous namespace)::A::B::C",
4669 /* These are used to check that the increment-last-char in the
4670 matching algorithm for completion doesn't match "t1_fund" when
4671 completing "t1_func". */
4677 /* A UTF-8 name with multi-byte sequences to make sure that
4678 cp-name-parser understands this as a single identifier ("função"
4679 is "function" in PT). */
4682 /* \377 (0xff) is Latin1 'ÿ'. */
4685 /* \377 (0xff) is Latin1 'ÿ'. */
4689 /* A name with all sorts of complications. Starts with "z" to make
4690 it easier for the completion tests below. */
4691 #define Z_SYM_NAME \
4692 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4693 "::tuple<(anonymous namespace)::ui*, " \
4694 "std::default_delete<(anonymous namespace)::ui>, void>"
4699 /* Returns true if the mapped_index_base::find_name_component_bounds
4700 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4701 in completion mode. */
4704 check_find_bounds_finds (mapped_index_base
&index
,
4705 const char *search_name
,
4706 gdb::array_view
<const char *> expected_syms
)
4708 lookup_name_info
lookup_name (search_name
,
4709 symbol_name_match_type::FULL
, true);
4711 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4714 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4715 if (distance
!= expected_syms
.size ())
4718 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4720 auto nc_elem
= bounds
.first
+ exp_elem
;
4721 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4722 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4729 /* Test the lower-level mapped_index::find_name_component_bounds
4733 test_mapped_index_find_name_component_bounds ()
4735 mock_mapped_index
mock_index (test_symbols
);
4737 mock_index
.build_name_components ();
4739 /* Test the lower-level mapped_index::find_name_component_bounds
4740 method in completion mode. */
4742 static const char *expected_syms
[] = {
4747 SELF_CHECK (check_find_bounds_finds (mock_index
,
4748 "t1_func", expected_syms
));
4751 /* Check that the increment-last-char in the name matching algorithm
4752 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4754 static const char *expected_syms1
[] = {
4758 SELF_CHECK (check_find_bounds_finds (mock_index
,
4759 "\377", expected_syms1
));
4761 static const char *expected_syms2
[] = {
4764 SELF_CHECK (check_find_bounds_finds (mock_index
,
4765 "\377\377", expected_syms2
));
4769 /* Test dw2_expand_symtabs_matching_symbol. */
4772 test_dw2_expand_symtabs_matching_symbol ()
4774 mock_mapped_index
mock_index (test_symbols
);
4776 /* We let all tests run until the end even if some fails, for debug
4778 bool any_mismatch
= false;
4780 /* Create the expected symbols list (an initializer_list). Needed
4781 because lists have commas, and we need to pass them to CHECK,
4782 which is a macro. */
4783 #define EXPECT(...) { __VA_ARGS__ }
4785 /* Wrapper for check_match that passes down the current
4786 __FILE__/__LINE__. */
4787 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4788 any_mismatch |= !check_match (__FILE__, __LINE__, \
4790 NAME, MATCH_TYPE, COMPLETION_MODE, \
4793 /* Identity checks. */
4794 for (const char *sym
: test_symbols
)
4796 /* Should be able to match all existing symbols. */
4797 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4800 /* Should be able to match all existing symbols with
4802 std::string with_params
= std::string (sym
) + "(int)";
4803 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4806 /* Should be able to match all existing symbols with
4807 parameters and qualifiers. */
4808 with_params
= std::string (sym
) + " ( int ) const";
4809 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4812 /* This should really find sym, but cp-name-parser.y doesn't
4813 know about lvalue/rvalue qualifiers yet. */
4814 with_params
= std::string (sym
) + " ( int ) &&";
4815 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4819 /* Check that the name matching algorithm for completion doesn't get
4820 confused with Latin1 'ÿ' / 0xff. */
4822 static const char str
[] = "\377";
4823 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4824 EXPECT ("\377", "\377\377123"));
4827 /* Check that the increment-last-char in the matching algorithm for
4828 completion doesn't match "t1_fund" when completing "t1_func". */
4830 static const char str
[] = "t1_func";
4831 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4832 EXPECT ("t1_func", "t1_func1"));
4835 /* Check that completion mode works at each prefix of the expected
4838 static const char str
[] = "function(int)";
4839 size_t len
= strlen (str
);
4842 for (size_t i
= 1; i
< len
; i
++)
4844 lookup
.assign (str
, i
);
4845 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4846 EXPECT ("function"));
4850 /* While "w" is a prefix of both components, the match function
4851 should still only be called once. */
4853 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4855 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4859 /* Same, with a "complicated" symbol. */
4861 static const char str
[] = Z_SYM_NAME
;
4862 size_t len
= strlen (str
);
4865 for (size_t i
= 1; i
< len
; i
++)
4867 lookup
.assign (str
, i
);
4868 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4869 EXPECT (Z_SYM_NAME
));
4873 /* In FULL mode, an incomplete symbol doesn't match. */
4875 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4879 /* A complete symbol with parameters matches any overload, since the
4880 index has no overload info. */
4882 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4883 EXPECT ("std::zfunction", "std::zfunction2"));
4884 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4885 EXPECT ("std::zfunction", "std::zfunction2"));
4886 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4887 EXPECT ("std::zfunction", "std::zfunction2"));
4890 /* Check that whitespace is ignored appropriately. A symbol with a
4891 template argument list. */
4893 static const char expected
[] = "ns::foo<int>";
4894 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4896 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4900 /* Check that whitespace is ignored appropriately. A symbol with a
4901 template argument list that includes a pointer. */
4903 static const char expected
[] = "ns::foo<char*>";
4904 /* Try both completion and non-completion modes. */
4905 static const bool completion_mode
[2] = {false, true};
4906 for (size_t i
= 0; i
< 2; i
++)
4908 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4909 completion_mode
[i
], EXPECT (expected
));
4910 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4911 completion_mode
[i
], EXPECT (expected
));
4913 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4914 completion_mode
[i
], EXPECT (expected
));
4915 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4916 completion_mode
[i
], EXPECT (expected
));
4921 /* Check method qualifiers are ignored. */
4922 static const char expected
[] = "ns::foo<char*>";
4923 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4924 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4925 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4926 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4927 CHECK_MATCH ("foo < char * > ( int ) const",
4928 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4929 CHECK_MATCH ("foo < char * > ( int ) &&",
4930 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4933 /* Test lookup names that don't match anything. */
4935 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4938 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4942 /* Some wild matching tests, exercising "(anonymous namespace)",
4943 which should not be confused with a parameter list. */
4945 static const char *syms
[] = {
4949 "A :: B :: C ( int )",
4954 for (const char *s
: syms
)
4956 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4957 EXPECT ("(anonymous namespace)::A::B::C"));
4962 static const char expected
[] = "ns2::tmpl<int>::foo2";
4963 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4965 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4969 SELF_CHECK (!any_mismatch
);
4978 test_mapped_index_find_name_component_bounds ();
4979 test_dw2_expand_symtabs_matching_symbol ();
4982 }} // namespace selftests::dw2_expand_symtabs_matching
4984 #endif /* GDB_SELF_TEST */
4986 /* If FILE_MATCHER is NULL or if PER_CU has
4987 dwarf2_per_cu_quick_data::MARK set (see
4988 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4989 EXPANSION_NOTIFY on it. */
4992 dw2_expand_symtabs_matching_one
4993 (struct dwarf2_per_cu_data
*per_cu
,
4994 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4995 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4997 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4999 bool symtab_was_null
5000 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5002 dw2_instantiate_symtab (per_cu
, false);
5004 if (expansion_notify
!= NULL
5006 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5007 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5011 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5012 matched, to expand corresponding CUs that were marked. IDX is the
5013 index of the symbol name that matched. */
5016 dw2_expand_marked_cus
5017 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5018 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5019 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5022 offset_type
*vec
, vec_len
, vec_idx
;
5023 bool global_seen
= false;
5024 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5026 vec
= (offset_type
*) (index
.constant_pool
5027 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5028 vec_len
= MAYBE_SWAP (vec
[0]);
5029 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5031 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5032 /* This value is only valid for index versions >= 7. */
5033 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5034 gdb_index_symbol_kind symbol_kind
=
5035 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5036 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5037 /* Only check the symbol attributes if they're present.
5038 Indices prior to version 7 don't record them,
5039 and indices >= 7 may elide them for certain symbols
5040 (gold does this). */
5043 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5045 /* Work around gold/15646. */
5048 if (!is_static
&& global_seen
)
5054 /* Only check the symbol's kind if it has one. */
5059 case VARIABLES_DOMAIN
:
5060 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5063 case FUNCTIONS_DOMAIN
:
5064 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5068 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5071 case MODULES_DOMAIN
:
5072 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
5080 /* Don't crash on bad data. */
5081 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5082 + dwarf2_per_objfile
->all_type_units
.size ()))
5084 complaint (_(".gdb_index entry has bad CU index"
5086 objfile_name (dwarf2_per_objfile
->objfile
));
5090 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5091 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5096 /* If FILE_MATCHER is non-NULL, set all the
5097 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5098 that match FILE_MATCHER. */
5101 dw_expand_symtabs_matching_file_matcher
5102 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5103 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5105 if (file_matcher
== NULL
)
5108 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5110 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5112 NULL
, xcalloc
, xfree
));
5113 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5115 NULL
, xcalloc
, xfree
));
5117 /* The rule is CUs specify all the files, including those used by
5118 any TU, so there's no need to scan TUs here. */
5120 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5124 per_cu
->v
.quick
->mark
= 0;
5126 /* We only need to look at symtabs not already expanded. */
5127 if (per_cu
->v
.quick
->compunit_symtab
)
5130 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5131 if (file_data
== NULL
)
5134 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5136 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5138 per_cu
->v
.quick
->mark
= 1;
5142 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5144 const char *this_real_name
;
5146 if (file_matcher (file_data
->file_names
[j
], false))
5148 per_cu
->v
.quick
->mark
= 1;
5152 /* Before we invoke realpath, which can get expensive when many
5153 files are involved, do a quick comparison of the basenames. */
5154 if (!basenames_may_differ
5155 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5159 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5160 if (file_matcher (this_real_name
, false))
5162 per_cu
->v
.quick
->mark
= 1;
5167 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5168 ? visited_found
.get ()
5169 : visited_not_found
.get (),
5176 dw2_expand_symtabs_matching
5177 (struct objfile
*objfile
,
5178 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5179 const lookup_name_info
&lookup_name
,
5180 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5181 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5182 enum search_domain kind
)
5184 struct dwarf2_per_objfile
*dwarf2_per_objfile
5185 = get_dwarf2_per_objfile (objfile
);
5187 /* index_table is NULL if OBJF_READNOW. */
5188 if (!dwarf2_per_objfile
->index_table
)
5191 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5193 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5195 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5197 kind
, [&] (offset_type idx
)
5199 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5200 expansion_notify
, kind
);
5205 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5208 static struct compunit_symtab
*
5209 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5214 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5215 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5218 if (cust
->includes
== NULL
)
5221 for (i
= 0; cust
->includes
[i
]; ++i
)
5223 struct compunit_symtab
*s
= cust
->includes
[i
];
5225 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5233 static struct compunit_symtab
*
5234 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5235 struct bound_minimal_symbol msymbol
,
5237 struct obj_section
*section
,
5240 struct dwarf2_per_cu_data
*data
;
5241 struct compunit_symtab
*result
;
5243 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5246 CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
5247 SECT_OFF_TEXT (objfile
));
5248 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5249 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5253 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5254 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5255 paddress (get_objfile_arch (objfile
), pc
));
5258 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5261 gdb_assert (result
!= NULL
);
5266 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5267 void *data
, int need_fullname
)
5269 struct dwarf2_per_objfile
*dwarf2_per_objfile
5270 = get_dwarf2_per_objfile (objfile
);
5272 if (!dwarf2_per_objfile
->filenames_cache
)
5274 dwarf2_per_objfile
->filenames_cache
.emplace ();
5276 htab_up
visited (htab_create_alloc (10,
5277 htab_hash_pointer
, htab_eq_pointer
,
5278 NULL
, xcalloc
, xfree
));
5280 /* The rule is CUs specify all the files, including those used
5281 by any TU, so there's no need to scan TUs here. We can
5282 ignore file names coming from already-expanded CUs. */
5284 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5286 if (per_cu
->v
.quick
->compunit_symtab
)
5288 void **slot
= htab_find_slot (visited
.get (),
5289 per_cu
->v
.quick
->file_names
,
5292 *slot
= per_cu
->v
.quick
->file_names
;
5296 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5298 /* We only need to look at symtabs not already expanded. */
5299 if (per_cu
->v
.quick
->compunit_symtab
)
5302 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5303 if (file_data
== NULL
)
5306 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5309 /* Already visited. */
5314 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5316 const char *filename
= file_data
->file_names
[j
];
5317 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5322 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5324 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5327 this_real_name
= gdb_realpath (filename
);
5328 (*fun
) (filename
, this_real_name
.get (), data
);
5333 dw2_has_symbols (struct objfile
*objfile
)
5338 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5341 dw2_find_last_source_symtab
,
5342 dw2_forget_cached_source_info
,
5343 dw2_map_symtabs_matching_filename
,
5347 dw2_expand_symtabs_for_function
,
5348 dw2_expand_all_symtabs
,
5349 dw2_expand_symtabs_with_fullname
,
5350 dw2_map_matching_symbols
,
5351 dw2_expand_symtabs_matching
,
5352 dw2_find_pc_sect_compunit_symtab
,
5354 dw2_map_symbol_filenames
5357 /* DWARF-5 debug_names reader. */
5359 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5360 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5362 /* A helper function that reads the .debug_names section in SECTION
5363 and fills in MAP. FILENAME is the name of the file containing the
5364 section; it is used for error reporting.
5366 Returns true if all went well, false otherwise. */
5369 read_debug_names_from_section (struct objfile
*objfile
,
5370 const char *filename
,
5371 struct dwarf2_section_info
*section
,
5372 mapped_debug_names
&map
)
5374 if (dwarf2_section_empty_p (section
))
5377 /* Older elfutils strip versions could keep the section in the main
5378 executable while splitting it for the separate debug info file. */
5379 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5382 dwarf2_read_section (objfile
, section
);
5384 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5386 const gdb_byte
*addr
= section
->buffer
;
5388 bfd
*const abfd
= get_section_bfd_owner (section
);
5390 unsigned int bytes_read
;
5391 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5394 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5395 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5396 if (bytes_read
+ length
!= section
->size
)
5398 /* There may be multiple per-CU indices. */
5399 warning (_("Section .debug_names in %s length %s does not match "
5400 "section length %s, ignoring .debug_names."),
5401 filename
, plongest (bytes_read
+ length
),
5402 pulongest (section
->size
));
5406 /* The version number. */
5407 uint16_t version
= read_2_bytes (abfd
, addr
);
5411 warning (_("Section .debug_names in %s has unsupported version %d, "
5412 "ignoring .debug_names."),
5418 uint16_t padding
= read_2_bytes (abfd
, addr
);
5422 warning (_("Section .debug_names in %s has unsupported padding %d, "
5423 "ignoring .debug_names."),
5428 /* comp_unit_count - The number of CUs in the CU list. */
5429 map
.cu_count
= read_4_bytes (abfd
, addr
);
5432 /* local_type_unit_count - The number of TUs in the local TU
5434 map
.tu_count
= read_4_bytes (abfd
, addr
);
5437 /* foreign_type_unit_count - The number of TUs in the foreign TU
5439 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5441 if (foreign_tu_count
!= 0)
5443 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5444 "ignoring .debug_names."),
5445 filename
, static_cast<unsigned long> (foreign_tu_count
));
5449 /* bucket_count - The number of hash buckets in the hash lookup
5451 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5454 /* name_count - The number of unique names in the index. */
5455 map
.name_count
= read_4_bytes (abfd
, addr
);
5458 /* abbrev_table_size - The size in bytes of the abbreviations
5460 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5463 /* augmentation_string_size - The size in bytes of the augmentation
5464 string. This value is rounded up to a multiple of 4. */
5465 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5467 map
.augmentation_is_gdb
= ((augmentation_string_size
5468 == sizeof (dwarf5_augmentation
))
5469 && memcmp (addr
, dwarf5_augmentation
,
5470 sizeof (dwarf5_augmentation
)) == 0);
5471 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5472 addr
+= augmentation_string_size
;
5475 map
.cu_table_reordered
= addr
;
5476 addr
+= map
.cu_count
* map
.offset_size
;
5478 /* List of Local TUs */
5479 map
.tu_table_reordered
= addr
;
5480 addr
+= map
.tu_count
* map
.offset_size
;
5482 /* Hash Lookup Table */
5483 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5484 addr
+= map
.bucket_count
* 4;
5485 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5486 addr
+= map
.name_count
* 4;
5489 map
.name_table_string_offs_reordered
= addr
;
5490 addr
+= map
.name_count
* map
.offset_size
;
5491 map
.name_table_entry_offs_reordered
= addr
;
5492 addr
+= map
.name_count
* map
.offset_size
;
5494 const gdb_byte
*abbrev_table_start
= addr
;
5497 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5502 const auto insertpair
5503 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5504 if (!insertpair
.second
)
5506 warning (_("Section .debug_names in %s has duplicate index %s, "
5507 "ignoring .debug_names."),
5508 filename
, pulongest (index_num
));
5511 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5512 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5517 mapped_debug_names::index_val::attr attr
;
5518 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5520 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5522 if (attr
.form
== DW_FORM_implicit_const
)
5524 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5528 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5530 indexval
.attr_vec
.push_back (std::move (attr
));
5533 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5535 warning (_("Section .debug_names in %s has abbreviation_table "
5536 "of size %s vs. written as %u, ignoring .debug_names."),
5537 filename
, plongest (addr
- abbrev_table_start
),
5541 map
.entry_pool
= addr
;
5546 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5550 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5551 const mapped_debug_names
&map
,
5552 dwarf2_section_info
§ion
,
5555 sect_offset sect_off_prev
;
5556 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5558 sect_offset sect_off_next
;
5559 if (i
< map
.cu_count
)
5562 = (sect_offset
) (extract_unsigned_integer
5563 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5565 map
.dwarf5_byte_order
));
5568 sect_off_next
= (sect_offset
) section
.size
;
5571 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5572 dwarf2_per_cu_data
*per_cu
5573 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5574 sect_off_prev
, length
);
5575 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5577 sect_off_prev
= sect_off_next
;
5581 /* Read the CU list from the mapped index, and use it to create all
5582 the CU objects for this dwarf2_per_objfile. */
5585 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5586 const mapped_debug_names
&map
,
5587 const mapped_debug_names
&dwz_map
)
5589 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5590 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5592 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5593 dwarf2_per_objfile
->info
,
5594 false /* is_dwz */);
5596 if (dwz_map
.cu_count
== 0)
5599 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5600 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5604 /* Read .debug_names. If everything went ok, initialize the "quick"
5605 elements of all the CUs and return true. Otherwise, return false. */
5608 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5610 std::unique_ptr
<mapped_debug_names
> map
5611 (new mapped_debug_names (dwarf2_per_objfile
));
5612 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5613 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5615 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5616 &dwarf2_per_objfile
->debug_names
,
5620 /* Don't use the index if it's empty. */
5621 if (map
->name_count
== 0)
5624 /* If there is a .dwz file, read it so we can get its CU list as
5626 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5629 if (!read_debug_names_from_section (objfile
,
5630 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5631 &dwz
->debug_names
, dwz_map
))
5633 warning (_("could not read '.debug_names' section from %s; skipping"),
5634 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5639 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5641 if (map
->tu_count
!= 0)
5643 /* We can only handle a single .debug_types when we have an
5645 if (dwarf2_per_objfile
->types
.size () != 1)
5648 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5650 create_signatured_type_table_from_debug_names
5651 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5654 create_addrmap_from_aranges (dwarf2_per_objfile
,
5655 &dwarf2_per_objfile
->debug_aranges
);
5657 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5658 dwarf2_per_objfile
->using_index
= 1;
5659 dwarf2_per_objfile
->quick_file_names_table
=
5660 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5665 /* Type used to manage iterating over all CUs looking for a symbol for
5668 class dw2_debug_names_iterator
5671 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5672 gdb::optional
<block_enum
> block_index
,
5675 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5676 m_addr (find_vec_in_debug_names (map
, name
))
5679 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5680 search_domain search
, uint32_t namei
)
5683 m_addr (find_vec_in_debug_names (map
, namei
))
5686 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5687 block_enum block_index
, domain_enum domain
,
5689 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5690 m_addr (find_vec_in_debug_names (map
, namei
))
5693 /* Return the next matching CU or NULL if there are no more. */
5694 dwarf2_per_cu_data
*next ();
5697 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5699 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5702 /* The internalized form of .debug_names. */
5703 const mapped_debug_names
&m_map
;
5705 /* If set, only look for symbols that match that block. Valid values are
5706 GLOBAL_BLOCK and STATIC_BLOCK. */
5707 const gdb::optional
<block_enum
> m_block_index
;
5709 /* The kind of symbol we're looking for. */
5710 const domain_enum m_domain
= UNDEF_DOMAIN
;
5711 const search_domain m_search
= ALL_DOMAIN
;
5713 /* The list of CUs from the index entry of the symbol, or NULL if
5715 const gdb_byte
*m_addr
;
5719 mapped_debug_names::namei_to_name (uint32_t namei
) const
5721 const ULONGEST namei_string_offs
5722 = extract_unsigned_integer ((name_table_string_offs_reordered
5723 + namei
* offset_size
),
5726 return read_indirect_string_at_offset
5727 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5730 /* Find a slot in .debug_names for the object named NAME. If NAME is
5731 found, return pointer to its pool data. If NAME cannot be found,
5735 dw2_debug_names_iterator::find_vec_in_debug_names
5736 (const mapped_debug_names
&map
, const char *name
)
5738 int (*cmp
) (const char *, const char *);
5740 gdb::unique_xmalloc_ptr
<char> without_params
;
5741 if (current_language
->la_language
== language_cplus
5742 || current_language
->la_language
== language_fortran
5743 || current_language
->la_language
== language_d
)
5745 /* NAME is already canonical. Drop any qualifiers as
5746 .debug_names does not contain any. */
5748 if (strchr (name
, '(') != NULL
)
5750 without_params
= cp_remove_params (name
);
5751 if (without_params
!= NULL
)
5752 name
= without_params
.get ();
5756 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5758 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5760 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5761 (map
.bucket_table_reordered
5762 + (full_hash
% map
.bucket_count
)), 4,
5763 map
.dwarf5_byte_order
);
5767 if (namei
>= map
.name_count
)
5769 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5771 namei
, map
.name_count
,
5772 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5778 const uint32_t namei_full_hash
5779 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5780 (map
.hash_table_reordered
+ namei
), 4,
5781 map
.dwarf5_byte_order
);
5782 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5785 if (full_hash
== namei_full_hash
)
5787 const char *const namei_string
= map
.namei_to_name (namei
);
5789 #if 0 /* An expensive sanity check. */
5790 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5792 complaint (_("Wrong .debug_names hash for string at index %u "
5794 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5799 if (cmp (namei_string
, name
) == 0)
5801 const ULONGEST namei_entry_offs
5802 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5803 + namei
* map
.offset_size
),
5804 map
.offset_size
, map
.dwarf5_byte_order
);
5805 return map
.entry_pool
+ namei_entry_offs
;
5810 if (namei
>= map
.name_count
)
5816 dw2_debug_names_iterator::find_vec_in_debug_names
5817 (const mapped_debug_names
&map
, uint32_t namei
)
5819 if (namei
>= map
.name_count
)
5821 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5823 namei
, map
.name_count
,
5824 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5828 const ULONGEST namei_entry_offs
5829 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5830 + namei
* map
.offset_size
),
5831 map
.offset_size
, map
.dwarf5_byte_order
);
5832 return map
.entry_pool
+ namei_entry_offs
;
5835 /* See dw2_debug_names_iterator. */
5837 dwarf2_per_cu_data
*
5838 dw2_debug_names_iterator::next ()
5843 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5844 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5845 bfd
*const abfd
= objfile
->obfd
;
5849 unsigned int bytes_read
;
5850 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5851 m_addr
+= bytes_read
;
5855 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5856 if (indexval_it
== m_map
.abbrev_map
.cend ())
5858 complaint (_("Wrong .debug_names undefined abbrev code %s "
5860 pulongest (abbrev
), objfile_name (objfile
));
5863 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5864 enum class symbol_linkage
{
5868 } symbol_linkage_
= symbol_linkage::unknown
;
5869 dwarf2_per_cu_data
*per_cu
= NULL
;
5870 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5875 case DW_FORM_implicit_const
:
5876 ull
= attr
.implicit_const
;
5878 case DW_FORM_flag_present
:
5882 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5883 m_addr
+= bytes_read
;
5886 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5887 dwarf_form_name (attr
.form
),
5888 objfile_name (objfile
));
5891 switch (attr
.dw_idx
)
5893 case DW_IDX_compile_unit
:
5894 /* Don't crash on bad data. */
5895 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5897 complaint (_(".debug_names entry has bad CU index %s"
5900 objfile_name (dwarf2_per_objfile
->objfile
));
5903 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5905 case DW_IDX_type_unit
:
5906 /* Don't crash on bad data. */
5907 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5909 complaint (_(".debug_names entry has bad TU index %s"
5912 objfile_name (dwarf2_per_objfile
->objfile
));
5915 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5917 case DW_IDX_GNU_internal
:
5918 if (!m_map
.augmentation_is_gdb
)
5920 symbol_linkage_
= symbol_linkage::static_
;
5922 case DW_IDX_GNU_external
:
5923 if (!m_map
.augmentation_is_gdb
)
5925 symbol_linkage_
= symbol_linkage::extern_
;
5930 /* Skip if already read in. */
5931 if (per_cu
->v
.quick
->compunit_symtab
)
5934 /* Check static vs global. */
5935 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5937 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5938 const bool symbol_is_static
=
5939 symbol_linkage_
== symbol_linkage::static_
;
5940 if (want_static
!= symbol_is_static
)
5944 /* Match dw2_symtab_iter_next, symbol_kind
5945 and debug_names::psymbol_tag. */
5949 switch (indexval
.dwarf_tag
)
5951 case DW_TAG_variable
:
5952 case DW_TAG_subprogram
:
5953 /* Some types are also in VAR_DOMAIN. */
5954 case DW_TAG_typedef
:
5955 case DW_TAG_structure_type
:
5962 switch (indexval
.dwarf_tag
)
5964 case DW_TAG_typedef
:
5965 case DW_TAG_structure_type
:
5972 switch (indexval
.dwarf_tag
)
5975 case DW_TAG_variable
:
5982 switch (indexval
.dwarf_tag
)
5994 /* Match dw2_expand_symtabs_matching, symbol_kind and
5995 debug_names::psymbol_tag. */
5998 case VARIABLES_DOMAIN
:
5999 switch (indexval
.dwarf_tag
)
6001 case DW_TAG_variable
:
6007 case FUNCTIONS_DOMAIN
:
6008 switch (indexval
.dwarf_tag
)
6010 case DW_TAG_subprogram
:
6017 switch (indexval
.dwarf_tag
)
6019 case DW_TAG_typedef
:
6020 case DW_TAG_structure_type
:
6026 case MODULES_DOMAIN
:
6027 switch (indexval
.dwarf_tag
)
6041 static struct compunit_symtab
*
6042 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
6043 const char *name
, domain_enum domain
)
6045 struct dwarf2_per_objfile
*dwarf2_per_objfile
6046 = get_dwarf2_per_objfile (objfile
);
6048 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6051 /* index is NULL if OBJF_READNOW. */
6054 const auto &map
= *mapp
;
6056 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
6058 struct compunit_symtab
*stab_best
= NULL
;
6059 struct dwarf2_per_cu_data
*per_cu
;
6060 while ((per_cu
= iter
.next ()) != NULL
)
6062 struct symbol
*sym
, *with_opaque
= NULL
;
6063 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6064 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6065 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6067 sym
= block_find_symbol (block
, name
, domain
,
6068 block_find_non_opaque_type_preferred
,
6071 /* Some caution must be observed with overloaded functions and
6072 methods, since the index will not contain any overload
6073 information (but NAME might contain it). */
6076 && strcmp_iw (sym
->search_name (), name
) == 0)
6078 if (with_opaque
!= NULL
6079 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
6082 /* Keep looking through other CUs. */
6088 /* This dumps minimal information about .debug_names. It is called
6089 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6090 uses this to verify that .debug_names has been loaded. */
6093 dw2_debug_names_dump (struct objfile
*objfile
)
6095 struct dwarf2_per_objfile
*dwarf2_per_objfile
6096 = get_dwarf2_per_objfile (objfile
);
6098 gdb_assert (dwarf2_per_objfile
->using_index
);
6099 printf_filtered (".debug_names:");
6100 if (dwarf2_per_objfile
->debug_names_table
)
6101 printf_filtered (" exists\n");
6103 printf_filtered (" faked for \"readnow\"\n");
6104 printf_filtered ("\n");
6108 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6109 const char *func_name
)
6111 struct dwarf2_per_objfile
*dwarf2_per_objfile
6112 = get_dwarf2_per_objfile (objfile
);
6114 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6115 if (dwarf2_per_objfile
->debug_names_table
)
6117 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6119 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
6121 struct dwarf2_per_cu_data
*per_cu
;
6122 while ((per_cu
= iter
.next ()) != NULL
)
6123 dw2_instantiate_symtab (per_cu
, false);
6128 dw2_debug_names_map_matching_symbols
6129 (struct objfile
*objfile
,
6130 const lookup_name_info
&name
, domain_enum domain
,
6132 gdb::function_view
<symbol_found_callback_ftype
> callback
,
6133 symbol_compare_ftype
*ordered_compare
)
6135 struct dwarf2_per_objfile
*dwarf2_per_objfile
6136 = get_dwarf2_per_objfile (objfile
);
6138 /* debug_names_table is NULL if OBJF_READNOW. */
6139 if (!dwarf2_per_objfile
->debug_names_table
)
6142 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6143 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
6145 const char *match_name
= name
.ada ().lookup_name ().c_str ();
6146 auto matcher
= [&] (const char *symname
)
6148 if (ordered_compare
== nullptr)
6150 return ordered_compare (symname
, match_name
) == 0;
6153 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
6154 [&] (offset_type namei
)
6156 /* The name was matched, now expand corresponding CUs that were
6158 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
6160 struct dwarf2_per_cu_data
*per_cu
;
6161 while ((per_cu
= iter
.next ()) != NULL
)
6162 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
6166 /* It's a shame we couldn't do this inside the
6167 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
6168 that have already been expanded. Instead, this loop matches what
6169 the psymtab code does. */
6170 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
6172 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
6173 if (cust
!= nullptr)
6175 const struct block
*block
6176 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
6177 if (!iterate_over_symbols_terminated (block
, name
,
6185 dw2_debug_names_expand_symtabs_matching
6186 (struct objfile
*objfile
,
6187 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6188 const lookup_name_info
&lookup_name
,
6189 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6190 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6191 enum search_domain kind
)
6193 struct dwarf2_per_objfile
*dwarf2_per_objfile
6194 = get_dwarf2_per_objfile (objfile
);
6196 /* debug_names_table is NULL if OBJF_READNOW. */
6197 if (!dwarf2_per_objfile
->debug_names_table
)
6200 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6202 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6204 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6206 kind
, [&] (offset_type namei
)
6208 /* The name was matched, now expand corresponding CUs that were
6210 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6212 struct dwarf2_per_cu_data
*per_cu
;
6213 while ((per_cu
= iter
.next ()) != NULL
)
6214 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6220 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6223 dw2_find_last_source_symtab
,
6224 dw2_forget_cached_source_info
,
6225 dw2_map_symtabs_matching_filename
,
6226 dw2_debug_names_lookup_symbol
,
6228 dw2_debug_names_dump
,
6229 dw2_debug_names_expand_symtabs_for_function
,
6230 dw2_expand_all_symtabs
,
6231 dw2_expand_symtabs_with_fullname
,
6232 dw2_debug_names_map_matching_symbols
,
6233 dw2_debug_names_expand_symtabs_matching
,
6234 dw2_find_pc_sect_compunit_symtab
,
6236 dw2_map_symbol_filenames
6239 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6240 to either a dwarf2_per_objfile or dwz_file object. */
6242 template <typename T
>
6243 static gdb::array_view
<const gdb_byte
>
6244 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6246 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6248 if (dwarf2_section_empty_p (section
))
6251 /* Older elfutils strip versions could keep the section in the main
6252 executable while splitting it for the separate debug info file. */
6253 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
6256 dwarf2_read_section (obj
, section
);
6258 /* dwarf2_section_info::size is a bfd_size_type, while
6259 gdb::array_view works with size_t. On 32-bit hosts, with
6260 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6261 is 32-bit. So we need an explicit narrowing conversion here.
6262 This is fine, because it's impossible to allocate or mmap an
6263 array/buffer larger than what size_t can represent. */
6264 return gdb::make_array_view (section
->buffer
, section
->size
);
6267 /* Lookup the index cache for the contents of the index associated to
6270 static gdb::array_view
<const gdb_byte
>
6271 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6273 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6274 if (build_id
== nullptr)
6277 return global_index_cache
.lookup_gdb_index (build_id
,
6278 &dwarf2_obj
->index_cache_res
);
6281 /* Same as the above, but for DWZ. */
6283 static gdb::array_view
<const gdb_byte
>
6284 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6286 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6287 if (build_id
== nullptr)
6290 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6293 /* See symfile.h. */
6296 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6298 struct dwarf2_per_objfile
*dwarf2_per_objfile
6299 = get_dwarf2_per_objfile (objfile
);
6301 /* If we're about to read full symbols, don't bother with the
6302 indices. In this case we also don't care if some other debug
6303 format is making psymtabs, because they are all about to be
6305 if ((objfile
->flags
& OBJF_READNOW
))
6307 dwarf2_per_objfile
->using_index
= 1;
6308 create_all_comp_units (dwarf2_per_objfile
);
6309 create_all_type_units (dwarf2_per_objfile
);
6310 dwarf2_per_objfile
->quick_file_names_table
6311 = create_quick_file_names_table
6312 (dwarf2_per_objfile
->all_comp_units
.size ());
6314 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6315 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6317 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6319 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6320 struct dwarf2_per_cu_quick_data
);
6323 /* Return 1 so that gdb sees the "quick" functions. However,
6324 these functions will be no-ops because we will have expanded
6326 *index_kind
= dw_index_kind::GDB_INDEX
;
6330 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6332 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6336 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6337 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6338 get_gdb_index_contents_from_section
<dwz_file
>))
6340 *index_kind
= dw_index_kind::GDB_INDEX
;
6344 /* ... otherwise, try to find the index in the index cache. */
6345 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6346 get_gdb_index_contents_from_cache
,
6347 get_gdb_index_contents_from_cache_dwz
))
6349 global_index_cache
.hit ();
6350 *index_kind
= dw_index_kind::GDB_INDEX
;
6354 global_index_cache
.miss ();
6360 /* Build a partial symbol table. */
6363 dwarf2_build_psymtabs (struct objfile
*objfile
)
6365 struct dwarf2_per_objfile
*dwarf2_per_objfile
6366 = get_dwarf2_per_objfile (objfile
);
6368 init_psymbol_list (objfile
, 1024);
6372 /* This isn't really ideal: all the data we allocate on the
6373 objfile's obstack is still uselessly kept around. However,
6374 freeing it seems unsafe. */
6375 psymtab_discarder
psymtabs (objfile
);
6376 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6379 /* (maybe) store an index in the cache. */
6380 global_index_cache
.store (dwarf2_per_objfile
);
6382 catch (const gdb_exception_error
&except
)
6384 exception_print (gdb_stderr
, except
);
6388 /* Return the total length of the CU described by HEADER. */
6391 get_cu_length (const struct comp_unit_head
*header
)
6393 return header
->initial_length_size
+ header
->length
;
6396 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6399 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6401 sect_offset bottom
= cu_header
->sect_off
;
6402 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6404 return sect_off
>= bottom
&& sect_off
< top
;
6407 /* Find the base address of the compilation unit for range lists and
6408 location lists. It will normally be specified by DW_AT_low_pc.
6409 In DWARF-3 draft 4, the base address could be overridden by
6410 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6411 compilation units with discontinuous ranges. */
6414 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6416 struct attribute
*attr
;
6419 cu
->base_address
= 0;
6421 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6422 if (attr
!= nullptr)
6424 cu
->base_address
= attr_value_as_address (attr
);
6429 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6430 if (attr
!= nullptr)
6432 cu
->base_address
= attr_value_as_address (attr
);
6438 /* Read in the comp unit header information from the debug_info at info_ptr.
6439 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6440 NOTE: This leaves members offset, first_die_offset to be filled in
6443 static const gdb_byte
*
6444 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6445 const gdb_byte
*info_ptr
,
6446 struct dwarf2_section_info
*section
,
6447 rcuh_kind section_kind
)
6450 unsigned int bytes_read
;
6451 const char *filename
= get_section_file_name (section
);
6452 bfd
*abfd
= get_section_bfd_owner (section
);
6454 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6455 cu_header
->initial_length_size
= bytes_read
;
6456 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6457 info_ptr
+= bytes_read
;
6458 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6459 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6460 error (_("Dwarf Error: wrong version in compilation unit header "
6461 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6462 cu_header
->version
, filename
);
6464 if (cu_header
->version
< 5)
6465 switch (section_kind
)
6467 case rcuh_kind::COMPILE
:
6468 cu_header
->unit_type
= DW_UT_compile
;
6470 case rcuh_kind::TYPE
:
6471 cu_header
->unit_type
= DW_UT_type
;
6474 internal_error (__FILE__
, __LINE__
,
6475 _("read_comp_unit_head: invalid section_kind"));
6479 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6480 (read_1_byte (abfd
, info_ptr
));
6482 switch (cu_header
->unit_type
)
6486 case DW_UT_skeleton
:
6487 case DW_UT_split_compile
:
6488 if (section_kind
!= rcuh_kind::COMPILE
)
6489 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6490 "(is %s, should be %s) [in module %s]"),
6491 dwarf_unit_type_name (cu_header
->unit_type
),
6492 dwarf_unit_type_name (DW_UT_type
), filename
);
6495 case DW_UT_split_type
:
6496 section_kind
= rcuh_kind::TYPE
;
6499 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6500 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6501 "[in module %s]"), cu_header
->unit_type
,
6502 dwarf_unit_type_name (DW_UT_compile
),
6503 dwarf_unit_type_name (DW_UT_skeleton
),
6504 dwarf_unit_type_name (DW_UT_split_compile
),
6505 dwarf_unit_type_name (DW_UT_type
),
6506 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6509 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6512 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6515 info_ptr
+= bytes_read
;
6516 if (cu_header
->version
< 5)
6518 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6521 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6522 if (signed_addr
< 0)
6523 internal_error (__FILE__
, __LINE__
,
6524 _("read_comp_unit_head: dwarf from non elf file"));
6525 cu_header
->signed_addr_p
= signed_addr
;
6527 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6528 || cu_header
->unit_type
== DW_UT_skeleton
6529 || cu_header
->unit_type
== DW_UT_split_compile
;
6531 if (header_has_signature
)
6533 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6537 if (section_kind
== rcuh_kind::TYPE
)
6539 LONGEST type_offset
;
6540 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6541 info_ptr
+= bytes_read
;
6542 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6543 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6544 error (_("Dwarf Error: Too big type_offset in compilation unit "
6545 "header (is %s) [in module %s]"), plongest (type_offset
),
6552 /* Helper function that returns the proper abbrev section for
6555 static struct dwarf2_section_info
*
6556 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6558 struct dwarf2_section_info
*abbrev
;
6559 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6561 if (this_cu
->is_dwz
)
6562 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6564 abbrev
= &dwarf2_per_objfile
->abbrev
;
6569 /* Subroutine of read_and_check_comp_unit_head and
6570 read_and_check_type_unit_head to simplify them.
6571 Perform various error checking on the header. */
6574 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6575 struct comp_unit_head
*header
,
6576 struct dwarf2_section_info
*section
,
6577 struct dwarf2_section_info
*abbrev_section
)
6579 const char *filename
= get_section_file_name (section
);
6581 if (to_underlying (header
->abbrev_sect_off
)
6582 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6583 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6584 "(offset %s + 6) [in module %s]"),
6585 sect_offset_str (header
->abbrev_sect_off
),
6586 sect_offset_str (header
->sect_off
),
6589 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6590 avoid potential 32-bit overflow. */
6591 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6593 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6594 "(offset %s + 0) [in module %s]"),
6595 header
->length
, sect_offset_str (header
->sect_off
),
6599 /* Read in a CU/TU header and perform some basic error checking.
6600 The contents of the header are stored in HEADER.
6601 The result is a pointer to the start of the first DIE. */
6603 static const gdb_byte
*
6604 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6605 struct comp_unit_head
*header
,
6606 struct dwarf2_section_info
*section
,
6607 struct dwarf2_section_info
*abbrev_section
,
6608 const gdb_byte
*info_ptr
,
6609 rcuh_kind section_kind
)
6611 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6613 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6615 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6617 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6619 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6625 /* Fetch the abbreviation table offset from a comp or type unit header. */
6628 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6629 struct dwarf2_section_info
*section
,
6630 sect_offset sect_off
)
6632 bfd
*abfd
= get_section_bfd_owner (section
);
6633 const gdb_byte
*info_ptr
;
6634 unsigned int initial_length_size
, offset_size
;
6637 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6638 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6639 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6640 offset_size
= initial_length_size
== 4 ? 4 : 8;
6641 info_ptr
+= initial_length_size
;
6643 version
= read_2_bytes (abfd
, info_ptr
);
6647 /* Skip unit type and address size. */
6651 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6654 /* Allocate a new partial symtab for file named NAME and mark this new
6655 partial symtab as being an include of PST. */
6658 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6659 struct objfile
*objfile
)
6661 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6663 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6665 /* It shares objfile->objfile_obstack. */
6666 subpst
->dirname
= pst
->dirname
;
6669 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6670 subpst
->dependencies
[0] = pst
;
6671 subpst
->number_of_dependencies
= 1;
6673 subpst
->read_symtab
= pst
->read_symtab
;
6675 /* No private part is necessary for include psymtabs. This property
6676 can be used to differentiate between such include psymtabs and
6677 the regular ones. */
6678 subpst
->read_symtab_private
= NULL
;
6681 /* Read the Line Number Program data and extract the list of files
6682 included by the source file represented by PST. Build an include
6683 partial symtab for each of these included files. */
6686 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6687 struct die_info
*die
,
6688 struct partial_symtab
*pst
)
6691 struct attribute
*attr
;
6693 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6694 if (attr
!= nullptr)
6695 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6697 return; /* No linetable, so no includes. */
6699 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6700 that we pass in the raw text_low here; that is ok because we're
6701 only decoding the line table to make include partial symtabs, and
6702 so the addresses aren't really used. */
6703 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6704 pst
->raw_text_low (), 1);
6708 hash_signatured_type (const void *item
)
6710 const struct signatured_type
*sig_type
6711 = (const struct signatured_type
*) item
;
6713 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6714 return sig_type
->signature
;
6718 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6720 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6721 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6723 return lhs
->signature
== rhs
->signature
;
6726 /* Allocate a hash table for signatured types. */
6729 allocate_signatured_type_table (struct objfile
*objfile
)
6731 return htab_create_alloc_ex (41,
6732 hash_signatured_type
,
6735 &objfile
->objfile_obstack
,
6736 hashtab_obstack_allocate
,
6737 dummy_obstack_deallocate
);
6740 /* A helper function to add a signatured type CU to a table. */
6743 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6745 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6746 std::vector
<signatured_type
*> *all_type_units
6747 = (std::vector
<signatured_type
*> *) datum
;
6749 all_type_units
->push_back (sigt
);
6754 /* A helper for create_debug_types_hash_table. Read types from SECTION
6755 and fill them into TYPES_HTAB. It will process only type units,
6756 therefore DW_UT_type. */
6759 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6760 struct dwo_file
*dwo_file
,
6761 dwarf2_section_info
*section
, htab_t
&types_htab
,
6762 rcuh_kind section_kind
)
6764 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6765 struct dwarf2_section_info
*abbrev_section
;
6767 const gdb_byte
*info_ptr
, *end_ptr
;
6769 abbrev_section
= (dwo_file
!= NULL
6770 ? &dwo_file
->sections
.abbrev
6771 : &dwarf2_per_objfile
->abbrev
);
6773 if (dwarf_read_debug
)
6774 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6775 get_section_name (section
),
6776 get_section_file_name (abbrev_section
));
6778 dwarf2_read_section (objfile
, section
);
6779 info_ptr
= section
->buffer
;
6781 if (info_ptr
== NULL
)
6784 /* We can't set abfd until now because the section may be empty or
6785 not present, in which case the bfd is unknown. */
6786 abfd
= get_section_bfd_owner (section
);
6788 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6789 because we don't need to read any dies: the signature is in the
6792 end_ptr
= info_ptr
+ section
->size
;
6793 while (info_ptr
< end_ptr
)
6795 struct signatured_type
*sig_type
;
6796 struct dwo_unit
*dwo_tu
;
6798 const gdb_byte
*ptr
= info_ptr
;
6799 struct comp_unit_head header
;
6800 unsigned int length
;
6802 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6804 /* Initialize it due to a false compiler warning. */
6805 header
.signature
= -1;
6806 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6808 /* We need to read the type's signature in order to build the hash
6809 table, but we don't need anything else just yet. */
6811 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6812 abbrev_section
, ptr
, section_kind
);
6814 length
= get_cu_length (&header
);
6816 /* Skip dummy type units. */
6817 if (ptr
>= info_ptr
+ length
6818 || peek_abbrev_code (abfd
, ptr
) == 0
6819 || header
.unit_type
!= DW_UT_type
)
6825 if (types_htab
== NULL
)
6828 types_htab
= allocate_dwo_unit_table (objfile
);
6830 types_htab
= allocate_signatured_type_table (objfile
);
6836 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6838 dwo_tu
->dwo_file
= dwo_file
;
6839 dwo_tu
->signature
= header
.signature
;
6840 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6841 dwo_tu
->section
= section
;
6842 dwo_tu
->sect_off
= sect_off
;
6843 dwo_tu
->length
= length
;
6847 /* N.B.: type_offset is not usable if this type uses a DWO file.
6848 The real type_offset is in the DWO file. */
6850 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6851 struct signatured_type
);
6852 sig_type
->signature
= header
.signature
;
6853 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6854 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6855 sig_type
->per_cu
.is_debug_types
= 1;
6856 sig_type
->per_cu
.section
= section
;
6857 sig_type
->per_cu
.sect_off
= sect_off
;
6858 sig_type
->per_cu
.length
= length
;
6861 slot
= htab_find_slot (types_htab
,
6862 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6864 gdb_assert (slot
!= NULL
);
6867 sect_offset dup_sect_off
;
6871 const struct dwo_unit
*dup_tu
6872 = (const struct dwo_unit
*) *slot
;
6874 dup_sect_off
= dup_tu
->sect_off
;
6878 const struct signatured_type
*dup_tu
6879 = (const struct signatured_type
*) *slot
;
6881 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6884 complaint (_("debug type entry at offset %s is duplicate to"
6885 " the entry at offset %s, signature %s"),
6886 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6887 hex_string (header
.signature
));
6889 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6891 if (dwarf_read_debug
> 1)
6892 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6893 sect_offset_str (sect_off
),
6894 hex_string (header
.signature
));
6900 /* Create the hash table of all entries in the .debug_types
6901 (or .debug_types.dwo) section(s).
6902 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6903 otherwise it is NULL.
6905 The result is a pointer to the hash table or NULL if there are no types.
6907 Note: This function processes DWO files only, not DWP files. */
6910 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6911 struct dwo_file
*dwo_file
,
6912 gdb::array_view
<dwarf2_section_info
> type_sections
,
6915 for (dwarf2_section_info
§ion
: type_sections
)
6916 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6917 types_htab
, rcuh_kind::TYPE
);
6920 /* Create the hash table of all entries in the .debug_types section,
6921 and initialize all_type_units.
6922 The result is zero if there is an error (e.g. missing .debug_types section),
6923 otherwise non-zero. */
6926 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6928 htab_t types_htab
= NULL
;
6930 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6931 &dwarf2_per_objfile
->info
, types_htab
,
6932 rcuh_kind::COMPILE
);
6933 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6934 dwarf2_per_objfile
->types
, types_htab
);
6935 if (types_htab
== NULL
)
6937 dwarf2_per_objfile
->signatured_types
= NULL
;
6941 dwarf2_per_objfile
->signatured_types
= types_htab
;
6943 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6944 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6946 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6947 &dwarf2_per_objfile
->all_type_units
);
6952 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6953 If SLOT is non-NULL, it is the entry to use in the hash table.
6954 Otherwise we find one. */
6956 static struct signatured_type
*
6957 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6960 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6962 if (dwarf2_per_objfile
->all_type_units
.size ()
6963 == dwarf2_per_objfile
->all_type_units
.capacity ())
6964 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6966 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6967 struct signatured_type
);
6969 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6970 sig_type
->signature
= sig
;
6971 sig_type
->per_cu
.is_debug_types
= 1;
6972 if (dwarf2_per_objfile
->using_index
)
6974 sig_type
->per_cu
.v
.quick
=
6975 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6976 struct dwarf2_per_cu_quick_data
);
6981 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6984 gdb_assert (*slot
== NULL
);
6986 /* The rest of sig_type must be filled in by the caller. */
6990 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6991 Fill in SIG_ENTRY with DWO_ENTRY. */
6994 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6995 struct signatured_type
*sig_entry
,
6996 struct dwo_unit
*dwo_entry
)
6998 /* Make sure we're not clobbering something we don't expect to. */
6999 gdb_assert (! sig_entry
->per_cu
.queued
);
7000 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
7001 if (dwarf2_per_objfile
->using_index
)
7003 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
7004 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
7007 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7008 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7009 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7010 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7011 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7013 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7014 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7015 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7016 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7017 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7018 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7019 sig_entry
->dwo_unit
= dwo_entry
;
7022 /* Subroutine of lookup_signatured_type.
7023 If we haven't read the TU yet, create the signatured_type data structure
7024 for a TU to be read in directly from a DWO file, bypassing the stub.
7025 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7026 using .gdb_index, then when reading a CU we want to stay in the DWO file
7027 containing that CU. Otherwise we could end up reading several other DWO
7028 files (due to comdat folding) to process the transitive closure of all the
7029 mentioned TUs, and that can be slow. The current DWO file will have every
7030 type signature that it needs.
7031 We only do this for .gdb_index because in the psymtab case we already have
7032 to read all the DWOs to build the type unit groups. */
7034 static struct signatured_type
*
7035 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7037 struct dwarf2_per_objfile
*dwarf2_per_objfile
7038 = cu
->per_cu
->dwarf2_per_objfile
;
7039 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7040 struct dwo_file
*dwo_file
;
7041 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7042 struct signatured_type find_sig_entry
, *sig_entry
;
7045 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7047 /* If TU skeletons have been removed then we may not have read in any
7049 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7051 dwarf2_per_objfile
->signatured_types
7052 = allocate_signatured_type_table (objfile
);
7055 /* We only ever need to read in one copy of a signatured type.
7056 Use the global signatured_types array to do our own comdat-folding
7057 of types. If this is the first time we're reading this TU, and
7058 the TU has an entry in .gdb_index, replace the recorded data from
7059 .gdb_index with this TU. */
7061 find_sig_entry
.signature
= sig
;
7062 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7063 &find_sig_entry
, INSERT
);
7064 sig_entry
= (struct signatured_type
*) *slot
;
7066 /* We can get here with the TU already read, *or* in the process of being
7067 read. Don't reassign the global entry to point to this DWO if that's
7068 the case. Also note that if the TU is already being read, it may not
7069 have come from a DWO, the program may be a mix of Fission-compiled
7070 code and non-Fission-compiled code. */
7072 /* Have we already tried to read this TU?
7073 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7074 needn't exist in the global table yet). */
7075 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7078 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7079 dwo_unit of the TU itself. */
7080 dwo_file
= cu
->dwo_unit
->dwo_file
;
7082 /* Ok, this is the first time we're reading this TU. */
7083 if (dwo_file
->tus
== NULL
)
7085 find_dwo_entry
.signature
= sig
;
7086 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7087 if (dwo_entry
== NULL
)
7090 /* If the global table doesn't have an entry for this TU, add one. */
7091 if (sig_entry
== NULL
)
7092 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7094 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7095 sig_entry
->per_cu
.tu_read
= 1;
7099 /* Subroutine of lookup_signatured_type.
7100 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7101 then try the DWP file. If the TU stub (skeleton) has been removed then
7102 it won't be in .gdb_index. */
7104 static struct signatured_type
*
7105 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7107 struct dwarf2_per_objfile
*dwarf2_per_objfile
7108 = cu
->per_cu
->dwarf2_per_objfile
;
7109 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7110 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7111 struct dwo_unit
*dwo_entry
;
7112 struct signatured_type find_sig_entry
, *sig_entry
;
7115 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7116 gdb_assert (dwp_file
!= NULL
);
7118 /* If TU skeletons have been removed then we may not have read in any
7120 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7122 dwarf2_per_objfile
->signatured_types
7123 = allocate_signatured_type_table (objfile
);
7126 find_sig_entry
.signature
= sig
;
7127 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7128 &find_sig_entry
, INSERT
);
7129 sig_entry
= (struct signatured_type
*) *slot
;
7131 /* Have we already tried to read this TU?
7132 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7133 needn't exist in the global table yet). */
7134 if (sig_entry
!= NULL
)
7137 if (dwp_file
->tus
== NULL
)
7139 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7140 sig
, 1 /* is_debug_types */);
7141 if (dwo_entry
== NULL
)
7144 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7145 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7150 /* Lookup a signature based type for DW_FORM_ref_sig8.
7151 Returns NULL if signature SIG is not present in the table.
7152 It is up to the caller to complain about this. */
7154 static struct signatured_type
*
7155 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7157 struct dwarf2_per_objfile
*dwarf2_per_objfile
7158 = cu
->per_cu
->dwarf2_per_objfile
;
7161 && dwarf2_per_objfile
->using_index
)
7163 /* We're in a DWO/DWP file, and we're using .gdb_index.
7164 These cases require special processing. */
7165 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7166 return lookup_dwo_signatured_type (cu
, sig
);
7168 return lookup_dwp_signatured_type (cu
, sig
);
7172 struct signatured_type find_entry
, *entry
;
7174 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7176 find_entry
.signature
= sig
;
7177 entry
= ((struct signatured_type
*)
7178 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7183 /* Low level DIE reading support. */
7185 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7188 init_cu_die_reader (struct die_reader_specs
*reader
,
7189 struct dwarf2_cu
*cu
,
7190 struct dwarf2_section_info
*section
,
7191 struct dwo_file
*dwo_file
,
7192 struct abbrev_table
*abbrev_table
)
7194 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7195 reader
->abfd
= get_section_bfd_owner (section
);
7197 reader
->dwo_file
= dwo_file
;
7198 reader
->die_section
= section
;
7199 reader
->buffer
= section
->buffer
;
7200 reader
->buffer_end
= section
->buffer
+ section
->size
;
7201 reader
->comp_dir
= NULL
;
7202 reader
->abbrev_table
= abbrev_table
;
7205 /* Subroutine of init_cutu_and_read_dies to simplify it.
7206 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7207 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7210 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7211 from it to the DIE in the DWO. If NULL we are skipping the stub.
7212 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7213 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7214 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7215 STUB_COMP_DIR may be non-NULL.
7216 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7217 are filled in with the info of the DIE from the DWO file.
7218 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7219 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7220 kept around for at least as long as *RESULT_READER.
7222 The result is non-zero if a valid (non-dummy) DIE was found. */
7225 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7226 struct dwo_unit
*dwo_unit
,
7227 struct die_info
*stub_comp_unit_die
,
7228 const char *stub_comp_dir
,
7229 struct die_reader_specs
*result_reader
,
7230 const gdb_byte
**result_info_ptr
,
7231 struct die_info
**result_comp_unit_die
,
7232 int *result_has_children
,
7233 abbrev_table_up
*result_dwo_abbrev_table
)
7235 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7236 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7237 struct dwarf2_cu
*cu
= this_cu
->cu
;
7239 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7240 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7241 int i
,num_extra_attrs
;
7242 struct dwarf2_section_info
*dwo_abbrev_section
;
7243 struct attribute
*attr
;
7244 struct die_info
*comp_unit_die
;
7246 /* At most one of these may be provided. */
7247 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7249 /* These attributes aren't processed until later:
7250 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7251 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7252 referenced later. However, these attributes are found in the stub
7253 which we won't have later. In order to not impose this complication
7254 on the rest of the code, we read them here and copy them to the
7263 if (stub_comp_unit_die
!= NULL
)
7265 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7267 if (! this_cu
->is_debug_types
)
7268 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7269 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7270 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7271 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7272 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7274 /* There should be a DW_AT_addr_base attribute here (if needed).
7275 We need the value before we can process DW_FORM_GNU_addr_index
7276 or DW_FORM_addrx. */
7278 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7279 if (attr
!= nullptr)
7280 cu
->addr_base
= DW_UNSND (attr
);
7282 /* There should be a DW_AT_ranges_base attribute here (if needed).
7283 We need the value before we can process DW_AT_ranges. */
7284 cu
->ranges_base
= 0;
7285 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7286 if (attr
!= nullptr)
7287 cu
->ranges_base
= DW_UNSND (attr
);
7289 else if (stub_comp_dir
!= NULL
)
7291 /* Reconstruct the comp_dir attribute to simplify the code below. */
7292 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7293 comp_dir
->name
= DW_AT_comp_dir
;
7294 comp_dir
->form
= DW_FORM_string
;
7295 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7296 DW_STRING (comp_dir
) = stub_comp_dir
;
7299 /* Set up for reading the DWO CU/TU. */
7300 cu
->dwo_unit
= dwo_unit
;
7301 dwarf2_section_info
*section
= dwo_unit
->section
;
7302 dwarf2_read_section (objfile
, section
);
7303 abfd
= get_section_bfd_owner (section
);
7304 begin_info_ptr
= info_ptr
= (section
->buffer
7305 + to_underlying (dwo_unit
->sect_off
));
7306 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7308 if (this_cu
->is_debug_types
)
7310 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7312 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7313 &cu
->header
, section
,
7315 info_ptr
, rcuh_kind::TYPE
);
7316 /* This is not an assert because it can be caused by bad debug info. */
7317 if (sig_type
->signature
!= cu
->header
.signature
)
7319 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7320 " TU at offset %s [in module %s]"),
7321 hex_string (sig_type
->signature
),
7322 hex_string (cu
->header
.signature
),
7323 sect_offset_str (dwo_unit
->sect_off
),
7324 bfd_get_filename (abfd
));
7326 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7327 /* For DWOs coming from DWP files, we don't know the CU length
7328 nor the type's offset in the TU until now. */
7329 dwo_unit
->length
= get_cu_length (&cu
->header
);
7330 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7332 /* Establish the type offset that can be used to lookup the type.
7333 For DWO files, we don't know it until now. */
7334 sig_type
->type_offset_in_section
7335 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7339 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7340 &cu
->header
, section
,
7342 info_ptr
, rcuh_kind::COMPILE
);
7343 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7344 /* For DWOs coming from DWP files, we don't know the CU length
7346 dwo_unit
->length
= get_cu_length (&cu
->header
);
7349 *result_dwo_abbrev_table
7350 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7351 cu
->header
.abbrev_sect_off
);
7352 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7353 result_dwo_abbrev_table
->get ());
7355 /* Read in the die, but leave space to copy over the attributes
7356 from the stub. This has the benefit of simplifying the rest of
7357 the code - all the work to maintain the illusion of a single
7358 DW_TAG_{compile,type}_unit DIE is done here. */
7359 num_extra_attrs
= ((stmt_list
!= NULL
)
7363 + (comp_dir
!= NULL
));
7364 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7365 result_has_children
, num_extra_attrs
);
7367 /* Copy over the attributes from the stub to the DIE we just read in. */
7368 comp_unit_die
= *result_comp_unit_die
;
7369 i
= comp_unit_die
->num_attrs
;
7370 if (stmt_list
!= NULL
)
7371 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7373 comp_unit_die
->attrs
[i
++] = *low_pc
;
7374 if (high_pc
!= NULL
)
7375 comp_unit_die
->attrs
[i
++] = *high_pc
;
7377 comp_unit_die
->attrs
[i
++] = *ranges
;
7378 if (comp_dir
!= NULL
)
7379 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7380 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7382 if (dwarf_die_debug
)
7384 fprintf_unfiltered (gdb_stdlog
,
7385 "Read die from %s@0x%x of %s:\n",
7386 get_section_name (section
),
7387 (unsigned) (begin_info_ptr
- section
->buffer
),
7388 bfd_get_filename (abfd
));
7389 dump_die (comp_unit_die
, dwarf_die_debug
);
7392 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7393 TUs by skipping the stub and going directly to the entry in the DWO file.
7394 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7395 to get it via circuitous means. Blech. */
7396 if (comp_dir
!= NULL
)
7397 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7399 /* Skip dummy compilation units. */
7400 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7401 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7404 *result_info_ptr
= info_ptr
;
7408 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7409 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7410 signature is part of the header. */
7411 static gdb::optional
<ULONGEST
>
7412 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7414 if (cu
->header
.version
>= 5)
7415 return cu
->header
.signature
;
7416 struct attribute
*attr
;
7417 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7418 if (attr
== nullptr)
7419 return gdb::optional
<ULONGEST
> ();
7420 return DW_UNSND (attr
);
7423 /* Subroutine of init_cutu_and_read_dies to simplify it.
7424 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7425 Returns NULL if the specified DWO unit cannot be found. */
7427 static struct dwo_unit
*
7428 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7429 struct die_info
*comp_unit_die
)
7431 struct dwarf2_cu
*cu
= this_cu
->cu
;
7432 struct dwo_unit
*dwo_unit
;
7433 const char *comp_dir
, *dwo_name
;
7435 gdb_assert (cu
!= NULL
);
7437 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7438 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7439 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7441 if (this_cu
->is_debug_types
)
7443 struct signatured_type
*sig_type
;
7445 /* Since this_cu is the first member of struct signatured_type,
7446 we can go from a pointer to one to a pointer to the other. */
7447 sig_type
= (struct signatured_type
*) this_cu
;
7448 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7452 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7453 if (!signature
.has_value ())
7454 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7456 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7457 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7464 /* Subroutine of init_cutu_and_read_dies to simplify it.
7465 See it for a description of the parameters.
7466 Read a TU directly from a DWO file, bypassing the stub. */
7469 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7470 int use_existing_cu
, int keep
,
7471 die_reader_func_ftype
*die_reader_func
,
7474 std::unique_ptr
<dwarf2_cu
> new_cu
;
7475 struct signatured_type
*sig_type
;
7476 struct die_reader_specs reader
;
7477 const gdb_byte
*info_ptr
;
7478 struct die_info
*comp_unit_die
;
7480 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7482 /* Verify we can do the following downcast, and that we have the
7484 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7485 sig_type
= (struct signatured_type
*) this_cu
;
7486 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7488 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7490 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7491 /* There's no need to do the rereading_dwo_cu handling that
7492 init_cutu_and_read_dies does since we don't read the stub. */
7496 /* If !use_existing_cu, this_cu->cu must be NULL. */
7497 gdb_assert (this_cu
->cu
== NULL
);
7498 new_cu
.reset (new dwarf2_cu (this_cu
));
7501 /* A future optimization, if needed, would be to use an existing
7502 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7503 could share abbrev tables. */
7505 /* The abbreviation table used by READER, this must live at least as long as
7507 abbrev_table_up dwo_abbrev_table
;
7509 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7510 NULL
/* stub_comp_unit_die */,
7511 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7513 &comp_unit_die
, &has_children
,
7514 &dwo_abbrev_table
) == 0)
7520 /* All the "real" work is done here. */
7521 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7523 /* This duplicates the code in init_cutu_and_read_dies,
7524 but the alternative is making the latter more complex.
7525 This function is only for the special case of using DWO files directly:
7526 no point in overly complicating the general case just to handle this. */
7527 if (new_cu
!= NULL
&& keep
)
7529 /* Link this CU into read_in_chain. */
7530 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7531 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7532 /* The chain owns it now. */
7537 /* Initialize a CU (or TU) and read its DIEs.
7538 If the CU defers to a DWO file, read the DWO file as well.
7540 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7541 Otherwise the table specified in the comp unit header is read in and used.
7542 This is an optimization for when we already have the abbrev table.
7544 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7545 Otherwise, a new CU is allocated with xmalloc.
7547 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7548 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7550 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7551 linker) then DIE_READER_FUNC will not get called. */
7554 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7555 struct abbrev_table
*abbrev_table
,
7556 int use_existing_cu
, int keep
,
7558 die_reader_func_ftype
*die_reader_func
,
7561 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7562 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7563 struct dwarf2_section_info
*section
= this_cu
->section
;
7564 bfd
*abfd
= get_section_bfd_owner (section
);
7565 struct dwarf2_cu
*cu
;
7566 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7567 struct die_reader_specs reader
;
7568 struct die_info
*comp_unit_die
;
7570 struct signatured_type
*sig_type
= NULL
;
7571 struct dwarf2_section_info
*abbrev_section
;
7572 /* Non-zero if CU currently points to a DWO file and we need to
7573 reread it. When this happens we need to reread the skeleton die
7574 before we can reread the DWO file (this only applies to CUs, not TUs). */
7575 int rereading_dwo_cu
= 0;
7577 if (dwarf_die_debug
)
7578 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7579 this_cu
->is_debug_types
? "type" : "comp",
7580 sect_offset_str (this_cu
->sect_off
));
7582 if (use_existing_cu
)
7585 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7586 file (instead of going through the stub), short-circuit all of this. */
7587 if (this_cu
->reading_dwo_directly
)
7589 /* Narrow down the scope of possibilities to have to understand. */
7590 gdb_assert (this_cu
->is_debug_types
);
7591 gdb_assert (abbrev_table
== NULL
);
7592 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7593 die_reader_func
, data
);
7597 /* This is cheap if the section is already read in. */
7598 dwarf2_read_section (objfile
, section
);
7600 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7602 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7604 std::unique_ptr
<dwarf2_cu
> new_cu
;
7605 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7608 /* If this CU is from a DWO file we need to start over, we need to
7609 refetch the attributes from the skeleton CU.
7610 This could be optimized by retrieving those attributes from when we
7611 were here the first time: the previous comp_unit_die was stored in
7612 comp_unit_obstack. But there's no data yet that we need this
7614 if (cu
->dwo_unit
!= NULL
)
7615 rereading_dwo_cu
= 1;
7619 /* If !use_existing_cu, this_cu->cu must be NULL. */
7620 gdb_assert (this_cu
->cu
== NULL
);
7621 new_cu
.reset (new dwarf2_cu (this_cu
));
7625 /* Get the header. */
7626 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7628 /* We already have the header, there's no need to read it in again. */
7629 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7633 if (this_cu
->is_debug_types
)
7635 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7636 &cu
->header
, section
,
7637 abbrev_section
, info_ptr
,
7640 /* Since per_cu is the first member of struct signatured_type,
7641 we can go from a pointer to one to a pointer to the other. */
7642 sig_type
= (struct signatured_type
*) this_cu
;
7643 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7644 gdb_assert (sig_type
->type_offset_in_tu
7645 == cu
->header
.type_cu_offset_in_tu
);
7646 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7648 /* LENGTH has not been set yet for type units if we're
7649 using .gdb_index. */
7650 this_cu
->length
= get_cu_length (&cu
->header
);
7652 /* Establish the type offset that can be used to lookup the type. */
7653 sig_type
->type_offset_in_section
=
7654 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7656 this_cu
->dwarf_version
= cu
->header
.version
;
7660 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7661 &cu
->header
, section
,
7664 rcuh_kind::COMPILE
);
7666 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7667 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7668 this_cu
->dwarf_version
= cu
->header
.version
;
7672 /* Skip dummy compilation units. */
7673 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7674 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7677 /* If we don't have them yet, read the abbrevs for this compilation unit.
7678 And if we need to read them now, make sure they're freed when we're
7679 done (own the table through ABBREV_TABLE_HOLDER). */
7680 abbrev_table_up abbrev_table_holder
;
7681 if (abbrev_table
!= NULL
)
7682 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7686 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7687 cu
->header
.abbrev_sect_off
);
7688 abbrev_table
= abbrev_table_holder
.get ();
7691 /* Read the top level CU/TU die. */
7692 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7693 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7695 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7698 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7699 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7700 table from the DWO file and pass the ownership over to us. It will be
7701 referenced from READER, so we must make sure to free it after we're done
7704 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7705 DWO CU, that this test will fail (the attribute will not be present). */
7706 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7707 abbrev_table_up dwo_abbrev_table
;
7708 if (dwo_name
!= nullptr)
7710 struct dwo_unit
*dwo_unit
;
7711 struct die_info
*dwo_comp_unit_die
;
7715 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7716 " has children (offset %s) [in module %s]"),
7717 sect_offset_str (this_cu
->sect_off
),
7718 bfd_get_filename (abfd
));
7720 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7721 if (dwo_unit
!= NULL
)
7723 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7724 comp_unit_die
, NULL
,
7726 &dwo_comp_unit_die
, &has_children
,
7727 &dwo_abbrev_table
) == 0)
7732 comp_unit_die
= dwo_comp_unit_die
;
7736 /* Yikes, we couldn't find the rest of the DIE, we only have
7737 the stub. A complaint has already been logged. There's
7738 not much more we can do except pass on the stub DIE to
7739 die_reader_func. We don't want to throw an error on bad
7744 /* All of the above is setup for this call. Yikes. */
7745 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7747 /* Done, clean up. */
7748 if (new_cu
!= NULL
&& keep
)
7750 /* Link this CU into read_in_chain. */
7751 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7752 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7753 /* The chain owns it now. */
7758 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7759 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7760 to have already done the lookup to find the DWO file).
7762 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7763 THIS_CU->is_debug_types, but nothing else.
7765 We fill in THIS_CU->length.
7767 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7768 linker) then DIE_READER_FUNC will not get called.
7770 THIS_CU->cu is always freed when done.
7771 This is done in order to not leave THIS_CU->cu in a state where we have
7772 to care whether it refers to the "main" CU or the DWO CU. */
7775 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7776 struct dwo_file
*dwo_file
,
7777 die_reader_func_ftype
*die_reader_func
,
7780 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7781 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7782 struct dwarf2_section_info
*section
= this_cu
->section
;
7783 bfd
*abfd
= get_section_bfd_owner (section
);
7784 struct dwarf2_section_info
*abbrev_section
;
7785 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7786 struct die_reader_specs reader
;
7787 struct die_info
*comp_unit_die
;
7790 if (dwarf_die_debug
)
7791 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7792 this_cu
->is_debug_types
? "type" : "comp",
7793 sect_offset_str (this_cu
->sect_off
));
7795 gdb_assert (this_cu
->cu
== NULL
);
7797 abbrev_section
= (dwo_file
!= NULL
7798 ? &dwo_file
->sections
.abbrev
7799 : get_abbrev_section_for_cu (this_cu
));
7801 /* This is cheap if the section is already read in. */
7802 dwarf2_read_section (objfile
, section
);
7804 struct dwarf2_cu
cu (this_cu
);
7806 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7807 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7808 &cu
.header
, section
,
7809 abbrev_section
, info_ptr
,
7810 (this_cu
->is_debug_types
7812 : rcuh_kind::COMPILE
));
7814 this_cu
->length
= get_cu_length (&cu
.header
);
7816 /* Skip dummy compilation units. */
7817 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7818 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7821 abbrev_table_up abbrev_table
7822 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7823 cu
.header
.abbrev_sect_off
);
7825 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7826 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7828 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7831 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
7832 does not lookup the specified DWO file.
7833 This cannot be used to read DWO files.
7835 THIS_CU->cu is always freed when done.
7836 This is done in order to not leave THIS_CU->cu in a state where we have
7837 to care whether it refers to the "main" CU or the DWO CU.
7838 We can revisit this if the data shows there's a performance issue. */
7841 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7842 die_reader_func_ftype
*die_reader_func
,
7845 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
7848 /* Type Unit Groups.
7850 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7851 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7852 so that all types coming from the same compilation (.o file) are grouped
7853 together. A future step could be to put the types in the same symtab as
7854 the CU the types ultimately came from. */
7857 hash_type_unit_group (const void *item
)
7859 const struct type_unit_group
*tu_group
7860 = (const struct type_unit_group
*) item
;
7862 return hash_stmt_list_entry (&tu_group
->hash
);
7866 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7868 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7869 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7871 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7874 /* Allocate a hash table for type unit groups. */
7877 allocate_type_unit_groups_table (struct objfile
*objfile
)
7879 return htab_create_alloc_ex (3,
7880 hash_type_unit_group
,
7883 &objfile
->objfile_obstack
,
7884 hashtab_obstack_allocate
,
7885 dummy_obstack_deallocate
);
7888 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7889 partial symtabs. We combine several TUs per psymtab to not let the size
7890 of any one psymtab grow too big. */
7891 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7892 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7894 /* Helper routine for get_type_unit_group.
7895 Create the type_unit_group object used to hold one or more TUs. */
7897 static struct type_unit_group
*
7898 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7900 struct dwarf2_per_objfile
*dwarf2_per_objfile
7901 = cu
->per_cu
->dwarf2_per_objfile
;
7902 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7903 struct dwarf2_per_cu_data
*per_cu
;
7904 struct type_unit_group
*tu_group
;
7906 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7907 struct type_unit_group
);
7908 per_cu
= &tu_group
->per_cu
;
7909 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7911 if (dwarf2_per_objfile
->using_index
)
7913 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7914 struct dwarf2_per_cu_quick_data
);
7918 unsigned int line_offset
= to_underlying (line_offset_struct
);
7919 struct partial_symtab
*pst
;
7922 /* Give the symtab a useful name for debug purposes. */
7923 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7924 name
= string_printf ("<type_units_%d>",
7925 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7927 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7929 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7933 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7934 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7939 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7940 STMT_LIST is a DW_AT_stmt_list attribute. */
7942 static struct type_unit_group
*
7943 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7945 struct dwarf2_per_objfile
*dwarf2_per_objfile
7946 = cu
->per_cu
->dwarf2_per_objfile
;
7947 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7948 struct type_unit_group
*tu_group
;
7950 unsigned int line_offset
;
7951 struct type_unit_group type_unit_group_for_lookup
;
7953 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7955 dwarf2_per_objfile
->type_unit_groups
=
7956 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7959 /* Do we need to create a new group, or can we use an existing one? */
7963 line_offset
= DW_UNSND (stmt_list
);
7964 ++tu_stats
->nr_symtab_sharers
;
7968 /* Ugh, no stmt_list. Rare, but we have to handle it.
7969 We can do various things here like create one group per TU or
7970 spread them over multiple groups to split up the expansion work.
7971 To avoid worst case scenarios (too many groups or too large groups)
7972 we, umm, group them in bunches. */
7973 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7974 | (tu_stats
->nr_stmt_less_type_units
7975 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7976 ++tu_stats
->nr_stmt_less_type_units
;
7979 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7980 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7981 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7982 &type_unit_group_for_lookup
, INSERT
);
7985 tu_group
= (struct type_unit_group
*) *slot
;
7986 gdb_assert (tu_group
!= NULL
);
7990 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7991 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7993 ++tu_stats
->nr_symtabs
;
7999 /* Partial symbol tables. */
8001 /* Create a psymtab named NAME and assign it to PER_CU.
8003 The caller must fill in the following details:
8004 dirname, textlow, texthigh. */
8006 static struct partial_symtab
*
8007 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8009 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
8010 struct partial_symtab
*pst
;
8012 pst
= start_psymtab_common (objfile
, name
, 0);
8014 pst
->psymtabs_addrmap_supported
= 1;
8016 /* This is the glue that links PST into GDB's symbol API. */
8017 pst
->read_symtab_private
= per_cu
;
8018 pst
->read_symtab
= dwarf2_read_symtab
;
8019 per_cu
->v
.psymtab
= pst
;
8024 /* The DATA object passed to process_psymtab_comp_unit_reader has this
8027 struct process_psymtab_comp_unit_data
8029 /* True if we are reading a DW_TAG_partial_unit. */
8031 int want_partial_unit
;
8033 /* The "pretend" language that is used if the CU doesn't declare a
8036 enum language pretend_language
;
8039 /* die_reader_func for process_psymtab_comp_unit. */
8042 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8043 const gdb_byte
*info_ptr
,
8044 struct die_info
*comp_unit_die
,
8048 struct dwarf2_cu
*cu
= reader
->cu
;
8049 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8050 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8051 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8053 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8054 struct partial_symtab
*pst
;
8055 enum pc_bounds_kind cu_bounds_kind
;
8056 const char *filename
;
8057 struct process_psymtab_comp_unit_data
*info
8058 = (struct process_psymtab_comp_unit_data
*) data
;
8060 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
8063 gdb_assert (! per_cu
->is_debug_types
);
8065 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
8067 /* Allocate a new partial symbol table structure. */
8068 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8069 if (filename
== NULL
)
8072 pst
= create_partial_symtab (per_cu
, filename
);
8074 /* This must be done before calling dwarf2_build_include_psymtabs. */
8075 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8077 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8079 dwarf2_find_base_address (comp_unit_die
, cu
);
8081 /* Possibly set the default values of LOWPC and HIGHPC from
8083 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8084 &best_highpc
, cu
, pst
);
8085 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8088 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
8091 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
8093 /* Store the contiguous range if it is not empty; it can be
8094 empty for CUs with no code. */
8095 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8099 /* Check if comp unit has_children.
8100 If so, read the rest of the partial symbols from this comp unit.
8101 If not, there's no more debug_info for this comp unit. */
8104 struct partial_die_info
*first_die
;
8105 CORE_ADDR lowpc
, highpc
;
8107 lowpc
= ((CORE_ADDR
) -1);
8108 highpc
= ((CORE_ADDR
) 0);
8110 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8112 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8113 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8115 /* If we didn't find a lowpc, set it to highpc to avoid
8116 complaints from `maint check'. */
8117 if (lowpc
== ((CORE_ADDR
) -1))
8120 /* If the compilation unit didn't have an explicit address range,
8121 then use the information extracted from its child dies. */
8122 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8125 best_highpc
= highpc
;
8128 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
8129 best_lowpc
+ baseaddr
)
8131 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
8132 best_highpc
+ baseaddr
)
8135 end_psymtab_common (objfile
, pst
);
8137 if (!cu
->per_cu
->imported_symtabs_empty ())
8140 int len
= cu
->per_cu
->imported_symtabs_size ();
8142 /* Fill in 'dependencies' here; we fill in 'users' in a
8144 pst
->number_of_dependencies
= len
;
8146 = objfile
->partial_symtabs
->allocate_dependencies (len
);
8147 for (i
= 0; i
< len
; ++i
)
8149 pst
->dependencies
[i
]
8150 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
8153 cu
->per_cu
->imported_symtabs_free ();
8156 /* Get the list of files included in the current compilation unit,
8157 and build a psymtab for each of them. */
8158 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8160 if (dwarf_read_debug
)
8161 fprintf_unfiltered (gdb_stdlog
,
8162 "Psymtab for %s unit @%s: %s - %s"
8163 ", %d global, %d static syms\n",
8164 per_cu
->is_debug_types
? "type" : "comp",
8165 sect_offset_str (per_cu
->sect_off
),
8166 paddress (gdbarch
, pst
->text_low (objfile
)),
8167 paddress (gdbarch
, pst
->text_high (objfile
)),
8168 pst
->n_global_syms
, pst
->n_static_syms
);
8171 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8172 Process compilation unit THIS_CU for a psymtab. */
8175 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8176 int want_partial_unit
,
8177 enum language pretend_language
)
8179 /* If this compilation unit was already read in, free the
8180 cached copy in order to read it in again. This is
8181 necessary because we skipped some symbols when we first
8182 read in the compilation unit (see load_partial_dies).
8183 This problem could be avoided, but the benefit is unclear. */
8184 if (this_cu
->cu
!= NULL
)
8185 free_one_cached_comp_unit (this_cu
);
8187 if (this_cu
->is_debug_types
)
8188 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8189 build_type_psymtabs_reader
, NULL
);
8192 process_psymtab_comp_unit_data info
;
8193 info
.want_partial_unit
= want_partial_unit
;
8194 info
.pretend_language
= pretend_language
;
8195 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8196 process_psymtab_comp_unit_reader
, &info
);
8199 /* Age out any secondary CUs. */
8200 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8203 /* Reader function for build_type_psymtabs. */
8206 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8207 const gdb_byte
*info_ptr
,
8208 struct die_info
*type_unit_die
,
8212 struct dwarf2_per_objfile
*dwarf2_per_objfile
8213 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8214 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8215 struct dwarf2_cu
*cu
= reader
->cu
;
8216 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8217 struct signatured_type
*sig_type
;
8218 struct type_unit_group
*tu_group
;
8219 struct attribute
*attr
;
8220 struct partial_die_info
*first_die
;
8221 CORE_ADDR lowpc
, highpc
;
8222 struct partial_symtab
*pst
;
8224 gdb_assert (data
== NULL
);
8225 gdb_assert (per_cu
->is_debug_types
);
8226 sig_type
= (struct signatured_type
*) per_cu
;
8231 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8232 tu_group
= get_type_unit_group (cu
, attr
);
8234 if (tu_group
->tus
== nullptr)
8235 tu_group
->tus
= new std::vector
<signatured_type
*>;
8236 tu_group
->tus
->push_back (sig_type
);
8238 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8239 pst
= create_partial_symtab (per_cu
, "");
8242 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8244 lowpc
= (CORE_ADDR
) -1;
8245 highpc
= (CORE_ADDR
) 0;
8246 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8248 end_psymtab_common (objfile
, pst
);
8251 /* Struct used to sort TUs by their abbreviation table offset. */
8253 struct tu_abbrev_offset
8255 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8256 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8259 signatured_type
*sig_type
;
8260 sect_offset abbrev_offset
;
8263 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8266 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8267 const struct tu_abbrev_offset
&b
)
8269 return a
.abbrev_offset
< b
.abbrev_offset
;
8272 /* Efficiently read all the type units.
8273 This does the bulk of the work for build_type_psymtabs.
8275 The efficiency is because we sort TUs by the abbrev table they use and
8276 only read each abbrev table once. In one program there are 200K TUs
8277 sharing 8K abbrev tables.
8279 The main purpose of this function is to support building the
8280 dwarf2_per_objfile->type_unit_groups table.
8281 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8282 can collapse the search space by grouping them by stmt_list.
8283 The savings can be significant, in the same program from above the 200K TUs
8284 share 8K stmt_list tables.
8286 FUNC is expected to call get_type_unit_group, which will create the
8287 struct type_unit_group if necessary and add it to
8288 dwarf2_per_objfile->type_unit_groups. */
8291 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8293 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8294 abbrev_table_up abbrev_table
;
8295 sect_offset abbrev_offset
;
8297 /* It's up to the caller to not call us multiple times. */
8298 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8300 if (dwarf2_per_objfile
->all_type_units
.empty ())
8303 /* TUs typically share abbrev tables, and there can be way more TUs than
8304 abbrev tables. Sort by abbrev table to reduce the number of times we
8305 read each abbrev table in.
8306 Alternatives are to punt or to maintain a cache of abbrev tables.
8307 This is simpler and efficient enough for now.
8309 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8310 symtab to use). Typically TUs with the same abbrev offset have the same
8311 stmt_list value too so in practice this should work well.
8313 The basic algorithm here is:
8315 sort TUs by abbrev table
8316 for each TU with same abbrev table:
8317 read abbrev table if first user
8318 read TU top level DIE
8319 [IWBN if DWO skeletons had DW_AT_stmt_list]
8322 if (dwarf_read_debug
)
8323 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8325 /* Sort in a separate table to maintain the order of all_type_units
8326 for .gdb_index: TU indices directly index all_type_units. */
8327 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8328 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8330 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8331 sorted_by_abbrev
.emplace_back
8332 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8333 sig_type
->per_cu
.section
,
8334 sig_type
->per_cu
.sect_off
));
8336 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8337 sort_tu_by_abbrev_offset
);
8339 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8341 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8343 /* Switch to the next abbrev table if necessary. */
8344 if (abbrev_table
== NULL
8345 || tu
.abbrev_offset
!= abbrev_offset
)
8347 abbrev_offset
= tu
.abbrev_offset
;
8349 abbrev_table_read_table (dwarf2_per_objfile
,
8350 &dwarf2_per_objfile
->abbrev
,
8352 ++tu_stats
->nr_uniq_abbrev_tables
;
8355 init_cutu_and_read_dies (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8356 0, 0, false, build_type_psymtabs_reader
, NULL
);
8360 /* Print collected type unit statistics. */
8363 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8365 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8367 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8368 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8369 dwarf2_per_objfile
->all_type_units
.size ());
8370 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8371 tu_stats
->nr_uniq_abbrev_tables
);
8372 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8373 tu_stats
->nr_symtabs
);
8374 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8375 tu_stats
->nr_symtab_sharers
);
8376 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8377 tu_stats
->nr_stmt_less_type_units
);
8378 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8379 tu_stats
->nr_all_type_units_reallocs
);
8382 /* Traversal function for build_type_psymtabs. */
8385 build_type_psymtab_dependencies (void **slot
, void *info
)
8387 struct dwarf2_per_objfile
*dwarf2_per_objfile
8388 = (struct dwarf2_per_objfile
*) info
;
8389 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8390 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8391 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8392 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8393 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8396 gdb_assert (len
> 0);
8397 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8399 pst
->number_of_dependencies
= len
;
8400 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8401 for (i
= 0; i
< len
; ++i
)
8403 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8404 gdb_assert (iter
->per_cu
.is_debug_types
);
8405 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8406 iter
->type_unit_group
= tu_group
;
8409 delete tu_group
->tus
;
8410 tu_group
->tus
= nullptr;
8415 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8416 Build partial symbol tables for the .debug_types comp-units. */
8419 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8421 if (! create_all_type_units (dwarf2_per_objfile
))
8424 build_type_psymtabs_1 (dwarf2_per_objfile
);
8427 /* Traversal function for process_skeletonless_type_unit.
8428 Read a TU in a DWO file and build partial symbols for it. */
8431 process_skeletonless_type_unit (void **slot
, void *info
)
8433 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8434 struct dwarf2_per_objfile
*dwarf2_per_objfile
8435 = (struct dwarf2_per_objfile
*) info
;
8436 struct signatured_type find_entry
, *entry
;
8438 /* If this TU doesn't exist in the global table, add it and read it in. */
8440 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8442 dwarf2_per_objfile
->signatured_types
8443 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8446 find_entry
.signature
= dwo_unit
->signature
;
8447 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8449 /* If we've already seen this type there's nothing to do. What's happening
8450 is we're doing our own version of comdat-folding here. */
8454 /* This does the job that create_all_type_units would have done for
8456 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8457 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8460 /* This does the job that build_type_psymtabs_1 would have done. */
8461 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0, false,
8462 build_type_psymtabs_reader
, NULL
);
8467 /* Traversal function for process_skeletonless_type_units. */
8470 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8472 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8474 if (dwo_file
->tus
!= NULL
)
8476 htab_traverse_noresize (dwo_file
->tus
,
8477 process_skeletonless_type_unit
, info
);
8483 /* Scan all TUs of DWO files, verifying we've processed them.
8484 This is needed in case a TU was emitted without its skeleton.
8485 Note: This can't be done until we know what all the DWO files are. */
8488 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8490 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8491 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8492 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8494 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8495 process_dwo_file_for_skeletonless_type_units
,
8496 dwarf2_per_objfile
);
8500 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8503 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8505 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8507 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8512 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8514 /* Set the 'user' field only if it is not already set. */
8515 if (pst
->dependencies
[j
]->user
== NULL
)
8516 pst
->dependencies
[j
]->user
= pst
;
8521 /* Build the partial symbol table by doing a quick pass through the
8522 .debug_info and .debug_abbrev sections. */
8525 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8527 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8529 if (dwarf_read_debug
)
8531 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8532 objfile_name (objfile
));
8535 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8537 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8539 /* Any cached compilation units will be linked by the per-objfile
8540 read_in_chain. Make sure to free them when we're done. */
8541 free_cached_comp_units
freer (dwarf2_per_objfile
);
8543 build_type_psymtabs (dwarf2_per_objfile
);
8545 create_all_comp_units (dwarf2_per_objfile
);
8547 /* Create a temporary address map on a temporary obstack. We later
8548 copy this to the final obstack. */
8549 auto_obstack temp_obstack
;
8551 scoped_restore save_psymtabs_addrmap
8552 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8553 addrmap_create_mutable (&temp_obstack
));
8555 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8556 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8558 /* This has to wait until we read the CUs, we need the list of DWOs. */
8559 process_skeletonless_type_units (dwarf2_per_objfile
);
8561 /* Now that all TUs have been processed we can fill in the dependencies. */
8562 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8564 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8565 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8568 if (dwarf_read_debug
)
8569 print_tu_stats (dwarf2_per_objfile
);
8571 set_partial_user (dwarf2_per_objfile
);
8573 objfile
->partial_symtabs
->psymtabs_addrmap
8574 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8575 objfile
->partial_symtabs
->obstack ());
8576 /* At this point we want to keep the address map. */
8577 save_psymtabs_addrmap
.release ();
8579 if (dwarf_read_debug
)
8580 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8581 objfile_name (objfile
));
8584 /* die_reader_func for load_partial_comp_unit. */
8587 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8588 const gdb_byte
*info_ptr
,
8589 struct die_info
*comp_unit_die
,
8593 struct dwarf2_cu
*cu
= reader
->cu
;
8595 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8597 /* Check if comp unit has_children.
8598 If so, read the rest of the partial symbols from this comp unit.
8599 If not, there's no more debug_info for this comp unit. */
8601 load_partial_dies (reader
, info_ptr
, 0);
8604 /* Load the partial DIEs for a secondary CU into memory.
8605 This is also used when rereading a primary CU with load_all_dies. */
8608 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8610 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, false,
8611 load_partial_comp_unit_reader
, NULL
);
8615 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8616 struct dwarf2_section_info
*section
,
8617 struct dwarf2_section_info
*abbrev_section
,
8618 unsigned int is_dwz
)
8620 const gdb_byte
*info_ptr
;
8621 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8623 if (dwarf_read_debug
)
8624 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8625 get_section_name (section
),
8626 get_section_file_name (section
));
8628 dwarf2_read_section (objfile
, section
);
8630 info_ptr
= section
->buffer
;
8632 while (info_ptr
< section
->buffer
+ section
->size
)
8634 struct dwarf2_per_cu_data
*this_cu
;
8636 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8638 comp_unit_head cu_header
;
8639 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8640 abbrev_section
, info_ptr
,
8641 rcuh_kind::COMPILE
);
8643 /* Save the compilation unit for later lookup. */
8644 if (cu_header
.unit_type
!= DW_UT_type
)
8646 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8647 struct dwarf2_per_cu_data
);
8648 memset (this_cu
, 0, sizeof (*this_cu
));
8652 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8653 struct signatured_type
);
8654 memset (sig_type
, 0, sizeof (*sig_type
));
8655 sig_type
->signature
= cu_header
.signature
;
8656 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8657 this_cu
= &sig_type
->per_cu
;
8659 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8660 this_cu
->sect_off
= sect_off
;
8661 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8662 this_cu
->is_dwz
= is_dwz
;
8663 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8664 this_cu
->section
= section
;
8666 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8668 info_ptr
= info_ptr
+ this_cu
->length
;
8672 /* Create a list of all compilation units in OBJFILE.
8673 This is only done for -readnow and building partial symtabs. */
8676 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8678 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8679 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8680 &dwarf2_per_objfile
->abbrev
, 0);
8682 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8684 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8688 /* Process all loaded DIEs for compilation unit CU, starting at
8689 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8690 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8691 DW_AT_ranges). See the comments of add_partial_subprogram on how
8692 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8695 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8696 CORE_ADDR
*highpc
, int set_addrmap
,
8697 struct dwarf2_cu
*cu
)
8699 struct partial_die_info
*pdi
;
8701 /* Now, march along the PDI's, descending into ones which have
8702 interesting children but skipping the children of the other ones,
8703 until we reach the end of the compilation unit. */
8711 /* Anonymous namespaces or modules have no name but have interesting
8712 children, so we need to look at them. Ditto for anonymous
8715 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8716 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8717 || pdi
->tag
== DW_TAG_imported_unit
8718 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8722 case DW_TAG_subprogram
:
8723 case DW_TAG_inlined_subroutine
:
8724 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8726 case DW_TAG_constant
:
8727 case DW_TAG_variable
:
8728 case DW_TAG_typedef
:
8729 case DW_TAG_union_type
:
8730 if (!pdi
->is_declaration
)
8732 add_partial_symbol (pdi
, cu
);
8735 case DW_TAG_class_type
:
8736 case DW_TAG_interface_type
:
8737 case DW_TAG_structure_type
:
8738 if (!pdi
->is_declaration
)
8740 add_partial_symbol (pdi
, cu
);
8742 if ((cu
->language
== language_rust
8743 || cu
->language
== language_cplus
) && pdi
->has_children
)
8744 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8747 case DW_TAG_enumeration_type
:
8748 if (!pdi
->is_declaration
)
8749 add_partial_enumeration (pdi
, cu
);
8751 case DW_TAG_base_type
:
8752 case DW_TAG_subrange_type
:
8753 /* File scope base type definitions are added to the partial
8755 add_partial_symbol (pdi
, cu
);
8757 case DW_TAG_namespace
:
8758 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8761 if (!pdi
->is_declaration
)
8762 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8764 case DW_TAG_imported_unit
:
8766 struct dwarf2_per_cu_data
*per_cu
;
8768 /* For now we don't handle imported units in type units. */
8769 if (cu
->per_cu
->is_debug_types
)
8771 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8772 " supported in type units [in module %s]"),
8773 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8776 per_cu
= dwarf2_find_containing_comp_unit
8777 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8778 cu
->per_cu
->dwarf2_per_objfile
);
8780 /* Go read the partial unit, if needed. */
8781 if (per_cu
->v
.psymtab
== NULL
)
8782 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8784 cu
->per_cu
->imported_symtabs_push (per_cu
);
8787 case DW_TAG_imported_declaration
:
8788 add_partial_symbol (pdi
, cu
);
8795 /* If the die has a sibling, skip to the sibling. */
8797 pdi
= pdi
->die_sibling
;
8801 /* Functions used to compute the fully scoped name of a partial DIE.
8803 Normally, this is simple. For C++, the parent DIE's fully scoped
8804 name is concatenated with "::" and the partial DIE's name.
8805 Enumerators are an exception; they use the scope of their parent
8806 enumeration type, i.e. the name of the enumeration type is not
8807 prepended to the enumerator.
8809 There are two complexities. One is DW_AT_specification; in this
8810 case "parent" means the parent of the target of the specification,
8811 instead of the direct parent of the DIE. The other is compilers
8812 which do not emit DW_TAG_namespace; in this case we try to guess
8813 the fully qualified name of structure types from their members'
8814 linkage names. This must be done using the DIE's children rather
8815 than the children of any DW_AT_specification target. We only need
8816 to do this for structures at the top level, i.e. if the target of
8817 any DW_AT_specification (if any; otherwise the DIE itself) does not
8820 /* Compute the scope prefix associated with PDI's parent, in
8821 compilation unit CU. The result will be allocated on CU's
8822 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8823 field. NULL is returned if no prefix is necessary. */
8825 partial_die_parent_scope (struct partial_die_info
*pdi
,
8826 struct dwarf2_cu
*cu
)
8828 const char *grandparent_scope
;
8829 struct partial_die_info
*parent
, *real_pdi
;
8831 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8832 then this means the parent of the specification DIE. */
8835 while (real_pdi
->has_specification
)
8837 auto res
= find_partial_die (real_pdi
->spec_offset
,
8838 real_pdi
->spec_is_dwz
, cu
);
8843 parent
= real_pdi
->die_parent
;
8847 if (parent
->scope_set
)
8848 return parent
->scope
;
8852 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8854 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8855 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8856 Work around this problem here. */
8857 if (cu
->language
== language_cplus
8858 && parent
->tag
== DW_TAG_namespace
8859 && strcmp (parent
->name
, "::") == 0
8860 && grandparent_scope
== NULL
)
8862 parent
->scope
= NULL
;
8863 parent
->scope_set
= 1;
8867 /* Nested subroutines in Fortran get a prefix. */
8868 if (pdi
->tag
== DW_TAG_enumerator
)
8869 /* Enumerators should not get the name of the enumeration as a prefix. */
8870 parent
->scope
= grandparent_scope
;
8871 else if (parent
->tag
== DW_TAG_namespace
8872 || parent
->tag
== DW_TAG_module
8873 || parent
->tag
== DW_TAG_structure_type
8874 || parent
->tag
== DW_TAG_class_type
8875 || parent
->tag
== DW_TAG_interface_type
8876 || parent
->tag
== DW_TAG_union_type
8877 || parent
->tag
== DW_TAG_enumeration_type
8878 || (cu
->language
== language_fortran
8879 && parent
->tag
== DW_TAG_subprogram
8880 && pdi
->tag
== DW_TAG_subprogram
))
8882 if (grandparent_scope
== NULL
)
8883 parent
->scope
= parent
->name
;
8885 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8887 parent
->name
, 0, cu
);
8891 /* FIXME drow/2004-04-01: What should we be doing with
8892 function-local names? For partial symbols, we should probably be
8894 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8895 dwarf_tag_name (parent
->tag
),
8896 sect_offset_str (pdi
->sect_off
));
8897 parent
->scope
= grandparent_scope
;
8900 parent
->scope_set
= 1;
8901 return parent
->scope
;
8904 /* Return the fully scoped name associated with PDI, from compilation unit
8905 CU. The result will be allocated with malloc. */
8908 partial_die_full_name (struct partial_die_info
*pdi
,
8909 struct dwarf2_cu
*cu
)
8911 const char *parent_scope
;
8913 /* If this is a template instantiation, we can not work out the
8914 template arguments from partial DIEs. So, unfortunately, we have
8915 to go through the full DIEs. At least any work we do building
8916 types here will be reused if full symbols are loaded later. */
8917 if (pdi
->has_template_arguments
)
8921 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8923 struct die_info
*die
;
8924 struct attribute attr
;
8925 struct dwarf2_cu
*ref_cu
= cu
;
8927 /* DW_FORM_ref_addr is using section offset. */
8928 attr
.name
= (enum dwarf_attribute
) 0;
8929 attr
.form
= DW_FORM_ref_addr
;
8930 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8931 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8933 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8937 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8938 if (parent_scope
== NULL
)
8941 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
8945 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8947 struct dwarf2_per_objfile
*dwarf2_per_objfile
8948 = cu
->per_cu
->dwarf2_per_objfile
;
8949 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8950 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8952 const char *actual_name
= NULL
;
8954 char *built_actual_name
;
8956 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8958 built_actual_name
= partial_die_full_name (pdi
, cu
);
8959 if (built_actual_name
!= NULL
)
8960 actual_name
= built_actual_name
;
8962 if (actual_name
== NULL
)
8963 actual_name
= pdi
->name
;
8967 case DW_TAG_inlined_subroutine
:
8968 case DW_TAG_subprogram
:
8969 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8971 if (pdi
->is_external
8972 || cu
->language
== language_ada
8973 || (cu
->language
== language_fortran
8974 && pdi
->die_parent
!= NULL
8975 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8977 /* Normally, only "external" DIEs are part of the global scope.
8978 But in Ada and Fortran, we want to be able to access nested
8979 procedures globally. So all Ada and Fortran subprograms are
8980 stored in the global scope. */
8981 add_psymbol_to_list (actual_name
,
8982 built_actual_name
!= NULL
,
8983 VAR_DOMAIN
, LOC_BLOCK
,
8984 SECT_OFF_TEXT (objfile
),
8985 psymbol_placement::GLOBAL
,
8987 cu
->language
, objfile
);
8991 add_psymbol_to_list (actual_name
,
8992 built_actual_name
!= NULL
,
8993 VAR_DOMAIN
, LOC_BLOCK
,
8994 SECT_OFF_TEXT (objfile
),
8995 psymbol_placement::STATIC
,
8996 addr
, cu
->language
, objfile
);
8999 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
9000 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
9002 case DW_TAG_constant
:
9003 add_psymbol_to_list (actual_name
,
9004 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
9005 -1, (pdi
->is_external
9006 ? psymbol_placement::GLOBAL
9007 : psymbol_placement::STATIC
),
9008 0, cu
->language
, objfile
);
9010 case DW_TAG_variable
:
9012 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
9016 && !dwarf2_per_objfile
->has_section_at_zero
)
9018 /* A global or static variable may also have been stripped
9019 out by the linker if unused, in which case its address
9020 will be nullified; do not add such variables into partial
9021 symbol table then. */
9023 else if (pdi
->is_external
)
9026 Don't enter into the minimal symbol tables as there is
9027 a minimal symbol table entry from the ELF symbols already.
9028 Enter into partial symbol table if it has a location
9029 descriptor or a type.
9030 If the location descriptor is missing, new_symbol will create
9031 a LOC_UNRESOLVED symbol, the address of the variable will then
9032 be determined from the minimal symbol table whenever the variable
9034 The address for the partial symbol table entry is not
9035 used by GDB, but it comes in handy for debugging partial symbol
9038 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9039 add_psymbol_to_list (actual_name
,
9040 built_actual_name
!= NULL
,
9041 VAR_DOMAIN
, LOC_STATIC
,
9042 SECT_OFF_TEXT (objfile
),
9043 psymbol_placement::GLOBAL
,
9044 addr
, cu
->language
, objfile
);
9048 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9050 /* Static Variable. Skip symbols whose value we cannot know (those
9051 without location descriptors or constant values). */
9052 if (!has_loc
&& !pdi
->has_const_value
)
9054 xfree (built_actual_name
);
9058 add_psymbol_to_list (actual_name
,
9059 built_actual_name
!= NULL
,
9060 VAR_DOMAIN
, LOC_STATIC
,
9061 SECT_OFF_TEXT (objfile
),
9062 psymbol_placement::STATIC
,
9064 cu
->language
, objfile
);
9067 case DW_TAG_typedef
:
9068 case DW_TAG_base_type
:
9069 case DW_TAG_subrange_type
:
9070 add_psymbol_to_list (actual_name
,
9071 built_actual_name
!= NULL
,
9072 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9073 psymbol_placement::STATIC
,
9074 0, cu
->language
, objfile
);
9076 case DW_TAG_imported_declaration
:
9077 case DW_TAG_namespace
:
9078 add_psymbol_to_list (actual_name
,
9079 built_actual_name
!= NULL
,
9080 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9081 psymbol_placement::GLOBAL
,
9082 0, cu
->language
, objfile
);
9085 /* With Fortran 77 there might be a "BLOCK DATA" module
9086 available without any name. If so, we skip the module as it
9087 doesn't bring any value. */
9088 if (actual_name
!= nullptr)
9089 add_psymbol_to_list (actual_name
,
9090 built_actual_name
!= NULL
,
9091 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
9092 psymbol_placement::GLOBAL
,
9093 0, cu
->language
, objfile
);
9095 case DW_TAG_class_type
:
9096 case DW_TAG_interface_type
:
9097 case DW_TAG_structure_type
:
9098 case DW_TAG_union_type
:
9099 case DW_TAG_enumeration_type
:
9100 /* Skip external references. The DWARF standard says in the section
9101 about "Structure, Union, and Class Type Entries": "An incomplete
9102 structure, union or class type is represented by a structure,
9103 union or class entry that does not have a byte size attribute
9104 and that has a DW_AT_declaration attribute." */
9105 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9107 xfree (built_actual_name
);
9111 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9112 static vs. global. */
9113 add_psymbol_to_list (actual_name
,
9114 built_actual_name
!= NULL
,
9115 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
9116 cu
->language
== language_cplus
9117 ? psymbol_placement::GLOBAL
9118 : psymbol_placement::STATIC
,
9119 0, cu
->language
, objfile
);
9122 case DW_TAG_enumerator
:
9123 add_psymbol_to_list (actual_name
,
9124 built_actual_name
!= NULL
,
9125 VAR_DOMAIN
, LOC_CONST
, -1,
9126 cu
->language
== language_cplus
9127 ? psymbol_placement::GLOBAL
9128 : psymbol_placement::STATIC
,
9129 0, cu
->language
, objfile
);
9135 xfree (built_actual_name
);
9138 /* Read a partial die corresponding to a namespace; also, add a symbol
9139 corresponding to that namespace to the symbol table. NAMESPACE is
9140 the name of the enclosing namespace. */
9143 add_partial_namespace (struct partial_die_info
*pdi
,
9144 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9145 int set_addrmap
, struct dwarf2_cu
*cu
)
9147 /* Add a symbol for the namespace. */
9149 add_partial_symbol (pdi
, cu
);
9151 /* Now scan partial symbols in that namespace. */
9153 if (pdi
->has_children
)
9154 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9157 /* Read a partial die corresponding to a Fortran module. */
9160 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9161 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9163 /* Add a symbol for the namespace. */
9165 add_partial_symbol (pdi
, cu
);
9167 /* Now scan partial symbols in that module. */
9169 if (pdi
->has_children
)
9170 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9173 /* Read a partial die corresponding to a subprogram or an inlined
9174 subprogram and create a partial symbol for that subprogram.
9175 When the CU language allows it, this routine also defines a partial
9176 symbol for each nested subprogram that this subprogram contains.
9177 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9178 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9180 PDI may also be a lexical block, in which case we simply search
9181 recursively for subprograms defined inside that lexical block.
9182 Again, this is only performed when the CU language allows this
9183 type of definitions. */
9186 add_partial_subprogram (struct partial_die_info
*pdi
,
9187 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9188 int set_addrmap
, struct dwarf2_cu
*cu
)
9190 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9192 if (pdi
->has_pc_info
)
9194 if (pdi
->lowpc
< *lowpc
)
9195 *lowpc
= pdi
->lowpc
;
9196 if (pdi
->highpc
> *highpc
)
9197 *highpc
= pdi
->highpc
;
9200 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9201 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9203 CORE_ADDR this_highpc
;
9204 CORE_ADDR this_lowpc
;
9206 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9207 SECT_OFF_TEXT (objfile
));
9209 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9210 pdi
->lowpc
+ baseaddr
)
9213 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9214 pdi
->highpc
+ baseaddr
)
9216 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
9217 this_lowpc
, this_highpc
- 1,
9218 cu
->per_cu
->v
.psymtab
);
9222 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9224 if (!pdi
->is_declaration
)
9225 /* Ignore subprogram DIEs that do not have a name, they are
9226 illegal. Do not emit a complaint at this point, we will
9227 do so when we convert this psymtab into a symtab. */
9229 add_partial_symbol (pdi
, cu
);
9233 if (! pdi
->has_children
)
9236 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
9238 pdi
= pdi
->die_child
;
9242 if (pdi
->tag
== DW_TAG_subprogram
9243 || pdi
->tag
== DW_TAG_inlined_subroutine
9244 || pdi
->tag
== DW_TAG_lexical_block
)
9245 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9246 pdi
= pdi
->die_sibling
;
9251 /* Read a partial die corresponding to an enumeration type. */
9254 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9255 struct dwarf2_cu
*cu
)
9257 struct partial_die_info
*pdi
;
9259 if (enum_pdi
->name
!= NULL
)
9260 add_partial_symbol (enum_pdi
, cu
);
9262 pdi
= enum_pdi
->die_child
;
9265 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9266 complaint (_("malformed enumerator DIE ignored"));
9268 add_partial_symbol (pdi
, cu
);
9269 pdi
= pdi
->die_sibling
;
9273 /* Return the initial uleb128 in the die at INFO_PTR. */
9276 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9278 unsigned int bytes_read
;
9280 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9283 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9284 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9286 Return the corresponding abbrev, or NULL if the number is zero (indicating
9287 an empty DIE). In either case *BYTES_READ will be set to the length of
9288 the initial number. */
9290 static struct abbrev_info
*
9291 peek_die_abbrev (const die_reader_specs
&reader
,
9292 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9294 dwarf2_cu
*cu
= reader
.cu
;
9295 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9296 unsigned int abbrev_number
9297 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9299 if (abbrev_number
== 0)
9302 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9305 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9306 " at offset %s [in module %s]"),
9307 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9308 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9314 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9315 Returns a pointer to the end of a series of DIEs, terminated by an empty
9316 DIE. Any children of the skipped DIEs will also be skipped. */
9318 static const gdb_byte
*
9319 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9323 unsigned int bytes_read
;
9324 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9327 return info_ptr
+ bytes_read
;
9329 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9333 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9334 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9335 abbrev corresponding to that skipped uleb128 should be passed in
9336 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9339 static const gdb_byte
*
9340 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9341 struct abbrev_info
*abbrev
)
9343 unsigned int bytes_read
;
9344 struct attribute attr
;
9345 bfd
*abfd
= reader
->abfd
;
9346 struct dwarf2_cu
*cu
= reader
->cu
;
9347 const gdb_byte
*buffer
= reader
->buffer
;
9348 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9349 unsigned int form
, i
;
9351 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9353 /* The only abbrev we care about is DW_AT_sibling. */
9354 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9356 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9357 if (attr
.form
== DW_FORM_ref_addr
)
9358 complaint (_("ignoring absolute DW_AT_sibling"));
9361 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9362 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9364 if (sibling_ptr
< info_ptr
)
9365 complaint (_("DW_AT_sibling points backwards"));
9366 else if (sibling_ptr
> reader
->buffer_end
)
9367 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9373 /* If it isn't DW_AT_sibling, skip this attribute. */
9374 form
= abbrev
->attrs
[i
].form
;
9378 case DW_FORM_ref_addr
:
9379 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9380 and later it is offset sized. */
9381 if (cu
->header
.version
== 2)
9382 info_ptr
+= cu
->header
.addr_size
;
9384 info_ptr
+= cu
->header
.offset_size
;
9386 case DW_FORM_GNU_ref_alt
:
9387 info_ptr
+= cu
->header
.offset_size
;
9390 info_ptr
+= cu
->header
.addr_size
;
9398 case DW_FORM_flag_present
:
9399 case DW_FORM_implicit_const
:
9416 case DW_FORM_ref_sig8
:
9419 case DW_FORM_data16
:
9422 case DW_FORM_string
:
9423 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9424 info_ptr
+= bytes_read
;
9426 case DW_FORM_sec_offset
:
9428 case DW_FORM_GNU_strp_alt
:
9429 info_ptr
+= cu
->header
.offset_size
;
9431 case DW_FORM_exprloc
:
9433 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9434 info_ptr
+= bytes_read
;
9436 case DW_FORM_block1
:
9437 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9439 case DW_FORM_block2
:
9440 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9442 case DW_FORM_block4
:
9443 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9449 case DW_FORM_ref_udata
:
9450 case DW_FORM_GNU_addr_index
:
9451 case DW_FORM_GNU_str_index
:
9452 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9454 case DW_FORM_indirect
:
9455 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9456 info_ptr
+= bytes_read
;
9457 /* We need to continue parsing from here, so just go back to
9459 goto skip_attribute
;
9462 error (_("Dwarf Error: Cannot handle %s "
9463 "in DWARF reader [in module %s]"),
9464 dwarf_form_name (form
),
9465 bfd_get_filename (abfd
));
9469 if (abbrev
->has_children
)
9470 return skip_children (reader
, info_ptr
);
9475 /* Locate ORIG_PDI's sibling.
9476 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9478 static const gdb_byte
*
9479 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9480 struct partial_die_info
*orig_pdi
,
9481 const gdb_byte
*info_ptr
)
9483 /* Do we know the sibling already? */
9485 if (orig_pdi
->sibling
)
9486 return orig_pdi
->sibling
;
9488 /* Are there any children to deal with? */
9490 if (!orig_pdi
->has_children
)
9493 /* Skip the children the long way. */
9495 return skip_children (reader
, info_ptr
);
9498 /* Expand this partial symbol table into a full symbol table. SELF is
9502 dwarf2_read_symtab (struct partial_symtab
*self
,
9503 struct objfile
*objfile
)
9505 struct dwarf2_per_objfile
*dwarf2_per_objfile
9506 = get_dwarf2_per_objfile (objfile
);
9510 warning (_("bug: psymtab for %s is already read in."),
9517 printf_filtered (_("Reading in symbols for %s..."),
9519 gdb_flush (gdb_stdout
);
9522 /* If this psymtab is constructed from a debug-only objfile, the
9523 has_section_at_zero flag will not necessarily be correct. We
9524 can get the correct value for this flag by looking at the data
9525 associated with the (presumably stripped) associated objfile. */
9526 if (objfile
->separate_debug_objfile_backlink
)
9528 struct dwarf2_per_objfile
*dpo_backlink
9529 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9531 dwarf2_per_objfile
->has_section_at_zero
9532 = dpo_backlink
->has_section_at_zero
;
9535 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9537 psymtab_to_symtab_1 (self
);
9539 /* Finish up the debug error message. */
9541 printf_filtered (_("done.\n"));
9544 process_cu_includes (dwarf2_per_objfile
);
9547 /* Reading in full CUs. */
9549 /* Add PER_CU to the queue. */
9552 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9553 enum language pretend_language
)
9555 struct dwarf2_queue_item
*item
;
9558 item
= XNEW (struct dwarf2_queue_item
);
9559 item
->per_cu
= per_cu
;
9560 item
->pretend_language
= pretend_language
;
9563 if (dwarf2_queue
== NULL
)
9564 dwarf2_queue
= item
;
9566 dwarf2_queue_tail
->next
= item
;
9568 dwarf2_queue_tail
= item
;
9571 /* If PER_CU is not yet queued, add it to the queue.
9572 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9574 The result is non-zero if PER_CU was queued, otherwise the result is zero
9575 meaning either PER_CU is already queued or it is already loaded.
9577 N.B. There is an invariant here that if a CU is queued then it is loaded.
9578 The caller is required to load PER_CU if we return non-zero. */
9581 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9582 struct dwarf2_per_cu_data
*per_cu
,
9583 enum language pretend_language
)
9585 /* We may arrive here during partial symbol reading, if we need full
9586 DIEs to process an unusual case (e.g. template arguments). Do
9587 not queue PER_CU, just tell our caller to load its DIEs. */
9588 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9590 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9595 /* Mark the dependence relation so that we don't flush PER_CU
9597 if (dependent_cu
!= NULL
)
9598 dwarf2_add_dependence (dependent_cu
, per_cu
);
9600 /* If it's already on the queue, we have nothing to do. */
9604 /* If the compilation unit is already loaded, just mark it as
9606 if (per_cu
->cu
!= NULL
)
9608 per_cu
->cu
->last_used
= 0;
9612 /* Add it to the queue. */
9613 queue_comp_unit (per_cu
, pretend_language
);
9618 /* Process the queue. */
9621 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9623 struct dwarf2_queue_item
*item
, *next_item
;
9625 if (dwarf_read_debug
)
9627 fprintf_unfiltered (gdb_stdlog
,
9628 "Expanding one or more symtabs of objfile %s ...\n",
9629 objfile_name (dwarf2_per_objfile
->objfile
));
9632 /* The queue starts out with one item, but following a DIE reference
9633 may load a new CU, adding it to the end of the queue. */
9634 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9636 if ((dwarf2_per_objfile
->using_index
9637 ? !item
->per_cu
->v
.quick
->compunit_symtab
9638 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9639 /* Skip dummy CUs. */
9640 && item
->per_cu
->cu
!= NULL
)
9642 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9643 unsigned int debug_print_threshold
;
9646 if (per_cu
->is_debug_types
)
9648 struct signatured_type
*sig_type
=
9649 (struct signatured_type
*) per_cu
;
9651 sprintf (buf
, "TU %s at offset %s",
9652 hex_string (sig_type
->signature
),
9653 sect_offset_str (per_cu
->sect_off
));
9654 /* There can be 100s of TUs.
9655 Only print them in verbose mode. */
9656 debug_print_threshold
= 2;
9660 sprintf (buf
, "CU at offset %s",
9661 sect_offset_str (per_cu
->sect_off
));
9662 debug_print_threshold
= 1;
9665 if (dwarf_read_debug
>= debug_print_threshold
)
9666 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9668 if (per_cu
->is_debug_types
)
9669 process_full_type_unit (per_cu
, item
->pretend_language
);
9671 process_full_comp_unit (per_cu
, item
->pretend_language
);
9673 if (dwarf_read_debug
>= debug_print_threshold
)
9674 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9677 item
->per_cu
->queued
= 0;
9678 next_item
= item
->next
;
9682 dwarf2_queue_tail
= NULL
;
9684 if (dwarf_read_debug
)
9686 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9687 objfile_name (dwarf2_per_objfile
->objfile
));
9691 /* Read in full symbols for PST, and anything it depends on. */
9694 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9696 struct dwarf2_per_cu_data
*per_cu
;
9702 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9703 if (!pst
->dependencies
[i
]->readin
9704 && pst
->dependencies
[i
]->user
== NULL
)
9706 /* Inform about additional files that need to be read in. */
9709 /* FIXME: i18n: Need to make this a single string. */
9710 fputs_filtered (" ", gdb_stdout
);
9712 fputs_filtered ("and ", gdb_stdout
);
9714 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9715 wrap_here (""); /* Flush output. */
9716 gdb_flush (gdb_stdout
);
9718 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9721 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9725 /* It's an include file, no symbols to read for it.
9726 Everything is in the parent symtab. */
9731 dw2_do_instantiate_symtab (per_cu
, false);
9734 /* Trivial hash function for die_info: the hash value of a DIE
9735 is its offset in .debug_info for this objfile. */
9738 die_hash (const void *item
)
9740 const struct die_info
*die
= (const struct die_info
*) item
;
9742 return to_underlying (die
->sect_off
);
9745 /* Trivial comparison function for die_info structures: two DIEs
9746 are equal if they have the same offset. */
9749 die_eq (const void *item_lhs
, const void *item_rhs
)
9751 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9752 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9754 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9757 /* die_reader_func for load_full_comp_unit.
9758 This is identical to read_signatured_type_reader,
9759 but is kept separate for now. */
9762 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9763 const gdb_byte
*info_ptr
,
9764 struct die_info
*comp_unit_die
,
9768 struct dwarf2_cu
*cu
= reader
->cu
;
9769 enum language
*language_ptr
= (enum language
*) data
;
9771 gdb_assert (cu
->die_hash
== NULL
);
9773 htab_create_alloc_ex (cu
->header
.length
/ 12,
9777 &cu
->comp_unit_obstack
,
9778 hashtab_obstack_allocate
,
9779 dummy_obstack_deallocate
);
9782 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9783 &info_ptr
, comp_unit_die
);
9784 cu
->dies
= comp_unit_die
;
9785 /* comp_unit_die is not stored in die_hash, no need. */
9787 /* We try not to read any attributes in this function, because not
9788 all CUs needed for references have been loaded yet, and symbol
9789 table processing isn't initialized. But we have to set the CU language,
9790 or we won't be able to build types correctly.
9791 Similarly, if we do not read the producer, we can not apply
9792 producer-specific interpretation. */
9793 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9796 /* Load the DIEs associated with PER_CU into memory. */
9799 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9801 enum language pretend_language
)
9803 gdb_assert (! this_cu
->is_debug_types
);
9805 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, skip_partial
,
9806 load_full_comp_unit_reader
, &pretend_language
);
9809 /* Add a DIE to the delayed physname list. */
9812 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9813 const char *name
, struct die_info
*die
,
9814 struct dwarf2_cu
*cu
)
9816 struct delayed_method_info mi
;
9818 mi
.fnfield_index
= fnfield_index
;
9822 cu
->method_list
.push_back (mi
);
9825 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9826 "const" / "volatile". If so, decrements LEN by the length of the
9827 modifier and return true. Otherwise return false. */
9831 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9833 size_t mod_len
= sizeof (mod
) - 1;
9834 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9842 /* Compute the physnames of any methods on the CU's method list.
9844 The computation of method physnames is delayed in order to avoid the
9845 (bad) condition that one of the method's formal parameters is of an as yet
9849 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9851 /* Only C++ delays computing physnames. */
9852 if (cu
->method_list
.empty ())
9854 gdb_assert (cu
->language
== language_cplus
);
9856 for (const delayed_method_info
&mi
: cu
->method_list
)
9858 const char *physname
;
9859 struct fn_fieldlist
*fn_flp
9860 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9861 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9862 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9863 = physname
? physname
: "";
9865 /* Since there's no tag to indicate whether a method is a
9866 const/volatile overload, extract that information out of the
9868 if (physname
!= NULL
)
9870 size_t len
= strlen (physname
);
9874 if (physname
[len
] == ')') /* shortcut */
9876 else if (check_modifier (physname
, len
, " const"))
9877 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9878 else if (check_modifier (physname
, len
, " volatile"))
9879 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9886 /* The list is no longer needed. */
9887 cu
->method_list
.clear ();
9890 /* Go objects should be embedded in a DW_TAG_module DIE,
9891 and it's not clear if/how imported objects will appear.
9892 To keep Go support simple until that's worked out,
9893 go back through what we've read and create something usable.
9894 We could do this while processing each DIE, and feels kinda cleaner,
9895 but that way is more invasive.
9896 This is to, for example, allow the user to type "p var" or "b main"
9897 without having to specify the package name, and allow lookups
9898 of module.object to work in contexts that use the expression
9902 fixup_go_packaging (struct dwarf2_cu
*cu
)
9904 char *package_name
= NULL
;
9905 struct pending
*list
;
9908 for (list
= *cu
->get_builder ()->get_global_symbols ();
9912 for (i
= 0; i
< list
->nsyms
; ++i
)
9914 struct symbol
*sym
= list
->symbol
[i
];
9916 if (SYMBOL_LANGUAGE (sym
) == language_go
9917 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9919 char *this_package_name
= go_symbol_package_name (sym
);
9921 if (this_package_name
== NULL
)
9923 if (package_name
== NULL
)
9924 package_name
= this_package_name
;
9927 struct objfile
*objfile
9928 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9929 if (strcmp (package_name
, this_package_name
) != 0)
9930 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9931 (symbol_symtab (sym
) != NULL
9932 ? symtab_to_filename_for_display
9933 (symbol_symtab (sym
))
9934 : objfile_name (objfile
)),
9935 this_package_name
, package_name
);
9936 xfree (this_package_name
);
9942 if (package_name
!= NULL
)
9944 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9945 const char *saved_package_name
9946 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
);
9947 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9948 saved_package_name
);
9951 sym
= allocate_symbol (objfile
);
9952 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
9953 SYMBOL_SET_NAMES (sym
, saved_package_name
, false, objfile
);
9954 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9955 e.g., "main" finds the "main" module and not C's main(). */
9956 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9957 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9958 SYMBOL_TYPE (sym
) = type
;
9960 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9962 xfree (package_name
);
9966 /* Allocate a fully-qualified name consisting of the two parts on the
9970 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9972 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9975 /* A helper that allocates a struct discriminant_info to attach to a
9978 static struct discriminant_info
*
9979 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9982 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9983 gdb_assert (discriminant_index
== -1
9984 || (discriminant_index
>= 0
9985 && discriminant_index
< TYPE_NFIELDS (type
)));
9986 gdb_assert (default_index
== -1
9987 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9989 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9991 struct discriminant_info
*disc
9992 = ((struct discriminant_info
*)
9994 offsetof (struct discriminant_info
, discriminants
)
9995 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9996 disc
->default_index
= default_index
;
9997 disc
->discriminant_index
= discriminant_index
;
9999 struct dynamic_prop prop
;
10000 prop
.kind
= PROP_UNDEFINED
;
10001 prop
.data
.baton
= disc
;
10003 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
10008 /* Some versions of rustc emitted enums in an unusual way.
10010 Ordinary enums were emitted as unions. The first element of each
10011 structure in the union was named "RUST$ENUM$DISR". This element
10012 held the discriminant.
10014 These versions of Rust also implemented the "non-zero"
10015 optimization. When the enum had two values, and one is empty and
10016 the other holds a pointer that cannot be zero, the pointer is used
10017 as the discriminant, with a zero value meaning the empty variant.
10018 Here, the union's first member is of the form
10019 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
10020 where the fieldnos are the indices of the fields that should be
10021 traversed in order to find the field (which may be several fields deep)
10022 and the variantname is the name of the variant of the case when the
10025 This function recognizes whether TYPE is of one of these forms,
10026 and, if so, smashes it to be a variant type. */
10029 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
10031 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
10033 /* We don't need to deal with empty enums. */
10034 if (TYPE_NFIELDS (type
) == 0)
10037 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
10038 if (TYPE_NFIELDS (type
) == 1
10039 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
10041 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
10043 /* Decode the field name to find the offset of the
10045 ULONGEST bit_offset
= 0;
10046 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
10047 while (name
[0] >= '0' && name
[0] <= '9')
10050 unsigned long index
= strtoul (name
, &tail
, 10);
10053 || index
>= TYPE_NFIELDS (field_type
)
10054 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
10055 != FIELD_LOC_KIND_BITPOS
))
10057 complaint (_("Could not parse Rust enum encoding string \"%s\""
10059 TYPE_FIELD_NAME (type
, 0),
10060 objfile_name (objfile
));
10065 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10066 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10069 /* Make a union to hold the variants. */
10070 struct type
*union_type
= alloc_type (objfile
);
10071 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10072 TYPE_NFIELDS (union_type
) = 3;
10073 TYPE_FIELDS (union_type
)
10074 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10075 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10076 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10078 /* Put the discriminant must at index 0. */
10079 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10080 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10081 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10082 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10084 /* The order of fields doesn't really matter, so put the real
10085 field at index 1 and the data-less field at index 2. */
10086 struct discriminant_info
*disc
10087 = alloc_discriminant_info (union_type
, 0, 1);
10088 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10089 TYPE_FIELD_NAME (union_type
, 1)
10090 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10091 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10092 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10093 TYPE_FIELD_NAME (union_type
, 1));
10095 const char *dataless_name
10096 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10098 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10100 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10101 /* NAME points into the original discriminant name, which
10102 already has the correct lifetime. */
10103 TYPE_FIELD_NAME (union_type
, 2) = name
;
10104 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10105 disc
->discriminants
[2] = 0;
10107 /* Smash this type to be a structure type. We have to do this
10108 because the type has already been recorded. */
10109 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10110 TYPE_NFIELDS (type
) = 1;
10112 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10114 /* Install the variant part. */
10115 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10116 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10117 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10119 /* A union with a single anonymous field is probably an old-style
10120 univariant enum. */
10121 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
10123 /* Smash this type to be a structure type. We have to do this
10124 because the type has already been recorded. */
10125 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10127 /* Make a union to hold the variants. */
10128 struct type
*union_type
= alloc_type (objfile
);
10129 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10130 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10131 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10132 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10133 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10135 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10136 const char *variant_name
10137 = rust_last_path_segment (TYPE_NAME (field_type
));
10138 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10139 TYPE_NAME (field_type
)
10140 = rust_fully_qualify (&objfile
->objfile_obstack
,
10141 TYPE_NAME (type
), variant_name
);
10143 /* Install the union in the outer struct type. */
10144 TYPE_NFIELDS (type
) = 1;
10146 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10147 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10148 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10149 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10151 alloc_discriminant_info (union_type
, -1, 0);
10155 struct type
*disr_type
= nullptr;
10156 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10158 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10160 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10162 /* All fields of a true enum will be structs. */
10165 else if (TYPE_NFIELDS (disr_type
) == 0)
10167 /* Could be data-less variant, so keep going. */
10168 disr_type
= nullptr;
10170 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10171 "RUST$ENUM$DISR") != 0)
10173 /* Not a Rust enum. */
10183 /* If we got here without a discriminant, then it's probably
10185 if (disr_type
== nullptr)
10188 /* Smash this type to be a structure type. We have to do this
10189 because the type has already been recorded. */
10190 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10192 /* Make a union to hold the variants. */
10193 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10194 struct type
*union_type
= alloc_type (objfile
);
10195 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10196 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10197 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10198 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10199 TYPE_FIELDS (union_type
)
10200 = (struct field
*) TYPE_ZALLOC (union_type
,
10201 (TYPE_NFIELDS (union_type
)
10202 * sizeof (struct field
)));
10204 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10205 TYPE_NFIELDS (type
) * sizeof (struct field
));
10207 /* Install the discriminant at index 0 in the union. */
10208 TYPE_FIELD (union_type
, 0) = *disr_field
;
10209 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10210 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10212 /* Install the union in the outer struct type. */
10213 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10214 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10215 TYPE_NFIELDS (type
) = 1;
10217 /* Set the size and offset of the union type. */
10218 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10220 /* We need a way to find the correct discriminant given a
10221 variant name. For convenience we build a map here. */
10222 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10223 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10224 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10226 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10229 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10230 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10234 int n_fields
= TYPE_NFIELDS (union_type
);
10235 struct discriminant_info
*disc
10236 = alloc_discriminant_info (union_type
, 0, -1);
10237 /* Skip the discriminant here. */
10238 for (int i
= 1; i
< n_fields
; ++i
)
10240 /* Find the final word in the name of this variant's type.
10241 That name can be used to look up the correct
10243 const char *variant_name
10244 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10247 auto iter
= discriminant_map
.find (variant_name
);
10248 if (iter
!= discriminant_map
.end ())
10249 disc
->discriminants
[i
] = iter
->second
;
10251 /* Remove the discriminant field, if it exists. */
10252 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10253 if (TYPE_NFIELDS (sub_type
) > 0)
10255 --TYPE_NFIELDS (sub_type
);
10256 ++TYPE_FIELDS (sub_type
);
10258 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10259 TYPE_NAME (sub_type
)
10260 = rust_fully_qualify (&objfile
->objfile_obstack
,
10261 TYPE_NAME (type
), variant_name
);
10266 /* Rewrite some Rust unions to be structures with variants parts. */
10269 rust_union_quirks (struct dwarf2_cu
*cu
)
10271 gdb_assert (cu
->language
== language_rust
);
10272 for (type
*type_
: cu
->rust_unions
)
10273 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10274 /* We don't need this any more. */
10275 cu
->rust_unions
.clear ();
10278 /* Return the symtab for PER_CU. This works properly regardless of
10279 whether we're using the index or psymtabs. */
10281 static struct compunit_symtab
*
10282 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10284 return (per_cu
->dwarf2_per_objfile
->using_index
10285 ? per_cu
->v
.quick
->compunit_symtab
10286 : per_cu
->v
.psymtab
->compunit_symtab
);
10289 /* A helper function for computing the list of all symbol tables
10290 included by PER_CU. */
10293 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
10294 htab_t all_children
, htab_t all_type_symtabs
,
10295 struct dwarf2_per_cu_data
*per_cu
,
10296 struct compunit_symtab
*immediate_parent
)
10299 struct compunit_symtab
*cust
;
10301 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10304 /* This inclusion and its children have been processed. */
10309 /* Only add a CU if it has a symbol table. */
10310 cust
= get_compunit_symtab (per_cu
);
10313 /* If this is a type unit only add its symbol table if we haven't
10314 seen it yet (type unit per_cu's can share symtabs). */
10315 if (per_cu
->is_debug_types
)
10317 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10321 result
->push_back (cust
);
10322 if (cust
->user
== NULL
)
10323 cust
->user
= immediate_parent
;
10328 result
->push_back (cust
);
10329 if (cust
->user
== NULL
)
10330 cust
->user
= immediate_parent
;
10334 if (!per_cu
->imported_symtabs_empty ())
10335 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10337 recursively_compute_inclusions (result
, all_children
,
10338 all_type_symtabs
, ptr
, cust
);
10342 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10346 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10348 gdb_assert (! per_cu
->is_debug_types
);
10350 if (!per_cu
->imported_symtabs_empty ())
10353 std::vector
<compunit_symtab
*> result_symtabs
;
10354 htab_t all_children
, all_type_symtabs
;
10355 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10357 /* If we don't have a symtab, we can just skip this case. */
10361 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10362 NULL
, xcalloc
, xfree
);
10363 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10364 NULL
, xcalloc
, xfree
);
10366 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10368 recursively_compute_inclusions (&result_symtabs
, all_children
,
10369 all_type_symtabs
, ptr
, cust
);
10372 /* Now we have a transitive closure of all the included symtabs. */
10373 len
= result_symtabs
.size ();
10375 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10376 struct compunit_symtab
*, len
+ 1);
10377 memcpy (cust
->includes
, result_symtabs
.data (),
10378 len
* sizeof (compunit_symtab
*));
10379 cust
->includes
[len
] = NULL
;
10381 htab_delete (all_children
);
10382 htab_delete (all_type_symtabs
);
10386 /* Compute the 'includes' field for the symtabs of all the CUs we just
10390 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10392 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10394 if (! iter
->is_debug_types
)
10395 compute_compunit_symtab_includes (iter
);
10398 dwarf2_per_objfile
->just_read_cus
.clear ();
10401 /* Generate full symbol information for PER_CU, whose DIEs have
10402 already been loaded into memory. */
10405 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10406 enum language pretend_language
)
10408 struct dwarf2_cu
*cu
= per_cu
->cu
;
10409 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10410 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10411 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10412 CORE_ADDR lowpc
, highpc
;
10413 struct compunit_symtab
*cust
;
10414 CORE_ADDR baseaddr
;
10415 struct block
*static_block
;
10418 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10420 /* Clear the list here in case something was left over. */
10421 cu
->method_list
.clear ();
10423 cu
->language
= pretend_language
;
10424 cu
->language_defn
= language_def (cu
->language
);
10426 /* Do line number decoding in read_file_scope () */
10427 process_die (cu
->dies
, cu
);
10429 /* For now fudge the Go package. */
10430 if (cu
->language
== language_go
)
10431 fixup_go_packaging (cu
);
10433 /* Now that we have processed all the DIEs in the CU, all the types
10434 should be complete, and it should now be safe to compute all of the
10436 compute_delayed_physnames (cu
);
10438 if (cu
->language
== language_rust
)
10439 rust_union_quirks (cu
);
10441 /* Some compilers don't define a DW_AT_high_pc attribute for the
10442 compilation unit. If the DW_AT_high_pc is missing, synthesize
10443 it, by scanning the DIE's below the compilation unit. */
10444 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10446 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10447 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10449 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10450 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10451 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10452 addrmap to help ensure it has an accurate map of pc values belonging to
10454 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10456 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10457 SECT_OFF_TEXT (objfile
),
10462 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10464 /* Set symtab language to language from DW_AT_language. If the
10465 compilation is from a C file generated by language preprocessors, do
10466 not set the language if it was already deduced by start_subfile. */
10467 if (!(cu
->language
== language_c
10468 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10469 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10471 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10472 produce DW_AT_location with location lists but it can be possibly
10473 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10474 there were bugs in prologue debug info, fixed later in GCC-4.5
10475 by "unwind info for epilogues" patch (which is not directly related).
10477 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10478 needed, it would be wrong due to missing DW_AT_producer there.
10480 Still one can confuse GDB by using non-standard GCC compilation
10481 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10483 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10484 cust
->locations_valid
= 1;
10486 if (gcc_4_minor
>= 5)
10487 cust
->epilogue_unwind_valid
= 1;
10489 cust
->call_site_htab
= cu
->call_site_htab
;
10492 if (dwarf2_per_objfile
->using_index
)
10493 per_cu
->v
.quick
->compunit_symtab
= cust
;
10496 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10497 pst
->compunit_symtab
= cust
;
10501 /* Push it for inclusion processing later. */
10502 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10504 /* Not needed any more. */
10505 cu
->reset_builder ();
10508 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10509 already been loaded into memory. */
10512 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10513 enum language pretend_language
)
10515 struct dwarf2_cu
*cu
= per_cu
->cu
;
10516 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10517 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10518 struct compunit_symtab
*cust
;
10519 struct signatured_type
*sig_type
;
10521 gdb_assert (per_cu
->is_debug_types
);
10522 sig_type
= (struct signatured_type
*) per_cu
;
10524 /* Clear the list here in case something was left over. */
10525 cu
->method_list
.clear ();
10527 cu
->language
= pretend_language
;
10528 cu
->language_defn
= language_def (cu
->language
);
10530 /* The symbol tables are set up in read_type_unit_scope. */
10531 process_die (cu
->dies
, cu
);
10533 /* For now fudge the Go package. */
10534 if (cu
->language
== language_go
)
10535 fixup_go_packaging (cu
);
10537 /* Now that we have processed all the DIEs in the CU, all the types
10538 should be complete, and it should now be safe to compute all of the
10540 compute_delayed_physnames (cu
);
10542 if (cu
->language
== language_rust
)
10543 rust_union_quirks (cu
);
10545 /* TUs share symbol tables.
10546 If this is the first TU to use this symtab, complete the construction
10547 of it with end_expandable_symtab. Otherwise, complete the addition of
10548 this TU's symbols to the existing symtab. */
10549 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10551 buildsym_compunit
*builder
= cu
->get_builder ();
10552 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10553 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10557 /* Set symtab language to language from DW_AT_language. If the
10558 compilation is from a C file generated by language preprocessors,
10559 do not set the language if it was already deduced by
10561 if (!(cu
->language
== language_c
10562 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10563 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10568 cu
->get_builder ()->augment_type_symtab ();
10569 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10572 if (dwarf2_per_objfile
->using_index
)
10573 per_cu
->v
.quick
->compunit_symtab
= cust
;
10576 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10577 pst
->compunit_symtab
= cust
;
10581 /* Not needed any more. */
10582 cu
->reset_builder ();
10585 /* Process an imported unit DIE. */
10588 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10590 struct attribute
*attr
;
10592 /* For now we don't handle imported units in type units. */
10593 if (cu
->per_cu
->is_debug_types
)
10595 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10596 " supported in type units [in module %s]"),
10597 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10600 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10603 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10604 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10605 dwarf2_per_cu_data
*per_cu
10606 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10607 cu
->per_cu
->dwarf2_per_objfile
);
10609 /* If necessary, add it to the queue and load its DIEs. */
10610 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10611 load_full_comp_unit (per_cu
, false, cu
->language
);
10613 cu
->per_cu
->imported_symtabs_push (per_cu
);
10617 /* RAII object that represents a process_die scope: i.e.,
10618 starts/finishes processing a DIE. */
10619 class process_die_scope
10622 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10623 : m_die (die
), m_cu (cu
)
10625 /* We should only be processing DIEs not already in process. */
10626 gdb_assert (!m_die
->in_process
);
10627 m_die
->in_process
= true;
10630 ~process_die_scope ()
10632 m_die
->in_process
= false;
10634 /* If we're done processing the DIE for the CU that owns the line
10635 header, we don't need the line header anymore. */
10636 if (m_cu
->line_header_die_owner
== m_die
)
10638 delete m_cu
->line_header
;
10639 m_cu
->line_header
= NULL
;
10640 m_cu
->line_header_die_owner
= NULL
;
10649 /* Process a die and its children. */
10652 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10654 process_die_scope
scope (die
, cu
);
10658 case DW_TAG_padding
:
10660 case DW_TAG_compile_unit
:
10661 case DW_TAG_partial_unit
:
10662 read_file_scope (die
, cu
);
10664 case DW_TAG_type_unit
:
10665 read_type_unit_scope (die
, cu
);
10667 case DW_TAG_subprogram
:
10668 /* Nested subprograms in Fortran get a prefix. */
10669 if (cu
->language
== language_fortran
10670 && die
->parent
!= NULL
10671 && die
->parent
->tag
== DW_TAG_subprogram
)
10672 cu
->processing_has_namespace_info
= true;
10673 /* Fall through. */
10674 case DW_TAG_inlined_subroutine
:
10675 read_func_scope (die
, cu
);
10677 case DW_TAG_lexical_block
:
10678 case DW_TAG_try_block
:
10679 case DW_TAG_catch_block
:
10680 read_lexical_block_scope (die
, cu
);
10682 case DW_TAG_call_site
:
10683 case DW_TAG_GNU_call_site
:
10684 read_call_site_scope (die
, cu
);
10686 case DW_TAG_class_type
:
10687 case DW_TAG_interface_type
:
10688 case DW_TAG_structure_type
:
10689 case DW_TAG_union_type
:
10690 process_structure_scope (die
, cu
);
10692 case DW_TAG_enumeration_type
:
10693 process_enumeration_scope (die
, cu
);
10696 /* These dies have a type, but processing them does not create
10697 a symbol or recurse to process the children. Therefore we can
10698 read them on-demand through read_type_die. */
10699 case DW_TAG_subroutine_type
:
10700 case DW_TAG_set_type
:
10701 case DW_TAG_array_type
:
10702 case DW_TAG_pointer_type
:
10703 case DW_TAG_ptr_to_member_type
:
10704 case DW_TAG_reference_type
:
10705 case DW_TAG_rvalue_reference_type
:
10706 case DW_TAG_string_type
:
10709 case DW_TAG_base_type
:
10710 case DW_TAG_subrange_type
:
10711 case DW_TAG_typedef
:
10712 /* Add a typedef symbol for the type definition, if it has a
10714 new_symbol (die
, read_type_die (die
, cu
), cu
);
10716 case DW_TAG_common_block
:
10717 read_common_block (die
, cu
);
10719 case DW_TAG_common_inclusion
:
10721 case DW_TAG_namespace
:
10722 cu
->processing_has_namespace_info
= true;
10723 read_namespace (die
, cu
);
10725 case DW_TAG_module
:
10726 cu
->processing_has_namespace_info
= true;
10727 read_module (die
, cu
);
10729 case DW_TAG_imported_declaration
:
10730 cu
->processing_has_namespace_info
= true;
10731 if (read_namespace_alias (die
, cu
))
10733 /* The declaration is not a global namespace alias. */
10734 /* Fall through. */
10735 case DW_TAG_imported_module
:
10736 cu
->processing_has_namespace_info
= true;
10737 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10738 || cu
->language
!= language_fortran
))
10739 complaint (_("Tag '%s' has unexpected children"),
10740 dwarf_tag_name (die
->tag
));
10741 read_import_statement (die
, cu
);
10744 case DW_TAG_imported_unit
:
10745 process_imported_unit_die (die
, cu
);
10748 case DW_TAG_variable
:
10749 read_variable (die
, cu
);
10753 new_symbol (die
, NULL
, cu
);
10758 /* DWARF name computation. */
10760 /* A helper function for dwarf2_compute_name which determines whether DIE
10761 needs to have the name of the scope prepended to the name listed in the
10765 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10767 struct attribute
*attr
;
10771 case DW_TAG_namespace
:
10772 case DW_TAG_typedef
:
10773 case DW_TAG_class_type
:
10774 case DW_TAG_interface_type
:
10775 case DW_TAG_structure_type
:
10776 case DW_TAG_union_type
:
10777 case DW_TAG_enumeration_type
:
10778 case DW_TAG_enumerator
:
10779 case DW_TAG_subprogram
:
10780 case DW_TAG_inlined_subroutine
:
10781 case DW_TAG_member
:
10782 case DW_TAG_imported_declaration
:
10785 case DW_TAG_variable
:
10786 case DW_TAG_constant
:
10787 /* We only need to prefix "globally" visible variables. These include
10788 any variable marked with DW_AT_external or any variable that
10789 lives in a namespace. [Variables in anonymous namespaces
10790 require prefixing, but they are not DW_AT_external.] */
10792 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10794 struct dwarf2_cu
*spec_cu
= cu
;
10796 return die_needs_namespace (die_specification (die
, &spec_cu
),
10800 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10801 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10802 && die
->parent
->tag
!= DW_TAG_module
)
10804 /* A variable in a lexical block of some kind does not need a
10805 namespace, even though in C++ such variables may be external
10806 and have a mangled name. */
10807 if (die
->parent
->tag
== DW_TAG_lexical_block
10808 || die
->parent
->tag
== DW_TAG_try_block
10809 || die
->parent
->tag
== DW_TAG_catch_block
10810 || die
->parent
->tag
== DW_TAG_subprogram
)
10819 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10820 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10821 defined for the given DIE. */
10823 static struct attribute
*
10824 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10826 struct attribute
*attr
;
10828 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10830 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10835 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10836 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10837 defined for the given DIE. */
10839 static const char *
10840 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10842 const char *linkage_name
;
10844 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10845 if (linkage_name
== NULL
)
10846 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10848 return linkage_name
;
10851 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10852 compute the physname for the object, which include a method's:
10853 - formal parameters (C++),
10854 - receiver type (Go),
10856 The term "physname" is a bit confusing.
10857 For C++, for example, it is the demangled name.
10858 For Go, for example, it's the mangled name.
10860 For Ada, return the DIE's linkage name rather than the fully qualified
10861 name. PHYSNAME is ignored..
10863 The result is allocated on the objfile_obstack and canonicalized. */
10865 static const char *
10866 dwarf2_compute_name (const char *name
,
10867 struct die_info
*die
, struct dwarf2_cu
*cu
,
10870 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10873 name
= dwarf2_name (die
, cu
);
10875 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10876 but otherwise compute it by typename_concat inside GDB.
10877 FIXME: Actually this is not really true, or at least not always true.
10878 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
10879 Fortran names because there is no mangling standard. So new_symbol
10880 will set the demangled name to the result of dwarf2_full_name, and it is
10881 the demangled name that GDB uses if it exists. */
10882 if (cu
->language
== language_ada
10883 || (cu
->language
== language_fortran
&& physname
))
10885 /* For Ada unit, we prefer the linkage name over the name, as
10886 the former contains the exported name, which the user expects
10887 to be able to reference. Ideally, we want the user to be able
10888 to reference this entity using either natural or linkage name,
10889 but we haven't started looking at this enhancement yet. */
10890 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10892 if (linkage_name
!= NULL
)
10893 return linkage_name
;
10896 /* These are the only languages we know how to qualify names in. */
10898 && (cu
->language
== language_cplus
10899 || cu
->language
== language_fortran
|| cu
->language
== language_d
10900 || cu
->language
== language_rust
))
10902 if (die_needs_namespace (die
, cu
))
10904 const char *prefix
;
10905 const char *canonical_name
= NULL
;
10909 prefix
= determine_prefix (die
, cu
);
10910 if (*prefix
!= '\0')
10912 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
10915 buf
.puts (prefixed_name
);
10916 xfree (prefixed_name
);
10921 /* Template parameters may be specified in the DIE's DW_AT_name, or
10922 as children with DW_TAG_template_type_param or
10923 DW_TAG_value_type_param. If the latter, add them to the name
10924 here. If the name already has template parameters, then
10925 skip this step; some versions of GCC emit both, and
10926 it is more efficient to use the pre-computed name.
10928 Something to keep in mind about this process: it is very
10929 unlikely, or in some cases downright impossible, to produce
10930 something that will match the mangled name of a function.
10931 If the definition of the function has the same debug info,
10932 we should be able to match up with it anyway. But fallbacks
10933 using the minimal symbol, for instance to find a method
10934 implemented in a stripped copy of libstdc++, will not work.
10935 If we do not have debug info for the definition, we will have to
10936 match them up some other way.
10938 When we do name matching there is a related problem with function
10939 templates; two instantiated function templates are allowed to
10940 differ only by their return types, which we do not add here. */
10942 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10944 struct attribute
*attr
;
10945 struct die_info
*child
;
10948 die
->building_fullname
= 1;
10950 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10954 const gdb_byte
*bytes
;
10955 struct dwarf2_locexpr_baton
*baton
;
10958 if (child
->tag
!= DW_TAG_template_type_param
10959 && child
->tag
!= DW_TAG_template_value_param
)
10970 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10973 complaint (_("template parameter missing DW_AT_type"));
10974 buf
.puts ("UNKNOWN_TYPE");
10977 type
= die_type (child
, cu
);
10979 if (child
->tag
== DW_TAG_template_type_param
)
10981 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10982 &type_print_raw_options
);
10986 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10989 complaint (_("template parameter missing "
10990 "DW_AT_const_value"));
10991 buf
.puts ("UNKNOWN_VALUE");
10995 dwarf2_const_value_attr (attr
, type
, name
,
10996 &cu
->comp_unit_obstack
, cu
,
10997 &value
, &bytes
, &baton
);
10999 if (TYPE_NOSIGN (type
))
11000 /* GDB prints characters as NUMBER 'CHAR'. If that's
11001 changed, this can use value_print instead. */
11002 c_printchar (value
, type
, &buf
);
11005 struct value_print_options opts
;
11008 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
11012 else if (bytes
!= NULL
)
11014 v
= allocate_value (type
);
11015 memcpy (value_contents_writeable (v
), bytes
,
11016 TYPE_LENGTH (type
));
11019 v
= value_from_longest (type
, value
);
11021 /* Specify decimal so that we do not depend on
11023 get_formatted_print_options (&opts
, 'd');
11025 value_print (v
, &buf
, &opts
);
11030 die
->building_fullname
= 0;
11034 /* Close the argument list, with a space if necessary
11035 (nested templates). */
11036 if (!buf
.empty () && buf
.string ().back () == '>')
11043 /* For C++ methods, append formal parameter type
11044 information, if PHYSNAME. */
11046 if (physname
&& die
->tag
== DW_TAG_subprogram
11047 && cu
->language
== language_cplus
)
11049 struct type
*type
= read_type_die (die
, cu
);
11051 c_type_print_args (type
, &buf
, 1, cu
->language
,
11052 &type_print_raw_options
);
11054 if (cu
->language
== language_cplus
)
11056 /* Assume that an artificial first parameter is
11057 "this", but do not crash if it is not. RealView
11058 marks unnamed (and thus unused) parameters as
11059 artificial; there is no way to differentiate
11061 if (TYPE_NFIELDS (type
) > 0
11062 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11063 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11064 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11066 buf
.puts (" const");
11070 const std::string
&intermediate_name
= buf
.string ();
11072 if (cu
->language
== language_cplus
)
11074 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11075 &objfile
->per_bfd
->storage_obstack
);
11077 /* If we only computed INTERMEDIATE_NAME, or if
11078 INTERMEDIATE_NAME is already canonical, then we need to
11079 copy it to the appropriate obstack. */
11080 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11081 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
11082 intermediate_name
);
11084 name
= canonical_name
;
11091 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11092 If scope qualifiers are appropriate they will be added. The result
11093 will be allocated on the storage_obstack, or NULL if the DIE does
11094 not have a name. NAME may either be from a previous call to
11095 dwarf2_name or NULL.
11097 The output string will be canonicalized (if C++). */
11099 static const char *
11100 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11102 return dwarf2_compute_name (name
, die
, cu
, 0);
11105 /* Construct a physname for the given DIE in CU. NAME may either be
11106 from a previous call to dwarf2_name or NULL. The result will be
11107 allocated on the objfile_objstack or NULL if the DIE does not have a
11110 The output string will be canonicalized (if C++). */
11112 static const char *
11113 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11115 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11116 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11119 /* In this case dwarf2_compute_name is just a shortcut not building anything
11121 if (!die_needs_namespace (die
, cu
))
11122 return dwarf2_compute_name (name
, die
, cu
, 1);
11124 mangled
= dw2_linkage_name (die
, cu
);
11126 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11127 See https://github.com/rust-lang/rust/issues/32925. */
11128 if (cu
->language
== language_rust
&& mangled
!= NULL
11129 && strchr (mangled
, '{') != NULL
)
11132 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11134 gdb::unique_xmalloc_ptr
<char> demangled
;
11135 if (mangled
!= NULL
)
11138 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11140 /* Do nothing (do not demangle the symbol name). */
11142 else if (cu
->language
== language_go
)
11144 /* This is a lie, but we already lie to the caller new_symbol.
11145 new_symbol assumes we return the mangled name.
11146 This just undoes that lie until things are cleaned up. */
11150 /* Use DMGL_RET_DROP for C++ template functions to suppress
11151 their return type. It is easier for GDB users to search
11152 for such functions as `name(params)' than `long name(params)'.
11153 In such case the minimal symbol names do not match the full
11154 symbol names but for template functions there is never a need
11155 to look up their definition from their declaration so
11156 the only disadvantage remains the minimal symbol variant
11157 `long name(params)' does not have the proper inferior type. */
11158 demangled
.reset (gdb_demangle (mangled
,
11159 (DMGL_PARAMS
| DMGL_ANSI
11160 | DMGL_RET_DROP
)));
11163 canon
= demangled
.get ();
11171 if (canon
== NULL
|| check_physname
)
11173 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11175 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11177 /* It may not mean a bug in GDB. The compiler could also
11178 compute DW_AT_linkage_name incorrectly. But in such case
11179 GDB would need to be bug-to-bug compatible. */
11181 complaint (_("Computed physname <%s> does not match demangled <%s> "
11182 "(from linkage <%s>) - DIE at %s [in module %s]"),
11183 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11184 objfile_name (objfile
));
11186 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11187 is available here - over computed PHYSNAME. It is safer
11188 against both buggy GDB and buggy compilers. */
11202 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
11207 /* Inspect DIE in CU for a namespace alias. If one exists, record
11208 a new symbol for it.
11210 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11213 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11215 struct attribute
*attr
;
11217 /* If the die does not have a name, this is not a namespace
11219 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11223 struct die_info
*d
= die
;
11224 struct dwarf2_cu
*imported_cu
= cu
;
11226 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11227 keep inspecting DIEs until we hit the underlying import. */
11228 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11229 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11231 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11235 d
= follow_die_ref (d
, attr
, &imported_cu
);
11236 if (d
->tag
!= DW_TAG_imported_declaration
)
11240 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11242 complaint (_("DIE at %s has too many recursively imported "
11243 "declarations"), sect_offset_str (d
->sect_off
));
11250 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11252 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11253 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11255 /* This declaration is a global namespace alias. Add
11256 a symbol for it whose type is the aliased namespace. */
11257 new_symbol (die
, type
, cu
);
11266 /* Return the using directives repository (global or local?) to use in the
11267 current context for CU.
11269 For Ada, imported declarations can materialize renamings, which *may* be
11270 global. However it is impossible (for now?) in DWARF to distinguish
11271 "external" imported declarations and "static" ones. As all imported
11272 declarations seem to be static in all other languages, make them all CU-wide
11273 global only in Ada. */
11275 static struct using_direct
**
11276 using_directives (struct dwarf2_cu
*cu
)
11278 if (cu
->language
== language_ada
11279 && cu
->get_builder ()->outermost_context_p ())
11280 return cu
->get_builder ()->get_global_using_directives ();
11282 return cu
->get_builder ()->get_local_using_directives ();
11285 /* Read the import statement specified by the given die and record it. */
11288 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11290 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11291 struct attribute
*import_attr
;
11292 struct die_info
*imported_die
, *child_die
;
11293 struct dwarf2_cu
*imported_cu
;
11294 const char *imported_name
;
11295 const char *imported_name_prefix
;
11296 const char *canonical_name
;
11297 const char *import_alias
;
11298 const char *imported_declaration
= NULL
;
11299 const char *import_prefix
;
11300 std::vector
<const char *> excludes
;
11302 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11303 if (import_attr
== NULL
)
11305 complaint (_("Tag '%s' has no DW_AT_import"),
11306 dwarf_tag_name (die
->tag
));
11311 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11312 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11313 if (imported_name
== NULL
)
11315 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11317 The import in the following code:
11331 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11332 <52> DW_AT_decl_file : 1
11333 <53> DW_AT_decl_line : 6
11334 <54> DW_AT_import : <0x75>
11335 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11336 <59> DW_AT_name : B
11337 <5b> DW_AT_decl_file : 1
11338 <5c> DW_AT_decl_line : 2
11339 <5d> DW_AT_type : <0x6e>
11341 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11342 <76> DW_AT_byte_size : 4
11343 <77> DW_AT_encoding : 5 (signed)
11345 imports the wrong die ( 0x75 instead of 0x58 ).
11346 This case will be ignored until the gcc bug is fixed. */
11350 /* Figure out the local name after import. */
11351 import_alias
= dwarf2_name (die
, cu
);
11353 /* Figure out where the statement is being imported to. */
11354 import_prefix
= determine_prefix (die
, cu
);
11356 /* Figure out what the scope of the imported die is and prepend it
11357 to the name of the imported die. */
11358 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11360 if (imported_die
->tag
!= DW_TAG_namespace
11361 && imported_die
->tag
!= DW_TAG_module
)
11363 imported_declaration
= imported_name
;
11364 canonical_name
= imported_name_prefix
;
11366 else if (strlen (imported_name_prefix
) > 0)
11367 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11368 imported_name_prefix
,
11369 (cu
->language
== language_d
? "." : "::"),
11370 imported_name
, (char *) NULL
);
11372 canonical_name
= imported_name
;
11374 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11375 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11376 child_die
= sibling_die (child_die
))
11378 /* DWARF-4: A Fortran use statement with a “rename list” may be
11379 represented by an imported module entry with an import attribute
11380 referring to the module and owned entries corresponding to those
11381 entities that are renamed as part of being imported. */
11383 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11385 complaint (_("child DW_TAG_imported_declaration expected "
11386 "- DIE at %s [in module %s]"),
11387 sect_offset_str (child_die
->sect_off
),
11388 objfile_name (objfile
));
11392 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11393 if (import_attr
== NULL
)
11395 complaint (_("Tag '%s' has no DW_AT_import"),
11396 dwarf_tag_name (child_die
->tag
));
11401 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11403 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11404 if (imported_name
== NULL
)
11406 complaint (_("child DW_TAG_imported_declaration has unknown "
11407 "imported name - DIE at %s [in module %s]"),
11408 sect_offset_str (child_die
->sect_off
),
11409 objfile_name (objfile
));
11413 excludes
.push_back (imported_name
);
11415 process_die (child_die
, cu
);
11418 add_using_directive (using_directives (cu
),
11422 imported_declaration
,
11425 &objfile
->objfile_obstack
);
11428 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11429 types, but gives them a size of zero. Starting with version 14,
11430 ICC is compatible with GCC. */
11433 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11435 if (!cu
->checked_producer
)
11436 check_producer (cu
);
11438 return cu
->producer_is_icc_lt_14
;
11441 /* ICC generates a DW_AT_type for C void functions. This was observed on
11442 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11443 which says that void functions should not have a DW_AT_type. */
11446 producer_is_icc (struct dwarf2_cu
*cu
)
11448 if (!cu
->checked_producer
)
11449 check_producer (cu
);
11451 return cu
->producer_is_icc
;
11454 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11455 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11456 this, it was first present in GCC release 4.3.0. */
11459 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11461 if (!cu
->checked_producer
)
11462 check_producer (cu
);
11464 return cu
->producer_is_gcc_lt_4_3
;
11467 static file_and_directory
11468 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11470 file_and_directory res
;
11472 /* Find the filename. Do not use dwarf2_name here, since the filename
11473 is not a source language identifier. */
11474 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11475 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11477 if (res
.comp_dir
== NULL
11478 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11479 && IS_ABSOLUTE_PATH (res
.name
))
11481 res
.comp_dir_storage
= ldirname (res
.name
);
11482 if (!res
.comp_dir_storage
.empty ())
11483 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11485 if (res
.comp_dir
!= NULL
)
11487 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11488 directory, get rid of it. */
11489 const char *cp
= strchr (res
.comp_dir
, ':');
11491 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11492 res
.comp_dir
= cp
+ 1;
11495 if (res
.name
== NULL
)
11496 res
.name
= "<unknown>";
11501 /* Handle DW_AT_stmt_list for a compilation unit.
11502 DIE is the DW_TAG_compile_unit die for CU.
11503 COMP_DIR is the compilation directory. LOWPC is passed to
11504 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11507 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11508 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11510 struct dwarf2_per_objfile
*dwarf2_per_objfile
11511 = cu
->per_cu
->dwarf2_per_objfile
;
11512 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11513 struct attribute
*attr
;
11514 struct line_header line_header_local
;
11515 hashval_t line_header_local_hash
;
11517 int decode_mapping
;
11519 gdb_assert (! cu
->per_cu
->is_debug_types
);
11521 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11525 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11527 /* The line header hash table is only created if needed (it exists to
11528 prevent redundant reading of the line table for partial_units).
11529 If we're given a partial_unit, we'll need it. If we're given a
11530 compile_unit, then use the line header hash table if it's already
11531 created, but don't create one just yet. */
11533 if (dwarf2_per_objfile
->line_header_hash
== NULL
11534 && die
->tag
== DW_TAG_partial_unit
)
11536 dwarf2_per_objfile
->line_header_hash
11537 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11538 line_header_eq_voidp
,
11539 free_line_header_voidp
,
11540 &objfile
->objfile_obstack
,
11541 hashtab_obstack_allocate
,
11542 dummy_obstack_deallocate
);
11545 line_header_local
.sect_off
= line_offset
;
11546 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11547 line_header_local_hash
= line_header_hash (&line_header_local
);
11548 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11550 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11551 &line_header_local
,
11552 line_header_local_hash
, NO_INSERT
);
11554 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11555 is not present in *SLOT (since if there is something in *SLOT then
11556 it will be for a partial_unit). */
11557 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11559 gdb_assert (*slot
!= NULL
);
11560 cu
->line_header
= (struct line_header
*) *slot
;
11565 /* dwarf_decode_line_header does not yet provide sufficient information.
11566 We always have to call also dwarf_decode_lines for it. */
11567 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11571 cu
->line_header
= lh
.release ();
11572 cu
->line_header_die_owner
= die
;
11574 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11578 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11579 &line_header_local
,
11580 line_header_local_hash
, INSERT
);
11581 gdb_assert (slot
!= NULL
);
11583 if (slot
!= NULL
&& *slot
== NULL
)
11585 /* This newly decoded line number information unit will be owned
11586 by line_header_hash hash table. */
11587 *slot
= cu
->line_header
;
11588 cu
->line_header_die_owner
= NULL
;
11592 /* We cannot free any current entry in (*slot) as that struct line_header
11593 may be already used by multiple CUs. Create only temporary decoded
11594 line_header for this CU - it may happen at most once for each line
11595 number information unit. And if we're not using line_header_hash
11596 then this is what we want as well. */
11597 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11599 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11600 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11605 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11608 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11610 struct dwarf2_per_objfile
*dwarf2_per_objfile
11611 = cu
->per_cu
->dwarf2_per_objfile
;
11612 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11613 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11614 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11615 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11616 struct attribute
*attr
;
11617 struct die_info
*child_die
;
11618 CORE_ADDR baseaddr
;
11620 prepare_one_comp_unit (cu
, die
, cu
->language
);
11621 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11623 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11625 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11626 from finish_block. */
11627 if (lowpc
== ((CORE_ADDR
) -1))
11629 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11631 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11633 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11634 standardised yet. As a workaround for the language detection we fall
11635 back to the DW_AT_producer string. */
11636 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11637 cu
->language
= language_opencl
;
11639 /* Similar hack for Go. */
11640 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11641 set_cu_language (DW_LANG_Go
, cu
);
11643 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11645 /* Decode line number information if present. We do this before
11646 processing child DIEs, so that the line header table is available
11647 for DW_AT_decl_file. */
11648 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11650 /* Process all dies in compilation unit. */
11651 if (die
->child
!= NULL
)
11653 child_die
= die
->child
;
11654 while (child_die
&& child_die
->tag
)
11656 process_die (child_die
, cu
);
11657 child_die
= sibling_die (child_die
);
11661 /* Decode macro information, if present. Dwarf 2 macro information
11662 refers to information in the line number info statement program
11663 header, so we can only read it if we've read the header
11665 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11667 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11668 if (attr
&& cu
->line_header
)
11670 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11671 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11673 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11677 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11678 if (attr
&& cu
->line_header
)
11680 unsigned int macro_offset
= DW_UNSND (attr
);
11682 dwarf_decode_macros (cu
, macro_offset
, 0);
11688 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11690 struct type_unit_group
*tu_group
;
11692 struct attribute
*attr
;
11694 struct signatured_type
*sig_type
;
11696 gdb_assert (per_cu
->is_debug_types
);
11697 sig_type
= (struct signatured_type
*) per_cu
;
11699 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11701 /* If we're using .gdb_index (includes -readnow) then
11702 per_cu->type_unit_group may not have been set up yet. */
11703 if (sig_type
->type_unit_group
== NULL
)
11704 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11705 tu_group
= sig_type
->type_unit_group
;
11707 /* If we've already processed this stmt_list there's no real need to
11708 do it again, we could fake it and just recreate the part we need
11709 (file name,index -> symtab mapping). If data shows this optimization
11710 is useful we can do it then. */
11711 first_time
= tu_group
->compunit_symtab
== NULL
;
11713 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11718 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11719 lh
= dwarf_decode_line_header (line_offset
, this);
11724 start_symtab ("", NULL
, 0);
11727 gdb_assert (tu_group
->symtabs
== NULL
);
11728 gdb_assert (m_builder
== nullptr);
11729 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11730 m_builder
.reset (new struct buildsym_compunit
11731 (COMPUNIT_OBJFILE (cust
), "",
11732 COMPUNIT_DIRNAME (cust
),
11733 compunit_language (cust
),
11739 line_header
= lh
.release ();
11740 line_header_die_owner
= die
;
11744 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11746 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11747 still initializing it, and our caller (a few levels up)
11748 process_full_type_unit still needs to know if this is the first
11751 tu_group
->num_symtabs
= line_header
->file_names_size ();
11752 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11753 line_header
->file_names_size ());
11755 auto &file_names
= line_header
->file_names ();
11756 for (i
= 0; i
< file_names
.size (); ++i
)
11758 file_entry
&fe
= file_names
[i
];
11759 dwarf2_start_subfile (this, fe
.name
,
11760 fe
.include_dir (line_header
));
11761 buildsym_compunit
*b
= get_builder ();
11762 if (b
->get_current_subfile ()->symtab
== NULL
)
11764 /* NOTE: start_subfile will recognize when it's been
11765 passed a file it has already seen. So we can't
11766 assume there's a simple mapping from
11767 cu->line_header->file_names to subfiles, plus
11768 cu->line_header->file_names may contain dups. */
11769 b
->get_current_subfile ()->symtab
11770 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11773 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11774 tu_group
->symtabs
[i
] = fe
.symtab
;
11779 gdb_assert (m_builder
== nullptr);
11780 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11781 m_builder
.reset (new struct buildsym_compunit
11782 (COMPUNIT_OBJFILE (cust
), "",
11783 COMPUNIT_DIRNAME (cust
),
11784 compunit_language (cust
),
11787 auto &file_names
= line_header
->file_names ();
11788 for (i
= 0; i
< file_names
.size (); ++i
)
11790 file_entry
&fe
= file_names
[i
];
11791 fe
.symtab
= tu_group
->symtabs
[i
];
11795 /* The main symtab is allocated last. Type units don't have DW_AT_name
11796 so they don't have a "real" (so to speak) symtab anyway.
11797 There is later code that will assign the main symtab to all symbols
11798 that don't have one. We need to handle the case of a symbol with a
11799 missing symtab (DW_AT_decl_file) anyway. */
11802 /* Process DW_TAG_type_unit.
11803 For TUs we want to skip the first top level sibling if it's not the
11804 actual type being defined by this TU. In this case the first top
11805 level sibling is there to provide context only. */
11808 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11810 struct die_info
*child_die
;
11812 prepare_one_comp_unit (cu
, die
, language_minimal
);
11814 /* Initialize (or reinitialize) the machinery for building symtabs.
11815 We do this before processing child DIEs, so that the line header table
11816 is available for DW_AT_decl_file. */
11817 cu
->setup_type_unit_groups (die
);
11819 if (die
->child
!= NULL
)
11821 child_die
= die
->child
;
11822 while (child_die
&& child_die
->tag
)
11824 process_die (child_die
, cu
);
11825 child_die
= sibling_die (child_die
);
11832 http://gcc.gnu.org/wiki/DebugFission
11833 http://gcc.gnu.org/wiki/DebugFissionDWP
11835 To simplify handling of both DWO files ("object" files with the DWARF info)
11836 and DWP files (a file with the DWOs packaged up into one file), we treat
11837 DWP files as having a collection of virtual DWO files. */
11840 hash_dwo_file (const void *item
)
11842 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11845 hash
= htab_hash_string (dwo_file
->dwo_name
);
11846 if (dwo_file
->comp_dir
!= NULL
)
11847 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11852 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11854 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11855 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11857 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11859 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11860 return lhs
->comp_dir
== rhs
->comp_dir
;
11861 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11864 /* Allocate a hash table for DWO files. */
11867 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11869 auto delete_dwo_file
= [] (void *item
)
11871 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11876 return htab_up (htab_create_alloc_ex (41,
11880 &objfile
->objfile_obstack
,
11881 hashtab_obstack_allocate
,
11882 dummy_obstack_deallocate
));
11885 /* Lookup DWO file DWO_NAME. */
11888 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11889 const char *dwo_name
,
11890 const char *comp_dir
)
11892 struct dwo_file find_entry
;
11895 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11896 dwarf2_per_objfile
->dwo_files
11897 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11899 find_entry
.dwo_name
= dwo_name
;
11900 find_entry
.comp_dir
= comp_dir
;
11901 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11908 hash_dwo_unit (const void *item
)
11910 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11912 /* This drops the top 32 bits of the id, but is ok for a hash. */
11913 return dwo_unit
->signature
;
11917 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11919 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11920 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11922 /* The signature is assumed to be unique within the DWO file.
11923 So while object file CU dwo_id's always have the value zero,
11924 that's OK, assuming each object file DWO file has only one CU,
11925 and that's the rule for now. */
11926 return lhs
->signature
== rhs
->signature
;
11929 /* Allocate a hash table for DWO CUs,TUs.
11930 There is one of these tables for each of CUs,TUs for each DWO file. */
11933 allocate_dwo_unit_table (struct objfile
*objfile
)
11935 /* Start out with a pretty small number.
11936 Generally DWO files contain only one CU and maybe some TUs. */
11937 return htab_create_alloc_ex (3,
11941 &objfile
->objfile_obstack
,
11942 hashtab_obstack_allocate
,
11943 dummy_obstack_deallocate
);
11946 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11948 struct create_dwo_cu_data
11950 struct dwo_file
*dwo_file
;
11951 struct dwo_unit dwo_unit
;
11954 /* die_reader_func for create_dwo_cu. */
11957 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11958 const gdb_byte
*info_ptr
,
11959 struct die_info
*comp_unit_die
,
11963 struct dwarf2_cu
*cu
= reader
->cu
;
11964 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11965 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11966 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11967 struct dwo_file
*dwo_file
= data
->dwo_file
;
11968 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11970 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11971 if (!signature
.has_value ())
11973 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11974 " its dwo_id [in module %s]"),
11975 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11979 dwo_unit
->dwo_file
= dwo_file
;
11980 dwo_unit
->signature
= *signature
;
11981 dwo_unit
->section
= section
;
11982 dwo_unit
->sect_off
= sect_off
;
11983 dwo_unit
->length
= cu
->per_cu
->length
;
11985 if (dwarf_read_debug
)
11986 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11987 sect_offset_str (sect_off
),
11988 hex_string (dwo_unit
->signature
));
11991 /* Create the dwo_units for the CUs in a DWO_FILE.
11992 Note: This function processes DWO files only, not DWP files. */
11995 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11996 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11999 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12000 const gdb_byte
*info_ptr
, *end_ptr
;
12002 dwarf2_read_section (objfile
, §ion
);
12003 info_ptr
= section
.buffer
;
12005 if (info_ptr
== NULL
)
12008 if (dwarf_read_debug
)
12010 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
12011 get_section_name (§ion
),
12012 get_section_file_name (§ion
));
12015 end_ptr
= info_ptr
+ section
.size
;
12016 while (info_ptr
< end_ptr
)
12018 struct dwarf2_per_cu_data per_cu
;
12019 struct create_dwo_cu_data create_dwo_cu_data
;
12020 struct dwo_unit
*dwo_unit
;
12022 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
12024 memset (&create_dwo_cu_data
.dwo_unit
, 0,
12025 sizeof (create_dwo_cu_data
.dwo_unit
));
12026 memset (&per_cu
, 0, sizeof (per_cu
));
12027 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
12028 per_cu
.is_debug_types
= 0;
12029 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
12030 per_cu
.section
= §ion
;
12031 create_dwo_cu_data
.dwo_file
= &dwo_file
;
12033 init_cutu_and_read_dies_no_follow (
12034 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
12035 info_ptr
+= per_cu
.length
;
12037 // If the unit could not be parsed, skip it.
12038 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
12041 if (cus_htab
== NULL
)
12042 cus_htab
= allocate_dwo_unit_table (objfile
);
12044 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12045 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
12046 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
12047 gdb_assert (slot
!= NULL
);
12050 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
12051 sect_offset dup_sect_off
= dup_cu
->sect_off
;
12053 complaint (_("debug cu entry at offset %s is duplicate to"
12054 " the entry at offset %s, signature %s"),
12055 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
12056 hex_string (dwo_unit
->signature
));
12058 *slot
= (void *)dwo_unit
;
12062 /* DWP file .debug_{cu,tu}_index section format:
12063 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12067 Both index sections have the same format, and serve to map a 64-bit
12068 signature to a set of section numbers. Each section begins with a header,
12069 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12070 indexes, and a pool of 32-bit section numbers. The index sections will be
12071 aligned at 8-byte boundaries in the file.
12073 The index section header consists of:
12075 V, 32 bit version number
12077 N, 32 bit number of compilation units or type units in the index
12078 M, 32 bit number of slots in the hash table
12080 Numbers are recorded using the byte order of the application binary.
12082 The hash table begins at offset 16 in the section, and consists of an array
12083 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12084 order of the application binary). Unused slots in the hash table are 0.
12085 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12087 The parallel table begins immediately after the hash table
12088 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12089 array of 32-bit indexes (using the byte order of the application binary),
12090 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12091 table contains a 32-bit index into the pool of section numbers. For unused
12092 hash table slots, the corresponding entry in the parallel table will be 0.
12094 The pool of section numbers begins immediately following the hash table
12095 (at offset 16 + 12 * M from the beginning of the section). The pool of
12096 section numbers consists of an array of 32-bit words (using the byte order
12097 of the application binary). Each item in the array is indexed starting
12098 from 0. The hash table entry provides the index of the first section
12099 number in the set. Additional section numbers in the set follow, and the
12100 set is terminated by a 0 entry (section number 0 is not used in ELF).
12102 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12103 section must be the first entry in the set, and the .debug_abbrev.dwo must
12104 be the second entry. Other members of the set may follow in any order.
12110 DWP Version 2 combines all the .debug_info, etc. sections into one,
12111 and the entries in the index tables are now offsets into these sections.
12112 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12115 Index Section Contents:
12117 Hash Table of Signatures dwp_hash_table.hash_table
12118 Parallel Table of Indices dwp_hash_table.unit_table
12119 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12120 Table of Section Sizes dwp_hash_table.v2.sizes
12122 The index section header consists of:
12124 V, 32 bit version number
12125 L, 32 bit number of columns in the table of section offsets
12126 N, 32 bit number of compilation units or type units in the index
12127 M, 32 bit number of slots in the hash table
12129 Numbers are recorded using the byte order of the application binary.
12131 The hash table has the same format as version 1.
12132 The parallel table of indices has the same format as version 1,
12133 except that the entries are origin-1 indices into the table of sections
12134 offsets and the table of section sizes.
12136 The table of offsets begins immediately following the parallel table
12137 (at offset 16 + 12 * M from the beginning of the section). The table is
12138 a two-dimensional array of 32-bit words (using the byte order of the
12139 application binary), with L columns and N+1 rows, in row-major order.
12140 Each row in the array is indexed starting from 0. The first row provides
12141 a key to the remaining rows: each column in this row provides an identifier
12142 for a debug section, and the offsets in the same column of subsequent rows
12143 refer to that section. The section identifiers are:
12145 DW_SECT_INFO 1 .debug_info.dwo
12146 DW_SECT_TYPES 2 .debug_types.dwo
12147 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12148 DW_SECT_LINE 4 .debug_line.dwo
12149 DW_SECT_LOC 5 .debug_loc.dwo
12150 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12151 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12152 DW_SECT_MACRO 8 .debug_macro.dwo
12154 The offsets provided by the CU and TU index sections are the base offsets
12155 for the contributions made by each CU or TU to the corresponding section
12156 in the package file. Each CU and TU header contains an abbrev_offset
12157 field, used to find the abbreviations table for that CU or TU within the
12158 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12159 be interpreted as relative to the base offset given in the index section.
12160 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12161 should be interpreted as relative to the base offset for .debug_line.dwo,
12162 and offsets into other debug sections obtained from DWARF attributes should
12163 also be interpreted as relative to the corresponding base offset.
12165 The table of sizes begins immediately following the table of offsets.
12166 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12167 with L columns and N rows, in row-major order. Each row in the array is
12168 indexed starting from 1 (row 0 is shared by the two tables).
12172 Hash table lookup is handled the same in version 1 and 2:
12174 We assume that N and M will not exceed 2^32 - 1.
12175 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12177 Given a 64-bit compilation unit signature or a type signature S, an entry
12178 in the hash table is located as follows:
12180 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12181 the low-order k bits all set to 1.
12183 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12185 3) If the hash table entry at index H matches the signature, use that
12186 entry. If the hash table entry at index H is unused (all zeroes),
12187 terminate the search: the signature is not present in the table.
12189 4) Let H = (H + H') modulo M. Repeat at Step 3.
12191 Because M > N and H' and M are relatively prime, the search is guaranteed
12192 to stop at an unused slot or find the match. */
12194 /* Create a hash table to map DWO IDs to their CU/TU entry in
12195 .debug_{info,types}.dwo in DWP_FILE.
12196 Returns NULL if there isn't one.
12197 Note: This function processes DWP files only, not DWO files. */
12199 static struct dwp_hash_table
*
12200 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12201 struct dwp_file
*dwp_file
, int is_debug_types
)
12203 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12204 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12205 const gdb_byte
*index_ptr
, *index_end
;
12206 struct dwarf2_section_info
*index
;
12207 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12208 struct dwp_hash_table
*htab
;
12210 if (is_debug_types
)
12211 index
= &dwp_file
->sections
.tu_index
;
12213 index
= &dwp_file
->sections
.cu_index
;
12215 if (dwarf2_section_empty_p (index
))
12217 dwarf2_read_section (objfile
, index
);
12219 index_ptr
= index
->buffer
;
12220 index_end
= index_ptr
+ index
->size
;
12222 version
= read_4_bytes (dbfd
, index_ptr
);
12225 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12229 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12231 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12234 if (version
!= 1 && version
!= 2)
12236 error (_("Dwarf Error: unsupported DWP file version (%s)"
12237 " [in module %s]"),
12238 pulongest (version
), dwp_file
->name
);
12240 if (nr_slots
!= (nr_slots
& -nr_slots
))
12242 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12243 " is not power of 2 [in module %s]"),
12244 pulongest (nr_slots
), dwp_file
->name
);
12247 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12248 htab
->version
= version
;
12249 htab
->nr_columns
= nr_columns
;
12250 htab
->nr_units
= nr_units
;
12251 htab
->nr_slots
= nr_slots
;
12252 htab
->hash_table
= index_ptr
;
12253 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12255 /* Exit early if the table is empty. */
12256 if (nr_slots
== 0 || nr_units
== 0
12257 || (version
== 2 && nr_columns
== 0))
12259 /* All must be zero. */
12260 if (nr_slots
!= 0 || nr_units
!= 0
12261 || (version
== 2 && nr_columns
!= 0))
12263 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
12264 " all zero [in modules %s]"),
12272 htab
->section_pool
.v1
.indices
=
12273 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12274 /* It's harder to decide whether the section is too small in v1.
12275 V1 is deprecated anyway so we punt. */
12279 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12280 int *ids
= htab
->section_pool
.v2
.section_ids
;
12281 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
12282 /* Reverse map for error checking. */
12283 int ids_seen
[DW_SECT_MAX
+ 1];
12286 if (nr_columns
< 2)
12288 error (_("Dwarf Error: bad DWP hash table, too few columns"
12289 " in section table [in module %s]"),
12292 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12294 error (_("Dwarf Error: bad DWP hash table, too many columns"
12295 " in section table [in module %s]"),
12298 memset (ids
, 255, sizeof_ids
);
12299 memset (ids_seen
, 255, sizeof (ids_seen
));
12300 for (i
= 0; i
< nr_columns
; ++i
)
12302 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12304 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12306 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12307 " in section table [in module %s]"),
12308 id
, dwp_file
->name
);
12310 if (ids_seen
[id
] != -1)
12312 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12313 " id %d in section table [in module %s]"),
12314 id
, dwp_file
->name
);
12319 /* Must have exactly one info or types section. */
12320 if (((ids_seen
[DW_SECT_INFO
] != -1)
12321 + (ids_seen
[DW_SECT_TYPES
] != -1))
12324 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12325 " DWO info/types section [in module %s]"),
12328 /* Must have an abbrev section. */
12329 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12331 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12332 " section [in module %s]"),
12335 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12336 htab
->section_pool
.v2
.sizes
=
12337 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12338 * nr_units
* nr_columns
);
12339 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12340 * nr_units
* nr_columns
))
12343 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12344 " [in module %s]"),
12352 /* Update SECTIONS with the data from SECTP.
12354 This function is like the other "locate" section routines that are
12355 passed to bfd_map_over_sections, but in this context the sections to
12356 read comes from the DWP V1 hash table, not the full ELF section table.
12358 The result is non-zero for success, or zero if an error was found. */
12361 locate_v1_virtual_dwo_sections (asection
*sectp
,
12362 struct virtual_v1_dwo_sections
*sections
)
12364 const struct dwop_section_names
*names
= &dwop_section_names
;
12366 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12368 /* There can be only one. */
12369 if (sections
->abbrev
.s
.section
!= NULL
)
12371 sections
->abbrev
.s
.section
= sectp
;
12372 sections
->abbrev
.size
= bfd_section_size (sectp
);
12374 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12375 || section_is_p (sectp
->name
, &names
->types_dwo
))
12377 /* There can be only one. */
12378 if (sections
->info_or_types
.s
.section
!= NULL
)
12380 sections
->info_or_types
.s
.section
= sectp
;
12381 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12383 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12385 /* There can be only one. */
12386 if (sections
->line
.s
.section
!= NULL
)
12388 sections
->line
.s
.section
= sectp
;
12389 sections
->line
.size
= bfd_section_size (sectp
);
12391 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12393 /* There can be only one. */
12394 if (sections
->loc
.s
.section
!= NULL
)
12396 sections
->loc
.s
.section
= sectp
;
12397 sections
->loc
.size
= bfd_section_size (sectp
);
12399 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12401 /* There can be only one. */
12402 if (sections
->macinfo
.s
.section
!= NULL
)
12404 sections
->macinfo
.s
.section
= sectp
;
12405 sections
->macinfo
.size
= bfd_section_size (sectp
);
12407 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12409 /* There can be only one. */
12410 if (sections
->macro
.s
.section
!= NULL
)
12412 sections
->macro
.s
.section
= sectp
;
12413 sections
->macro
.size
= bfd_section_size (sectp
);
12415 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12417 /* There can be only one. */
12418 if (sections
->str_offsets
.s
.section
!= NULL
)
12420 sections
->str_offsets
.s
.section
= sectp
;
12421 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12425 /* No other kind of section is valid. */
12432 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12433 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12434 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12435 This is for DWP version 1 files. */
12437 static struct dwo_unit
*
12438 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12439 struct dwp_file
*dwp_file
,
12440 uint32_t unit_index
,
12441 const char *comp_dir
,
12442 ULONGEST signature
, int is_debug_types
)
12444 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12445 const struct dwp_hash_table
*dwp_htab
=
12446 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12447 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12448 const char *kind
= is_debug_types
? "TU" : "CU";
12449 struct dwo_file
*dwo_file
;
12450 struct dwo_unit
*dwo_unit
;
12451 struct virtual_v1_dwo_sections sections
;
12452 void **dwo_file_slot
;
12455 gdb_assert (dwp_file
->version
== 1);
12457 if (dwarf_read_debug
)
12459 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12461 pulongest (unit_index
), hex_string (signature
),
12465 /* Fetch the sections of this DWO unit.
12466 Put a limit on the number of sections we look for so that bad data
12467 doesn't cause us to loop forever. */
12469 #define MAX_NR_V1_DWO_SECTIONS \
12470 (1 /* .debug_info or .debug_types */ \
12471 + 1 /* .debug_abbrev */ \
12472 + 1 /* .debug_line */ \
12473 + 1 /* .debug_loc */ \
12474 + 1 /* .debug_str_offsets */ \
12475 + 1 /* .debug_macro or .debug_macinfo */ \
12476 + 1 /* trailing zero */)
12478 memset (§ions
, 0, sizeof (sections
));
12480 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12483 uint32_t section_nr
=
12484 read_4_bytes (dbfd
,
12485 dwp_htab
->section_pool
.v1
.indices
12486 + (unit_index
+ i
) * sizeof (uint32_t));
12488 if (section_nr
== 0)
12490 if (section_nr
>= dwp_file
->num_sections
)
12492 error (_("Dwarf Error: bad DWP hash table, section number too large"
12493 " [in module %s]"),
12497 sectp
= dwp_file
->elf_sections
[section_nr
];
12498 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12500 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12501 " [in module %s]"),
12507 || dwarf2_section_empty_p (§ions
.info_or_types
)
12508 || dwarf2_section_empty_p (§ions
.abbrev
))
12510 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12511 " [in module %s]"),
12514 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12516 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12517 " [in module %s]"),
12521 /* It's easier for the rest of the code if we fake a struct dwo_file and
12522 have dwo_unit "live" in that. At least for now.
12524 The DWP file can be made up of a random collection of CUs and TUs.
12525 However, for each CU + set of TUs that came from the same original DWO
12526 file, we can combine them back into a virtual DWO file to save space
12527 (fewer struct dwo_file objects to allocate). Remember that for really
12528 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12530 std::string virtual_dwo_name
=
12531 string_printf ("virtual-dwo/%d-%d-%d-%d",
12532 get_section_id (§ions
.abbrev
),
12533 get_section_id (§ions
.line
),
12534 get_section_id (§ions
.loc
),
12535 get_section_id (§ions
.str_offsets
));
12536 /* Can we use an existing virtual DWO file? */
12537 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12538 virtual_dwo_name
.c_str (),
12540 /* Create one if necessary. */
12541 if (*dwo_file_slot
== NULL
)
12543 if (dwarf_read_debug
)
12545 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12546 virtual_dwo_name
.c_str ());
12548 dwo_file
= new struct dwo_file
;
12549 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12551 dwo_file
->comp_dir
= comp_dir
;
12552 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12553 dwo_file
->sections
.line
= sections
.line
;
12554 dwo_file
->sections
.loc
= sections
.loc
;
12555 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12556 dwo_file
->sections
.macro
= sections
.macro
;
12557 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12558 /* The "str" section is global to the entire DWP file. */
12559 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12560 /* The info or types section is assigned below to dwo_unit,
12561 there's no need to record it in dwo_file.
12562 Also, we can't simply record type sections in dwo_file because
12563 we record a pointer into the vector in dwo_unit. As we collect more
12564 types we'll grow the vector and eventually have to reallocate space
12565 for it, invalidating all copies of pointers into the previous
12567 *dwo_file_slot
= dwo_file
;
12571 if (dwarf_read_debug
)
12573 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12574 virtual_dwo_name
.c_str ());
12576 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12579 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12580 dwo_unit
->dwo_file
= dwo_file
;
12581 dwo_unit
->signature
= signature
;
12582 dwo_unit
->section
=
12583 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12584 *dwo_unit
->section
= sections
.info_or_types
;
12585 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12590 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12591 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12592 piece within that section used by a TU/CU, return a virtual section
12593 of just that piece. */
12595 static struct dwarf2_section_info
12596 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12597 struct dwarf2_section_info
*section
,
12598 bfd_size_type offset
, bfd_size_type size
)
12600 struct dwarf2_section_info result
;
12603 gdb_assert (section
!= NULL
);
12604 gdb_assert (!section
->is_virtual
);
12606 memset (&result
, 0, sizeof (result
));
12607 result
.s
.containing_section
= section
;
12608 result
.is_virtual
= true;
12613 sectp
= get_section_bfd_section (section
);
12615 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12616 bounds of the real section. This is a pretty-rare event, so just
12617 flag an error (easier) instead of a warning and trying to cope. */
12619 || offset
+ size
> bfd_section_size (sectp
))
12621 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12622 " in section %s [in module %s]"),
12623 sectp
? bfd_section_name (sectp
) : "<unknown>",
12624 objfile_name (dwarf2_per_objfile
->objfile
));
12627 result
.virtual_offset
= offset
;
12628 result
.size
= size
;
12632 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12633 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12634 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12635 This is for DWP version 2 files. */
12637 static struct dwo_unit
*
12638 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12639 struct dwp_file
*dwp_file
,
12640 uint32_t unit_index
,
12641 const char *comp_dir
,
12642 ULONGEST signature
, int is_debug_types
)
12644 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12645 const struct dwp_hash_table
*dwp_htab
=
12646 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12647 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12648 const char *kind
= is_debug_types
? "TU" : "CU";
12649 struct dwo_file
*dwo_file
;
12650 struct dwo_unit
*dwo_unit
;
12651 struct virtual_v2_dwo_sections sections
;
12652 void **dwo_file_slot
;
12655 gdb_assert (dwp_file
->version
== 2);
12657 if (dwarf_read_debug
)
12659 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12661 pulongest (unit_index
), hex_string (signature
),
12665 /* Fetch the section offsets of this DWO unit. */
12667 memset (§ions
, 0, sizeof (sections
));
12669 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12671 uint32_t offset
= read_4_bytes (dbfd
,
12672 dwp_htab
->section_pool
.v2
.offsets
12673 + (((unit_index
- 1) * dwp_htab
->nr_columns
12675 * sizeof (uint32_t)));
12676 uint32_t size
= read_4_bytes (dbfd
,
12677 dwp_htab
->section_pool
.v2
.sizes
12678 + (((unit_index
- 1) * dwp_htab
->nr_columns
12680 * sizeof (uint32_t)));
12682 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12685 case DW_SECT_TYPES
:
12686 sections
.info_or_types_offset
= offset
;
12687 sections
.info_or_types_size
= size
;
12689 case DW_SECT_ABBREV
:
12690 sections
.abbrev_offset
= offset
;
12691 sections
.abbrev_size
= size
;
12694 sections
.line_offset
= offset
;
12695 sections
.line_size
= size
;
12698 sections
.loc_offset
= offset
;
12699 sections
.loc_size
= size
;
12701 case DW_SECT_STR_OFFSETS
:
12702 sections
.str_offsets_offset
= offset
;
12703 sections
.str_offsets_size
= size
;
12705 case DW_SECT_MACINFO
:
12706 sections
.macinfo_offset
= offset
;
12707 sections
.macinfo_size
= size
;
12709 case DW_SECT_MACRO
:
12710 sections
.macro_offset
= offset
;
12711 sections
.macro_size
= size
;
12716 /* It's easier for the rest of the code if we fake a struct dwo_file and
12717 have dwo_unit "live" in that. At least for now.
12719 The DWP file can be made up of a random collection of CUs and TUs.
12720 However, for each CU + set of TUs that came from the same original DWO
12721 file, we can combine them back into a virtual DWO file to save space
12722 (fewer struct dwo_file objects to allocate). Remember that for really
12723 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12725 std::string virtual_dwo_name
=
12726 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12727 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12728 (long) (sections
.line_size
? sections
.line_offset
: 0),
12729 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12730 (long) (sections
.str_offsets_size
12731 ? sections
.str_offsets_offset
: 0));
12732 /* Can we use an existing virtual DWO file? */
12733 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12734 virtual_dwo_name
.c_str (),
12736 /* Create one if necessary. */
12737 if (*dwo_file_slot
== NULL
)
12739 if (dwarf_read_debug
)
12741 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12742 virtual_dwo_name
.c_str ());
12744 dwo_file
= new struct dwo_file
;
12745 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12747 dwo_file
->comp_dir
= comp_dir
;
12748 dwo_file
->sections
.abbrev
=
12749 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12750 sections
.abbrev_offset
, sections
.abbrev_size
);
12751 dwo_file
->sections
.line
=
12752 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12753 sections
.line_offset
, sections
.line_size
);
12754 dwo_file
->sections
.loc
=
12755 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12756 sections
.loc_offset
, sections
.loc_size
);
12757 dwo_file
->sections
.macinfo
=
12758 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12759 sections
.macinfo_offset
, sections
.macinfo_size
);
12760 dwo_file
->sections
.macro
=
12761 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12762 sections
.macro_offset
, sections
.macro_size
);
12763 dwo_file
->sections
.str_offsets
=
12764 create_dwp_v2_section (dwarf2_per_objfile
,
12765 &dwp_file
->sections
.str_offsets
,
12766 sections
.str_offsets_offset
,
12767 sections
.str_offsets_size
);
12768 /* The "str" section is global to the entire DWP file. */
12769 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12770 /* The info or types section is assigned below to dwo_unit,
12771 there's no need to record it in dwo_file.
12772 Also, we can't simply record type sections in dwo_file because
12773 we record a pointer into the vector in dwo_unit. As we collect more
12774 types we'll grow the vector and eventually have to reallocate space
12775 for it, invalidating all copies of pointers into the previous
12777 *dwo_file_slot
= dwo_file
;
12781 if (dwarf_read_debug
)
12783 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12784 virtual_dwo_name
.c_str ());
12786 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12789 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12790 dwo_unit
->dwo_file
= dwo_file
;
12791 dwo_unit
->signature
= signature
;
12792 dwo_unit
->section
=
12793 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12794 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12796 ? &dwp_file
->sections
.types
12797 : &dwp_file
->sections
.info
,
12798 sections
.info_or_types_offset
,
12799 sections
.info_or_types_size
);
12800 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12805 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12806 Returns NULL if the signature isn't found. */
12808 static struct dwo_unit
*
12809 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12810 struct dwp_file
*dwp_file
, const char *comp_dir
,
12811 ULONGEST signature
, int is_debug_types
)
12813 const struct dwp_hash_table
*dwp_htab
=
12814 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12815 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12816 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12817 uint32_t hash
= signature
& mask
;
12818 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12821 struct dwo_unit find_dwo_cu
;
12823 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12824 find_dwo_cu
.signature
= signature
;
12825 slot
= htab_find_slot (is_debug_types
12826 ? dwp_file
->loaded_tus
12827 : dwp_file
->loaded_cus
,
12828 &find_dwo_cu
, INSERT
);
12831 return (struct dwo_unit
*) *slot
;
12833 /* Use a for loop so that we don't loop forever on bad debug info. */
12834 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12836 ULONGEST signature_in_table
;
12838 signature_in_table
=
12839 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12840 if (signature_in_table
== signature
)
12842 uint32_t unit_index
=
12843 read_4_bytes (dbfd
,
12844 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12846 if (dwp_file
->version
== 1)
12848 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12849 dwp_file
, unit_index
,
12850 comp_dir
, signature
,
12855 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12856 dwp_file
, unit_index
,
12857 comp_dir
, signature
,
12860 return (struct dwo_unit
*) *slot
;
12862 if (signature_in_table
== 0)
12864 hash
= (hash
+ hash2
) & mask
;
12867 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12868 " [in module %s]"),
12872 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12873 Open the file specified by FILE_NAME and hand it off to BFD for
12874 preliminary analysis. Return a newly initialized bfd *, which
12875 includes a canonicalized copy of FILE_NAME.
12876 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12877 SEARCH_CWD is true if the current directory is to be searched.
12878 It will be searched before debug-file-directory.
12879 If successful, the file is added to the bfd include table of the
12880 objfile's bfd (see gdb_bfd_record_inclusion).
12881 If unable to find/open the file, return NULL.
12882 NOTE: This function is derived from symfile_bfd_open. */
12884 static gdb_bfd_ref_ptr
12885 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12886 const char *file_name
, int is_dwp
, int search_cwd
)
12889 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12890 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12891 to debug_file_directory. */
12892 const char *search_path
;
12893 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12895 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12898 if (*debug_file_directory
!= '\0')
12900 search_path_holder
.reset (concat (".", dirname_separator_string
,
12901 debug_file_directory
,
12903 search_path
= search_path_holder
.get ();
12909 search_path
= debug_file_directory
;
12911 openp_flags flags
= OPF_RETURN_REALPATH
;
12913 flags
|= OPF_SEARCH_IN_PATH
;
12915 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12916 desc
= openp (search_path
, flags
, file_name
,
12917 O_RDONLY
| O_BINARY
, &absolute_name
);
12921 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12923 if (sym_bfd
== NULL
)
12925 bfd_set_cacheable (sym_bfd
.get (), 1);
12927 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12930 /* Success. Record the bfd as having been included by the objfile's bfd.
12931 This is important because things like demangled_names_hash lives in the
12932 objfile's per_bfd space and may have references to things like symbol
12933 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12934 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12939 /* Try to open DWO file FILE_NAME.
12940 COMP_DIR is the DW_AT_comp_dir attribute.
12941 The result is the bfd handle of the file.
12942 If there is a problem finding or opening the file, return NULL.
12943 Upon success, the canonicalized path of the file is stored in the bfd,
12944 same as symfile_bfd_open. */
12946 static gdb_bfd_ref_ptr
12947 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12948 const char *file_name
, const char *comp_dir
)
12950 if (IS_ABSOLUTE_PATH (file_name
))
12951 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12952 0 /*is_dwp*/, 0 /*search_cwd*/);
12954 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12956 if (comp_dir
!= NULL
)
12958 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
12959 file_name
, (char *) NULL
);
12961 /* NOTE: If comp_dir is a relative path, this will also try the
12962 search path, which seems useful. */
12963 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12966 1 /*search_cwd*/));
12967 xfree (path_to_try
);
12972 /* That didn't work, try debug-file-directory, which, despite its name,
12973 is a list of paths. */
12975 if (*debug_file_directory
== '\0')
12978 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12979 0 /*is_dwp*/, 1 /*search_cwd*/);
12982 /* This function is mapped across the sections and remembers the offset and
12983 size of each of the DWO debugging sections we are interested in. */
12986 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12988 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12989 const struct dwop_section_names
*names
= &dwop_section_names
;
12991 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12993 dwo_sections
->abbrev
.s
.section
= sectp
;
12994 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12996 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12998 dwo_sections
->info
.s
.section
= sectp
;
12999 dwo_sections
->info
.size
= bfd_section_size (sectp
);
13001 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13003 dwo_sections
->line
.s
.section
= sectp
;
13004 dwo_sections
->line
.size
= bfd_section_size (sectp
);
13006 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13008 dwo_sections
->loc
.s
.section
= sectp
;
13009 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
13011 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13013 dwo_sections
->macinfo
.s
.section
= sectp
;
13014 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
13016 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13018 dwo_sections
->macro
.s
.section
= sectp
;
13019 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
13021 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
13023 dwo_sections
->str
.s
.section
= sectp
;
13024 dwo_sections
->str
.size
= bfd_section_size (sectp
);
13026 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13028 dwo_sections
->str_offsets
.s
.section
= sectp
;
13029 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
13031 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13033 struct dwarf2_section_info type_section
;
13035 memset (&type_section
, 0, sizeof (type_section
));
13036 type_section
.s
.section
= sectp
;
13037 type_section
.size
= bfd_section_size (sectp
);
13038 dwo_sections
->types
.push_back (type_section
);
13042 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
13043 by PER_CU. This is for the non-DWP case.
13044 The result is NULL if DWO_NAME can't be found. */
13046 static struct dwo_file
*
13047 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
13048 const char *dwo_name
, const char *comp_dir
)
13050 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
13052 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
13055 if (dwarf_read_debug
)
13056 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13060 dwo_file_up
dwo_file (new struct dwo_file
);
13061 dwo_file
->dwo_name
= dwo_name
;
13062 dwo_file
->comp_dir
= comp_dir
;
13063 dwo_file
->dbfd
= std::move (dbfd
);
13065 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
13066 &dwo_file
->sections
);
13068 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13071 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
13072 dwo_file
->sections
.types
, dwo_file
->tus
);
13074 if (dwarf_read_debug
)
13075 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13077 return dwo_file
.release ();
13080 /* This function is mapped across the sections and remembers the offset and
13081 size of each of the DWP debugging sections common to version 1 and 2 that
13082 we are interested in. */
13085 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13086 void *dwp_file_ptr
)
13088 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13089 const struct dwop_section_names
*names
= &dwop_section_names
;
13090 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13092 /* Record the ELF section number for later lookup: this is what the
13093 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13094 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13095 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13097 /* Look for specific sections that we need. */
13098 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13100 dwp_file
->sections
.str
.s
.section
= sectp
;
13101 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
13103 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13105 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13106 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
13108 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13110 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13111 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
13115 /* This function is mapped across the sections and remembers the offset and
13116 size of each of the DWP version 2 debugging sections that we are interested
13117 in. This is split into a separate function because we don't know if we
13118 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13121 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13123 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13124 const struct dwop_section_names
*names
= &dwop_section_names
;
13125 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13127 /* Record the ELF section number for later lookup: this is what the
13128 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13129 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13130 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13132 /* Look for specific sections that we need. */
13133 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13135 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13136 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13138 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13140 dwp_file
->sections
.info
.s
.section
= sectp
;
13141 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13143 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13145 dwp_file
->sections
.line
.s
.section
= sectp
;
13146 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13148 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13150 dwp_file
->sections
.loc
.s
.section
= sectp
;
13151 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
13153 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13155 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13156 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
13158 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13160 dwp_file
->sections
.macro
.s
.section
= sectp
;
13161 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13163 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13165 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13166 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13168 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13170 dwp_file
->sections
.types
.s
.section
= sectp
;
13171 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13175 /* Hash function for dwp_file loaded CUs/TUs. */
13178 hash_dwp_loaded_cutus (const void *item
)
13180 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13182 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13183 return dwo_unit
->signature
;
13186 /* Equality function for dwp_file loaded CUs/TUs. */
13189 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13191 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13192 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13194 return dua
->signature
== dub
->signature
;
13197 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13200 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13202 return htab_create_alloc_ex (3,
13203 hash_dwp_loaded_cutus
,
13204 eq_dwp_loaded_cutus
,
13206 &objfile
->objfile_obstack
,
13207 hashtab_obstack_allocate
,
13208 dummy_obstack_deallocate
);
13211 /* Try to open DWP file FILE_NAME.
13212 The result is the bfd handle of the file.
13213 If there is a problem finding or opening the file, return NULL.
13214 Upon success, the canonicalized path of the file is stored in the bfd,
13215 same as symfile_bfd_open. */
13217 static gdb_bfd_ref_ptr
13218 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13219 const char *file_name
)
13221 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13223 1 /*search_cwd*/));
13227 /* Work around upstream bug 15652.
13228 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13229 [Whether that's a "bug" is debatable, but it is getting in our way.]
13230 We have no real idea where the dwp file is, because gdb's realpath-ing
13231 of the executable's path may have discarded the needed info.
13232 [IWBN if the dwp file name was recorded in the executable, akin to
13233 .gnu_debuglink, but that doesn't exist yet.]
13234 Strip the directory from FILE_NAME and search again. */
13235 if (*debug_file_directory
!= '\0')
13237 /* Don't implicitly search the current directory here.
13238 If the user wants to search "." to handle this case,
13239 it must be added to debug-file-directory. */
13240 return try_open_dwop_file (dwarf2_per_objfile
,
13241 lbasename (file_name
), 1 /*is_dwp*/,
13248 /* Initialize the use of the DWP file for the current objfile.
13249 By convention the name of the DWP file is ${objfile}.dwp.
13250 The result is NULL if it can't be found. */
13252 static std::unique_ptr
<struct dwp_file
>
13253 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13255 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13257 /* Try to find first .dwp for the binary file before any symbolic links
13260 /* If the objfile is a debug file, find the name of the real binary
13261 file and get the name of dwp file from there. */
13262 std::string dwp_name
;
13263 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13265 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13266 const char *backlink_basename
= lbasename (backlink
->original_name
);
13268 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13271 dwp_name
= objfile
->original_name
;
13273 dwp_name
+= ".dwp";
13275 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13277 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13279 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13280 dwp_name
= objfile_name (objfile
);
13281 dwp_name
+= ".dwp";
13282 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13287 if (dwarf_read_debug
)
13288 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13289 return std::unique_ptr
<dwp_file
> ();
13292 const char *name
= bfd_get_filename (dbfd
.get ());
13293 std::unique_ptr
<struct dwp_file
> dwp_file
13294 (new struct dwp_file (name
, std::move (dbfd
)));
13296 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13297 dwp_file
->elf_sections
=
13298 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13299 dwp_file
->num_sections
, asection
*);
13301 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13302 dwarf2_locate_common_dwp_sections
,
13305 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13308 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13311 /* The DWP file version is stored in the hash table. Oh well. */
13312 if (dwp_file
->cus
&& dwp_file
->tus
13313 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13315 /* Technically speaking, we should try to limp along, but this is
13316 pretty bizarre. We use pulongest here because that's the established
13317 portability solution (e.g, we cannot use %u for uint32_t). */
13318 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13319 " TU version %s [in DWP file %s]"),
13320 pulongest (dwp_file
->cus
->version
),
13321 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13325 dwp_file
->version
= dwp_file
->cus
->version
;
13326 else if (dwp_file
->tus
)
13327 dwp_file
->version
= dwp_file
->tus
->version
;
13329 dwp_file
->version
= 2;
13331 if (dwp_file
->version
== 2)
13332 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13333 dwarf2_locate_v2_dwp_sections
,
13336 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13337 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13339 if (dwarf_read_debug
)
13341 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13342 fprintf_unfiltered (gdb_stdlog
,
13343 " %s CUs, %s TUs\n",
13344 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13345 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13351 /* Wrapper around open_and_init_dwp_file, only open it once. */
13353 static struct dwp_file
*
13354 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13356 if (! dwarf2_per_objfile
->dwp_checked
)
13358 dwarf2_per_objfile
->dwp_file
13359 = open_and_init_dwp_file (dwarf2_per_objfile
);
13360 dwarf2_per_objfile
->dwp_checked
= 1;
13362 return dwarf2_per_objfile
->dwp_file
.get ();
13365 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13366 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13367 or in the DWP file for the objfile, referenced by THIS_UNIT.
13368 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13369 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13371 This is called, for example, when wanting to read a variable with a
13372 complex location. Therefore we don't want to do file i/o for every call.
13373 Therefore we don't want to look for a DWO file on every call.
13374 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13375 then we check if we've already seen DWO_NAME, and only THEN do we check
13378 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13379 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13381 static struct dwo_unit
*
13382 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13383 const char *dwo_name
, const char *comp_dir
,
13384 ULONGEST signature
, int is_debug_types
)
13386 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13387 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13388 const char *kind
= is_debug_types
? "TU" : "CU";
13389 void **dwo_file_slot
;
13390 struct dwo_file
*dwo_file
;
13391 struct dwp_file
*dwp_file
;
13393 /* First see if there's a DWP file.
13394 If we have a DWP file but didn't find the DWO inside it, don't
13395 look for the original DWO file. It makes gdb behave differently
13396 depending on whether one is debugging in the build tree. */
13398 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13399 if (dwp_file
!= NULL
)
13401 const struct dwp_hash_table
*dwp_htab
=
13402 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13404 if (dwp_htab
!= NULL
)
13406 struct dwo_unit
*dwo_cutu
=
13407 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13408 signature
, is_debug_types
);
13410 if (dwo_cutu
!= NULL
)
13412 if (dwarf_read_debug
)
13414 fprintf_unfiltered (gdb_stdlog
,
13415 "Virtual DWO %s %s found: @%s\n",
13416 kind
, hex_string (signature
),
13417 host_address_to_string (dwo_cutu
));
13425 /* No DWP file, look for the DWO file. */
13427 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13428 dwo_name
, comp_dir
);
13429 if (*dwo_file_slot
== NULL
)
13431 /* Read in the file and build a table of the CUs/TUs it contains. */
13432 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13434 /* NOTE: This will be NULL if unable to open the file. */
13435 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13437 if (dwo_file
!= NULL
)
13439 struct dwo_unit
*dwo_cutu
= NULL
;
13441 if (is_debug_types
&& dwo_file
->tus
)
13443 struct dwo_unit find_dwo_cutu
;
13445 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13446 find_dwo_cutu
.signature
= signature
;
13448 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13450 else if (!is_debug_types
&& dwo_file
->cus
)
13452 struct dwo_unit find_dwo_cutu
;
13454 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13455 find_dwo_cutu
.signature
= signature
;
13456 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13460 if (dwo_cutu
!= NULL
)
13462 if (dwarf_read_debug
)
13464 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13465 kind
, dwo_name
, hex_string (signature
),
13466 host_address_to_string (dwo_cutu
));
13473 /* We didn't find it. This could mean a dwo_id mismatch, or
13474 someone deleted the DWO/DWP file, or the search path isn't set up
13475 correctly to find the file. */
13477 if (dwarf_read_debug
)
13479 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13480 kind
, dwo_name
, hex_string (signature
));
13483 /* This is a warning and not a complaint because it can be caused by
13484 pilot error (e.g., user accidentally deleting the DWO). */
13486 /* Print the name of the DWP file if we looked there, helps the user
13487 better diagnose the problem. */
13488 std::string dwp_text
;
13490 if (dwp_file
!= NULL
)
13491 dwp_text
= string_printf (" [in DWP file %s]",
13492 lbasename (dwp_file
->name
));
13494 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13495 " [in module %s]"),
13496 kind
, dwo_name
, hex_string (signature
),
13498 this_unit
->is_debug_types
? "TU" : "CU",
13499 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13504 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13505 See lookup_dwo_cutu_unit for details. */
13507 static struct dwo_unit
*
13508 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13509 const char *dwo_name
, const char *comp_dir
,
13510 ULONGEST signature
)
13512 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13515 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13516 See lookup_dwo_cutu_unit for details. */
13518 static struct dwo_unit
*
13519 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13520 const char *dwo_name
, const char *comp_dir
)
13522 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13525 /* Traversal function for queue_and_load_all_dwo_tus. */
13528 queue_and_load_dwo_tu (void **slot
, void *info
)
13530 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13531 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13532 ULONGEST signature
= dwo_unit
->signature
;
13533 struct signatured_type
*sig_type
=
13534 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13536 if (sig_type
!= NULL
)
13538 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13540 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13541 a real dependency of PER_CU on SIG_TYPE. That is detected later
13542 while processing PER_CU. */
13543 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13544 load_full_type_unit (sig_cu
);
13545 per_cu
->imported_symtabs_push (sig_cu
);
13551 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13552 The DWO may have the only definition of the type, though it may not be
13553 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13554 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13557 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13559 struct dwo_unit
*dwo_unit
;
13560 struct dwo_file
*dwo_file
;
13562 gdb_assert (!per_cu
->is_debug_types
);
13563 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13564 gdb_assert (per_cu
->cu
!= NULL
);
13566 dwo_unit
= per_cu
->cu
->dwo_unit
;
13567 gdb_assert (dwo_unit
!= NULL
);
13569 dwo_file
= dwo_unit
->dwo_file
;
13570 if (dwo_file
->tus
!= NULL
)
13571 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13574 /* Read in various DIEs. */
13576 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13577 Inherit only the children of the DW_AT_abstract_origin DIE not being
13578 already referenced by DW_AT_abstract_origin from the children of the
13582 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13584 struct die_info
*child_die
;
13585 sect_offset
*offsetp
;
13586 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13587 struct die_info
*origin_die
;
13588 /* Iterator of the ORIGIN_DIE children. */
13589 struct die_info
*origin_child_die
;
13590 struct attribute
*attr
;
13591 struct dwarf2_cu
*origin_cu
;
13592 struct pending
**origin_previous_list_in_scope
;
13594 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13598 /* Note that following die references may follow to a die in a
13602 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13604 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13606 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13607 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13609 if (die
->tag
!= origin_die
->tag
13610 && !(die
->tag
== DW_TAG_inlined_subroutine
13611 && origin_die
->tag
== DW_TAG_subprogram
))
13612 complaint (_("DIE %s and its abstract origin %s have different tags"),
13613 sect_offset_str (die
->sect_off
),
13614 sect_offset_str (origin_die
->sect_off
));
13616 std::vector
<sect_offset
> offsets
;
13618 for (child_die
= die
->child
;
13619 child_die
&& child_die
->tag
;
13620 child_die
= sibling_die (child_die
))
13622 struct die_info
*child_origin_die
;
13623 struct dwarf2_cu
*child_origin_cu
;
13625 /* We are trying to process concrete instance entries:
13626 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13627 it's not relevant to our analysis here. i.e. detecting DIEs that are
13628 present in the abstract instance but not referenced in the concrete
13630 if (child_die
->tag
== DW_TAG_call_site
13631 || child_die
->tag
== DW_TAG_GNU_call_site
)
13634 /* For each CHILD_DIE, find the corresponding child of
13635 ORIGIN_DIE. If there is more than one layer of
13636 DW_AT_abstract_origin, follow them all; there shouldn't be,
13637 but GCC versions at least through 4.4 generate this (GCC PR
13639 child_origin_die
= child_die
;
13640 child_origin_cu
= cu
;
13643 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13647 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13651 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13652 counterpart may exist. */
13653 if (child_origin_die
!= child_die
)
13655 if (child_die
->tag
!= child_origin_die
->tag
13656 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13657 && child_origin_die
->tag
== DW_TAG_subprogram
))
13658 complaint (_("Child DIE %s and its abstract origin %s have "
13660 sect_offset_str (child_die
->sect_off
),
13661 sect_offset_str (child_origin_die
->sect_off
));
13662 if (child_origin_die
->parent
!= origin_die
)
13663 complaint (_("Child DIE %s and its abstract origin %s have "
13664 "different parents"),
13665 sect_offset_str (child_die
->sect_off
),
13666 sect_offset_str (child_origin_die
->sect_off
));
13668 offsets
.push_back (child_origin_die
->sect_off
);
13671 std::sort (offsets
.begin (), offsets
.end ());
13672 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13673 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13674 if (offsetp
[-1] == *offsetp
)
13675 complaint (_("Multiple children of DIE %s refer "
13676 "to DIE %s as their abstract origin"),
13677 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13679 offsetp
= offsets
.data ();
13680 origin_child_die
= origin_die
->child
;
13681 while (origin_child_die
&& origin_child_die
->tag
)
13683 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13684 while (offsetp
< offsets_end
13685 && *offsetp
< origin_child_die
->sect_off
)
13687 if (offsetp
>= offsets_end
13688 || *offsetp
> origin_child_die
->sect_off
)
13690 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13691 Check whether we're already processing ORIGIN_CHILD_DIE.
13692 This can happen with mutually referenced abstract_origins.
13694 if (!origin_child_die
->in_process
)
13695 process_die (origin_child_die
, origin_cu
);
13697 origin_child_die
= sibling_die (origin_child_die
);
13699 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13701 if (cu
!= origin_cu
)
13702 compute_delayed_physnames (origin_cu
);
13706 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13708 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13709 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13710 struct context_stack
*newobj
;
13713 struct die_info
*child_die
;
13714 struct attribute
*attr
, *call_line
, *call_file
;
13716 CORE_ADDR baseaddr
;
13717 struct block
*block
;
13718 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13719 std::vector
<struct symbol
*> template_args
;
13720 struct template_symbol
*templ_func
= NULL
;
13724 /* If we do not have call site information, we can't show the
13725 caller of this inlined function. That's too confusing, so
13726 only use the scope for local variables. */
13727 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13728 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13729 if (call_line
== NULL
|| call_file
== NULL
)
13731 read_lexical_block_scope (die
, cu
);
13736 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13738 name
= dwarf2_name (die
, cu
);
13740 /* Ignore functions with missing or empty names. These are actually
13741 illegal according to the DWARF standard. */
13744 complaint (_("missing name for subprogram DIE at %s"),
13745 sect_offset_str (die
->sect_off
));
13749 /* Ignore functions with missing or invalid low and high pc attributes. */
13750 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13751 <= PC_BOUNDS_INVALID
)
13753 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13754 if (!attr
|| !DW_UNSND (attr
))
13755 complaint (_("cannot get low and high bounds "
13756 "for subprogram DIE at %s"),
13757 sect_offset_str (die
->sect_off
));
13761 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13762 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13764 /* If we have any template arguments, then we must allocate a
13765 different sort of symbol. */
13766 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13768 if (child_die
->tag
== DW_TAG_template_type_param
13769 || child_die
->tag
== DW_TAG_template_value_param
)
13771 templ_func
= allocate_template_symbol (objfile
);
13772 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13777 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13778 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13779 (struct symbol
*) templ_func
);
13781 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13782 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13785 /* If there is a location expression for DW_AT_frame_base, record
13787 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13788 if (attr
!= nullptr)
13789 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13791 /* If there is a location for the static link, record it. */
13792 newobj
->static_link
= NULL
;
13793 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13794 if (attr
!= nullptr)
13796 newobj
->static_link
13797 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13798 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13799 dwarf2_per_cu_addr_type (cu
->per_cu
));
13802 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13804 if (die
->child
!= NULL
)
13806 child_die
= die
->child
;
13807 while (child_die
&& child_die
->tag
)
13809 if (child_die
->tag
== DW_TAG_template_type_param
13810 || child_die
->tag
== DW_TAG_template_value_param
)
13812 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13815 template_args
.push_back (arg
);
13818 process_die (child_die
, cu
);
13819 child_die
= sibling_die (child_die
);
13823 inherit_abstract_dies (die
, cu
);
13825 /* If we have a DW_AT_specification, we might need to import using
13826 directives from the context of the specification DIE. See the
13827 comment in determine_prefix. */
13828 if (cu
->language
== language_cplus
13829 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13831 struct dwarf2_cu
*spec_cu
= cu
;
13832 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13836 child_die
= spec_die
->child
;
13837 while (child_die
&& child_die
->tag
)
13839 if (child_die
->tag
== DW_TAG_imported_module
)
13840 process_die (child_die
, spec_cu
);
13841 child_die
= sibling_die (child_die
);
13844 /* In some cases, GCC generates specification DIEs that
13845 themselves contain DW_AT_specification attributes. */
13846 spec_die
= die_specification (spec_die
, &spec_cu
);
13850 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13851 /* Make a block for the local symbols within. */
13852 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13853 cstk
.static_link
, lowpc
, highpc
);
13855 /* For C++, set the block's scope. */
13856 if ((cu
->language
== language_cplus
13857 || cu
->language
== language_fortran
13858 || cu
->language
== language_d
13859 || cu
->language
== language_rust
)
13860 && cu
->processing_has_namespace_info
)
13861 block_set_scope (block
, determine_prefix (die
, cu
),
13862 &objfile
->objfile_obstack
);
13864 /* If we have address ranges, record them. */
13865 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13867 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13869 /* Attach template arguments to function. */
13870 if (!template_args
.empty ())
13872 gdb_assert (templ_func
!= NULL
);
13874 templ_func
->n_template_arguments
= template_args
.size ();
13875 templ_func
->template_arguments
13876 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13877 templ_func
->n_template_arguments
);
13878 memcpy (templ_func
->template_arguments
,
13879 template_args
.data (),
13880 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13882 /* Make sure that the symtab is set on the new symbols. Even
13883 though they don't appear in this symtab directly, other parts
13884 of gdb assume that symbols do, and this is reasonably
13886 for (symbol
*sym
: template_args
)
13887 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13890 /* In C++, we can have functions nested inside functions (e.g., when
13891 a function declares a class that has methods). This means that
13892 when we finish processing a function scope, we may need to go
13893 back to building a containing block's symbol lists. */
13894 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13895 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13897 /* If we've finished processing a top-level function, subsequent
13898 symbols go in the file symbol list. */
13899 if (cu
->get_builder ()->outermost_context_p ())
13900 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13903 /* Process all the DIES contained within a lexical block scope. Start
13904 a new scope, process the dies, and then close the scope. */
13907 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13909 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13910 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13911 CORE_ADDR lowpc
, highpc
;
13912 struct die_info
*child_die
;
13913 CORE_ADDR baseaddr
;
13915 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13917 /* Ignore blocks with missing or invalid low and high pc attributes. */
13918 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13919 as multiple lexical blocks? Handling children in a sane way would
13920 be nasty. Might be easier to properly extend generic blocks to
13921 describe ranges. */
13922 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13924 case PC_BOUNDS_NOT_PRESENT
:
13925 /* DW_TAG_lexical_block has no attributes, process its children as if
13926 there was no wrapping by that DW_TAG_lexical_block.
13927 GCC does no longer produces such DWARF since GCC r224161. */
13928 for (child_die
= die
->child
;
13929 child_die
!= NULL
&& child_die
->tag
;
13930 child_die
= sibling_die (child_die
))
13931 process_die (child_die
, cu
);
13933 case PC_BOUNDS_INVALID
:
13936 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13937 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13939 cu
->get_builder ()->push_context (0, lowpc
);
13940 if (die
->child
!= NULL
)
13942 child_die
= die
->child
;
13943 while (child_die
&& child_die
->tag
)
13945 process_die (child_die
, cu
);
13946 child_die
= sibling_die (child_die
);
13949 inherit_abstract_dies (die
, cu
);
13950 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13952 if (*cu
->get_builder ()->get_local_symbols () != NULL
13953 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13955 struct block
*block
13956 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13957 cstk
.start_addr
, highpc
);
13959 /* Note that recording ranges after traversing children, as we
13960 do here, means that recording a parent's ranges entails
13961 walking across all its children's ranges as they appear in
13962 the address map, which is quadratic behavior.
13964 It would be nicer to record the parent's ranges before
13965 traversing its children, simply overriding whatever you find
13966 there. But since we don't even decide whether to create a
13967 block until after we've traversed its children, that's hard
13969 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13971 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13972 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13975 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13978 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13980 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13981 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13982 CORE_ADDR pc
, baseaddr
;
13983 struct attribute
*attr
;
13984 struct call_site
*call_site
, call_site_local
;
13987 struct die_info
*child_die
;
13989 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13991 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13994 /* This was a pre-DWARF-5 GNU extension alias
13995 for DW_AT_call_return_pc. */
13996 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14000 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
14001 "DIE %s [in module %s]"),
14002 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14005 pc
= attr_value_as_address (attr
) + baseaddr
;
14006 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
14008 if (cu
->call_site_htab
== NULL
)
14009 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
14010 NULL
, &objfile
->objfile_obstack
,
14011 hashtab_obstack_allocate
, NULL
);
14012 call_site_local
.pc
= pc
;
14013 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
14016 complaint (_("Duplicate PC %s for DW_TAG_call_site "
14017 "DIE %s [in module %s]"),
14018 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
14019 objfile_name (objfile
));
14023 /* Count parameters at the caller. */
14026 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
14027 child_die
= sibling_die (child_die
))
14029 if (child_die
->tag
!= DW_TAG_call_site_parameter
14030 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14032 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
14033 "DW_TAG_call_site child DIE %s [in module %s]"),
14034 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
14035 objfile_name (objfile
));
14043 = ((struct call_site
*)
14044 obstack_alloc (&objfile
->objfile_obstack
,
14045 sizeof (*call_site
)
14046 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14048 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14049 call_site
->pc
= pc
;
14051 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14052 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14054 struct die_info
*func_die
;
14056 /* Skip also over DW_TAG_inlined_subroutine. */
14057 for (func_die
= die
->parent
;
14058 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14059 && func_die
->tag
!= DW_TAG_subroutine_type
;
14060 func_die
= func_die
->parent
);
14062 /* DW_AT_call_all_calls is a superset
14063 of DW_AT_call_all_tail_calls. */
14065 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14066 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14067 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14068 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14070 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14071 not complete. But keep CALL_SITE for look ups via call_site_htab,
14072 both the initial caller containing the real return address PC and
14073 the final callee containing the current PC of a chain of tail
14074 calls do not need to have the tail call list complete. But any
14075 function candidate for a virtual tail call frame searched via
14076 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14077 determined unambiguously. */
14081 struct type
*func_type
= NULL
;
14084 func_type
= get_die_type (func_die
, cu
);
14085 if (func_type
!= NULL
)
14087 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14089 /* Enlist this call site to the function. */
14090 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14091 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14094 complaint (_("Cannot find function owning DW_TAG_call_site "
14095 "DIE %s [in module %s]"),
14096 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14100 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14102 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14104 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14107 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14108 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14110 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14111 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14112 /* Keep NULL DWARF_BLOCK. */;
14113 else if (attr_form_is_block (attr
))
14115 struct dwarf2_locexpr_baton
*dlbaton
;
14117 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14118 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14119 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14120 dlbaton
->per_cu
= cu
->per_cu
;
14122 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14124 else if (attr_form_is_ref (attr
))
14126 struct dwarf2_cu
*target_cu
= cu
;
14127 struct die_info
*target_die
;
14129 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14130 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14131 if (die_is_declaration (target_die
, target_cu
))
14133 const char *target_physname
;
14135 /* Prefer the mangled name; otherwise compute the demangled one. */
14136 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14137 if (target_physname
== NULL
)
14138 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14139 if (target_physname
== NULL
)
14140 complaint (_("DW_AT_call_target target DIE has invalid "
14141 "physname, for referencing DIE %s [in module %s]"),
14142 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14144 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14150 /* DW_AT_entry_pc should be preferred. */
14151 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14152 <= PC_BOUNDS_INVALID
)
14153 complaint (_("DW_AT_call_target target DIE has invalid "
14154 "low pc, for referencing DIE %s [in module %s]"),
14155 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14158 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14159 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14164 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14165 "block nor reference, for DIE %s [in module %s]"),
14166 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14168 call_site
->per_cu
= cu
->per_cu
;
14170 for (child_die
= die
->child
;
14171 child_die
&& child_die
->tag
;
14172 child_die
= sibling_die (child_die
))
14174 struct call_site_parameter
*parameter
;
14175 struct attribute
*loc
, *origin
;
14177 if (child_die
->tag
!= DW_TAG_call_site_parameter
14178 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14180 /* Already printed the complaint above. */
14184 gdb_assert (call_site
->parameter_count
< nparams
);
14185 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14187 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14188 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14189 register is contained in DW_AT_call_value. */
14191 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14192 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14193 if (origin
== NULL
)
14195 /* This was a pre-DWARF-5 GNU extension alias
14196 for DW_AT_call_parameter. */
14197 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14199 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14201 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14203 sect_offset sect_off
14204 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14205 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14207 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14208 binding can be done only inside one CU. Such referenced DIE
14209 therefore cannot be even moved to DW_TAG_partial_unit. */
14210 complaint (_("DW_AT_call_parameter offset is not in CU for "
14211 "DW_TAG_call_site child DIE %s [in module %s]"),
14212 sect_offset_str (child_die
->sect_off
),
14213 objfile_name (objfile
));
14216 parameter
->u
.param_cu_off
14217 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14219 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14221 complaint (_("No DW_FORM_block* DW_AT_location for "
14222 "DW_TAG_call_site child DIE %s [in module %s]"),
14223 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14228 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14229 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14230 if (parameter
->u
.dwarf_reg
!= -1)
14231 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14232 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14233 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14234 ¶meter
->u
.fb_offset
))
14235 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14238 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14239 "for DW_FORM_block* DW_AT_location is supported for "
14240 "DW_TAG_call_site child DIE %s "
14242 sect_offset_str (child_die
->sect_off
),
14243 objfile_name (objfile
));
14248 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14250 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14251 if (!attr_form_is_block (attr
))
14253 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14254 "DW_TAG_call_site child DIE %s [in module %s]"),
14255 sect_offset_str (child_die
->sect_off
),
14256 objfile_name (objfile
));
14259 parameter
->value
= DW_BLOCK (attr
)->data
;
14260 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14262 /* Parameters are not pre-cleared by memset above. */
14263 parameter
->data_value
= NULL
;
14264 parameter
->data_value_size
= 0;
14265 call_site
->parameter_count
++;
14267 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14269 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14270 if (attr
!= nullptr)
14272 if (!attr_form_is_block (attr
))
14273 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14274 "DW_TAG_call_site child DIE %s [in module %s]"),
14275 sect_offset_str (child_die
->sect_off
),
14276 objfile_name (objfile
));
14279 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14280 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14286 /* Helper function for read_variable. If DIE represents a virtual
14287 table, then return the type of the concrete object that is
14288 associated with the virtual table. Otherwise, return NULL. */
14290 static struct type
*
14291 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14293 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14297 /* Find the type DIE. */
14298 struct die_info
*type_die
= NULL
;
14299 struct dwarf2_cu
*type_cu
= cu
;
14301 if (attr_form_is_ref (attr
))
14302 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14303 if (type_die
== NULL
)
14306 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14308 return die_containing_type (type_die
, type_cu
);
14311 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14314 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14316 struct rust_vtable_symbol
*storage
= NULL
;
14318 if (cu
->language
== language_rust
)
14320 struct type
*containing_type
= rust_containing_type (die
, cu
);
14322 if (containing_type
!= NULL
)
14324 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14326 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
14327 initialize_objfile_symbol (storage
);
14328 storage
->concrete_type
= containing_type
;
14329 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14333 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14334 struct attribute
*abstract_origin
14335 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14336 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14337 if (res
== NULL
&& loc
&& abstract_origin
)
14339 /* We have a variable without a name, but with a location and an abstract
14340 origin. This may be a concrete instance of an abstract variable
14341 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14343 struct dwarf2_cu
*origin_cu
= cu
;
14344 struct die_info
*origin_die
14345 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14346 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14347 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
14351 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14352 reading .debug_rnglists.
14353 Callback's type should be:
14354 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14355 Return true if the attributes are present and valid, otherwise,
14358 template <typename Callback
>
14360 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14361 Callback
&&callback
)
14363 struct dwarf2_per_objfile
*dwarf2_per_objfile
14364 = cu
->per_cu
->dwarf2_per_objfile
;
14365 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14366 bfd
*obfd
= objfile
->obfd
;
14367 /* Base address selection entry. */
14370 const gdb_byte
*buffer
;
14371 CORE_ADDR baseaddr
;
14372 bool overflow
= false;
14374 found_base
= cu
->base_known
;
14375 base
= cu
->base_address
;
14377 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14378 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14380 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14384 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14386 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14390 /* Initialize it due to a false compiler warning. */
14391 CORE_ADDR range_beginning
= 0, range_end
= 0;
14392 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14393 + dwarf2_per_objfile
->rnglists
.size
);
14394 unsigned int bytes_read
;
14396 if (buffer
== buf_end
)
14401 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14404 case DW_RLE_end_of_list
:
14406 case DW_RLE_base_address
:
14407 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14412 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14414 buffer
+= bytes_read
;
14416 case DW_RLE_start_length
:
14417 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14422 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14423 buffer
+= bytes_read
;
14424 range_end
= (range_beginning
14425 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14426 buffer
+= bytes_read
;
14427 if (buffer
> buf_end
)
14433 case DW_RLE_offset_pair
:
14434 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14435 buffer
+= bytes_read
;
14436 if (buffer
> buf_end
)
14441 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14442 buffer
+= bytes_read
;
14443 if (buffer
> buf_end
)
14449 case DW_RLE_start_end
:
14450 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14455 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14456 buffer
+= bytes_read
;
14457 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14458 buffer
+= bytes_read
;
14461 complaint (_("Invalid .debug_rnglists data (no base address)"));
14464 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14466 if (rlet
== DW_RLE_base_address
)
14471 /* We have no valid base address for the ranges
14473 complaint (_("Invalid .debug_rnglists data (no base address)"));
14477 if (range_beginning
> range_end
)
14479 /* Inverted range entries are invalid. */
14480 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14484 /* Empty range entries have no effect. */
14485 if (range_beginning
== range_end
)
14488 range_beginning
+= base
;
14491 /* A not-uncommon case of bad debug info.
14492 Don't pollute the addrmap with bad data. */
14493 if (range_beginning
+ baseaddr
== 0
14494 && !dwarf2_per_objfile
->has_section_at_zero
)
14496 complaint (_(".debug_rnglists entry has start address of zero"
14497 " [in module %s]"), objfile_name (objfile
));
14501 callback (range_beginning
, range_end
);
14506 complaint (_("Offset %d is not terminated "
14507 "for DW_AT_ranges attribute"),
14515 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14516 Callback's type should be:
14517 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14518 Return 1 if the attributes are present and valid, otherwise, return 0. */
14520 template <typename Callback
>
14522 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14523 Callback
&&callback
)
14525 struct dwarf2_per_objfile
*dwarf2_per_objfile
14526 = cu
->per_cu
->dwarf2_per_objfile
;
14527 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14528 struct comp_unit_head
*cu_header
= &cu
->header
;
14529 bfd
*obfd
= objfile
->obfd
;
14530 unsigned int addr_size
= cu_header
->addr_size
;
14531 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14532 /* Base address selection entry. */
14535 unsigned int dummy
;
14536 const gdb_byte
*buffer
;
14537 CORE_ADDR baseaddr
;
14539 if (cu_header
->version
>= 5)
14540 return dwarf2_rnglists_process (offset
, cu
, callback
);
14542 found_base
= cu
->base_known
;
14543 base
= cu
->base_address
;
14545 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14546 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14548 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14552 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14554 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14558 CORE_ADDR range_beginning
, range_end
;
14560 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14561 buffer
+= addr_size
;
14562 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14563 buffer
+= addr_size
;
14564 offset
+= 2 * addr_size
;
14566 /* An end of list marker is a pair of zero addresses. */
14567 if (range_beginning
== 0 && range_end
== 0)
14568 /* Found the end of list entry. */
14571 /* Each base address selection entry is a pair of 2 values.
14572 The first is the largest possible address, the second is
14573 the base address. Check for a base address here. */
14574 if ((range_beginning
& mask
) == mask
)
14576 /* If we found the largest possible address, then we already
14577 have the base address in range_end. */
14585 /* We have no valid base address for the ranges
14587 complaint (_("Invalid .debug_ranges data (no base address)"));
14591 if (range_beginning
> range_end
)
14593 /* Inverted range entries are invalid. */
14594 complaint (_("Invalid .debug_ranges data (inverted range)"));
14598 /* Empty range entries have no effect. */
14599 if (range_beginning
== range_end
)
14602 range_beginning
+= base
;
14605 /* A not-uncommon case of bad debug info.
14606 Don't pollute the addrmap with bad data. */
14607 if (range_beginning
+ baseaddr
== 0
14608 && !dwarf2_per_objfile
->has_section_at_zero
)
14610 complaint (_(".debug_ranges entry has start address of zero"
14611 " [in module %s]"), objfile_name (objfile
));
14615 callback (range_beginning
, range_end
);
14621 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14622 Return 1 if the attributes are present and valid, otherwise, return 0.
14623 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14626 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14627 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14628 struct partial_symtab
*ranges_pst
)
14630 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14631 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14632 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14633 SECT_OFF_TEXT (objfile
));
14636 CORE_ADDR high
= 0;
14639 retval
= dwarf2_ranges_process (offset
, cu
,
14640 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14642 if (ranges_pst
!= NULL
)
14647 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14648 range_beginning
+ baseaddr
)
14650 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14651 range_end
+ baseaddr
)
14653 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14654 lowpc
, highpc
- 1, ranges_pst
);
14657 /* FIXME: This is recording everything as a low-high
14658 segment of consecutive addresses. We should have a
14659 data structure for discontiguous block ranges
14663 low
= range_beginning
;
14669 if (range_beginning
< low
)
14670 low
= range_beginning
;
14671 if (range_end
> high
)
14679 /* If the first entry is an end-of-list marker, the range
14680 describes an empty scope, i.e. no instructions. */
14686 *high_return
= high
;
14690 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14691 definition for the return value. *LOWPC and *HIGHPC are set iff
14692 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14694 static enum pc_bounds_kind
14695 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14696 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14697 struct partial_symtab
*pst
)
14699 struct dwarf2_per_objfile
*dwarf2_per_objfile
14700 = cu
->per_cu
->dwarf2_per_objfile
;
14701 struct attribute
*attr
;
14702 struct attribute
*attr_high
;
14704 CORE_ADDR high
= 0;
14705 enum pc_bounds_kind ret
;
14707 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14710 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14711 if (attr
!= nullptr)
14713 low
= attr_value_as_address (attr
);
14714 high
= attr_value_as_address (attr_high
);
14715 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14719 /* Found high w/o low attribute. */
14720 return PC_BOUNDS_INVALID
;
14722 /* Found consecutive range of addresses. */
14723 ret
= PC_BOUNDS_HIGH_LOW
;
14727 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14730 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14731 We take advantage of the fact that DW_AT_ranges does not appear
14732 in DW_TAG_compile_unit of DWO files. */
14733 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14734 unsigned int ranges_offset
= (DW_UNSND (attr
)
14735 + (need_ranges_base
14739 /* Value of the DW_AT_ranges attribute is the offset in the
14740 .debug_ranges section. */
14741 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14742 return PC_BOUNDS_INVALID
;
14743 /* Found discontinuous range of addresses. */
14744 ret
= PC_BOUNDS_RANGES
;
14747 return PC_BOUNDS_NOT_PRESENT
;
14750 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14752 return PC_BOUNDS_INVALID
;
14754 /* When using the GNU linker, .gnu.linkonce. sections are used to
14755 eliminate duplicate copies of functions and vtables and such.
14756 The linker will arbitrarily choose one and discard the others.
14757 The AT_*_pc values for such functions refer to local labels in
14758 these sections. If the section from that file was discarded, the
14759 labels are not in the output, so the relocs get a value of 0.
14760 If this is a discarded function, mark the pc bounds as invalid,
14761 so that GDB will ignore it. */
14762 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14763 return PC_BOUNDS_INVALID
;
14771 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14772 its low and high PC addresses. Do nothing if these addresses could not
14773 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14774 and HIGHPC to the high address if greater than HIGHPC. */
14777 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14778 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14779 struct dwarf2_cu
*cu
)
14781 CORE_ADDR low
, high
;
14782 struct die_info
*child
= die
->child
;
14784 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14786 *lowpc
= std::min (*lowpc
, low
);
14787 *highpc
= std::max (*highpc
, high
);
14790 /* If the language does not allow nested subprograms (either inside
14791 subprograms or lexical blocks), we're done. */
14792 if (cu
->language
!= language_ada
)
14795 /* Check all the children of the given DIE. If it contains nested
14796 subprograms, then check their pc bounds. Likewise, we need to
14797 check lexical blocks as well, as they may also contain subprogram
14799 while (child
&& child
->tag
)
14801 if (child
->tag
== DW_TAG_subprogram
14802 || child
->tag
== DW_TAG_lexical_block
)
14803 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14804 child
= sibling_die (child
);
14808 /* Get the low and high pc's represented by the scope DIE, and store
14809 them in *LOWPC and *HIGHPC. If the correct values can't be
14810 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14813 get_scope_pc_bounds (struct die_info
*die
,
14814 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14815 struct dwarf2_cu
*cu
)
14817 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14818 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14819 CORE_ADDR current_low
, current_high
;
14821 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14822 >= PC_BOUNDS_RANGES
)
14824 best_low
= current_low
;
14825 best_high
= current_high
;
14829 struct die_info
*child
= die
->child
;
14831 while (child
&& child
->tag
)
14833 switch (child
->tag
) {
14834 case DW_TAG_subprogram
:
14835 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14837 case DW_TAG_namespace
:
14838 case DW_TAG_module
:
14839 /* FIXME: carlton/2004-01-16: Should we do this for
14840 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14841 that current GCC's always emit the DIEs corresponding
14842 to definitions of methods of classes as children of a
14843 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14844 the DIEs giving the declarations, which could be
14845 anywhere). But I don't see any reason why the
14846 standards says that they have to be there. */
14847 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14849 if (current_low
!= ((CORE_ADDR
) -1))
14851 best_low
= std::min (best_low
, current_low
);
14852 best_high
= std::max (best_high
, current_high
);
14860 child
= sibling_die (child
);
14865 *highpc
= best_high
;
14868 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14872 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14873 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14875 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14876 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14877 struct attribute
*attr
;
14878 struct attribute
*attr_high
;
14880 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14883 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14884 if (attr
!= nullptr)
14886 CORE_ADDR low
= attr_value_as_address (attr
);
14887 CORE_ADDR high
= attr_value_as_address (attr_high
);
14889 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14892 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14893 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14894 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14898 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14899 if (attr
!= nullptr)
14901 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14902 We take advantage of the fact that DW_AT_ranges does not appear
14903 in DW_TAG_compile_unit of DWO files. */
14904 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14906 /* The value of the DW_AT_ranges attribute is the offset of the
14907 address range list in the .debug_ranges section. */
14908 unsigned long offset
= (DW_UNSND (attr
)
14909 + (need_ranges_base
? cu
->ranges_base
: 0));
14911 std::vector
<blockrange
> blockvec
;
14912 dwarf2_ranges_process (offset
, cu
,
14913 [&] (CORE_ADDR start
, CORE_ADDR end
)
14917 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14918 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14919 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14920 blockvec
.emplace_back (start
, end
);
14923 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14927 /* Check whether the producer field indicates either of GCC < 4.6, or the
14928 Intel C/C++ compiler, and cache the result in CU. */
14931 check_producer (struct dwarf2_cu
*cu
)
14935 if (cu
->producer
== NULL
)
14937 /* For unknown compilers expect their behavior is DWARF version
14940 GCC started to support .debug_types sections by -gdwarf-4 since
14941 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14942 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14943 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14944 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14946 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14948 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14949 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14951 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14953 cu
->producer_is_icc
= true;
14954 cu
->producer_is_icc_lt_14
= major
< 14;
14956 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14957 cu
->producer_is_codewarrior
= true;
14960 /* For other non-GCC compilers, expect their behavior is DWARF version
14964 cu
->checked_producer
= true;
14967 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14968 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14969 during 4.6.0 experimental. */
14972 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14974 if (!cu
->checked_producer
)
14975 check_producer (cu
);
14977 return cu
->producer_is_gxx_lt_4_6
;
14981 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14982 with incorrect is_stmt attributes. */
14985 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14987 if (!cu
->checked_producer
)
14988 check_producer (cu
);
14990 return cu
->producer_is_codewarrior
;
14993 /* Return the default accessibility type if it is not overridden by
14994 DW_AT_accessibility. */
14996 static enum dwarf_access_attribute
14997 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14999 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
15001 /* The default DWARF 2 accessibility for members is public, the default
15002 accessibility for inheritance is private. */
15004 if (die
->tag
!= DW_TAG_inheritance
)
15005 return DW_ACCESS_public
;
15007 return DW_ACCESS_private
;
15011 /* DWARF 3+ defines the default accessibility a different way. The same
15012 rules apply now for DW_TAG_inheritance as for the members and it only
15013 depends on the container kind. */
15015 if (die
->parent
->tag
== DW_TAG_class_type
)
15016 return DW_ACCESS_private
;
15018 return DW_ACCESS_public
;
15022 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
15023 offset. If the attribute was not found return 0, otherwise return
15024 1. If it was found but could not properly be handled, set *OFFSET
15028 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15031 struct attribute
*attr
;
15033 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15038 /* Note that we do not check for a section offset first here.
15039 This is because DW_AT_data_member_location is new in DWARF 4,
15040 so if we see it, we can assume that a constant form is really
15041 a constant and not a section offset. */
15042 if (attr_form_is_constant (attr
))
15043 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15044 else if (attr_form_is_section_offset (attr
))
15045 dwarf2_complex_location_expr_complaint ();
15046 else if (attr_form_is_block (attr
))
15047 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15049 dwarf2_complex_location_expr_complaint ();
15057 /* Add an aggregate field to the field list. */
15060 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15061 struct dwarf2_cu
*cu
)
15063 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15064 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15065 struct nextfield
*new_field
;
15066 struct attribute
*attr
;
15068 const char *fieldname
= "";
15070 if (die
->tag
== DW_TAG_inheritance
)
15072 fip
->baseclasses
.emplace_back ();
15073 new_field
= &fip
->baseclasses
.back ();
15077 fip
->fields
.emplace_back ();
15078 new_field
= &fip
->fields
.back ();
15083 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15084 if (attr
!= nullptr)
15085 new_field
->accessibility
= DW_UNSND (attr
);
15087 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15088 if (new_field
->accessibility
!= DW_ACCESS_public
)
15089 fip
->non_public_fields
= 1;
15091 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15092 if (attr
!= nullptr)
15093 new_field
->virtuality
= DW_UNSND (attr
);
15095 new_field
->virtuality
= DW_VIRTUALITY_none
;
15097 fp
= &new_field
->field
;
15099 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15103 /* Data member other than a C++ static data member. */
15105 /* Get type of field. */
15106 fp
->type
= die_type (die
, cu
);
15108 SET_FIELD_BITPOS (*fp
, 0);
15110 /* Get bit size of field (zero if none). */
15111 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15112 if (attr
!= nullptr)
15114 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15118 FIELD_BITSIZE (*fp
) = 0;
15121 /* Get bit offset of field. */
15122 if (handle_data_member_location (die
, cu
, &offset
))
15123 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15124 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15125 if (attr
!= nullptr)
15127 if (gdbarch_bits_big_endian (gdbarch
))
15129 /* For big endian bits, the DW_AT_bit_offset gives the
15130 additional bit offset from the MSB of the containing
15131 anonymous object to the MSB of the field. We don't
15132 have to do anything special since we don't need to
15133 know the size of the anonymous object. */
15134 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15138 /* For little endian bits, compute the bit offset to the
15139 MSB of the anonymous object, subtract off the number of
15140 bits from the MSB of the field to the MSB of the
15141 object, and then subtract off the number of bits of
15142 the field itself. The result is the bit offset of
15143 the LSB of the field. */
15144 int anonymous_size
;
15145 int bit_offset
= DW_UNSND (attr
);
15147 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15148 if (attr
!= nullptr)
15150 /* The size of the anonymous object containing
15151 the bit field is explicit, so use the
15152 indicated size (in bytes). */
15153 anonymous_size
= DW_UNSND (attr
);
15157 /* The size of the anonymous object containing
15158 the bit field must be inferred from the type
15159 attribute of the data member containing the
15161 anonymous_size
= TYPE_LENGTH (fp
->type
);
15163 SET_FIELD_BITPOS (*fp
,
15164 (FIELD_BITPOS (*fp
)
15165 + anonymous_size
* bits_per_byte
15166 - bit_offset
- FIELD_BITSIZE (*fp
)));
15169 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15171 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15172 + dwarf2_get_attr_constant_value (attr
, 0)));
15174 /* Get name of field. */
15175 fieldname
= dwarf2_name (die
, cu
);
15176 if (fieldname
== NULL
)
15179 /* The name is already allocated along with this objfile, so we don't
15180 need to duplicate it for the type. */
15181 fp
->name
= fieldname
;
15183 /* Change accessibility for artificial fields (e.g. virtual table
15184 pointer or virtual base class pointer) to private. */
15185 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15187 FIELD_ARTIFICIAL (*fp
) = 1;
15188 new_field
->accessibility
= DW_ACCESS_private
;
15189 fip
->non_public_fields
= 1;
15192 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15194 /* C++ static member. */
15196 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15197 is a declaration, but all versions of G++ as of this writing
15198 (so through at least 3.2.1) incorrectly generate
15199 DW_TAG_variable tags. */
15201 const char *physname
;
15203 /* Get name of field. */
15204 fieldname
= dwarf2_name (die
, cu
);
15205 if (fieldname
== NULL
)
15208 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15210 /* Only create a symbol if this is an external value.
15211 new_symbol checks this and puts the value in the global symbol
15212 table, which we want. If it is not external, new_symbol
15213 will try to put the value in cu->list_in_scope which is wrong. */
15214 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15216 /* A static const member, not much different than an enum as far as
15217 we're concerned, except that we can support more types. */
15218 new_symbol (die
, NULL
, cu
);
15221 /* Get physical name. */
15222 physname
= dwarf2_physname (fieldname
, die
, cu
);
15224 /* The name is already allocated along with this objfile, so we don't
15225 need to duplicate it for the type. */
15226 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15227 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15228 FIELD_NAME (*fp
) = fieldname
;
15230 else if (die
->tag
== DW_TAG_inheritance
)
15234 /* C++ base class field. */
15235 if (handle_data_member_location (die
, cu
, &offset
))
15236 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15237 FIELD_BITSIZE (*fp
) = 0;
15238 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15239 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
15241 else if (die
->tag
== DW_TAG_variant_part
)
15243 /* process_structure_scope will treat this DIE as a union. */
15244 process_structure_scope (die
, cu
);
15246 /* The variant part is relative to the start of the enclosing
15248 SET_FIELD_BITPOS (*fp
, 0);
15249 fp
->type
= get_die_type (die
, cu
);
15250 fp
->artificial
= 1;
15251 fp
->name
= "<<variant>>";
15253 /* Normally a DW_TAG_variant_part won't have a size, but our
15254 representation requires one, so set it to the maximum of the
15256 if (TYPE_LENGTH (fp
->type
) == 0)
15259 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
15260 if (TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)) > max
)
15261 max
= TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
));
15262 TYPE_LENGTH (fp
->type
) = max
;
15266 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15269 /* Can the type given by DIE define another type? */
15272 type_can_define_types (const struct die_info
*die
)
15276 case DW_TAG_typedef
:
15277 case DW_TAG_class_type
:
15278 case DW_TAG_structure_type
:
15279 case DW_TAG_union_type
:
15280 case DW_TAG_enumeration_type
:
15288 /* Add a type definition defined in the scope of the FIP's class. */
15291 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15292 struct dwarf2_cu
*cu
)
15294 struct decl_field fp
;
15295 memset (&fp
, 0, sizeof (fp
));
15297 gdb_assert (type_can_define_types (die
));
15299 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15300 fp
.name
= dwarf2_name (die
, cu
);
15301 fp
.type
= read_type_die (die
, cu
);
15303 /* Save accessibility. */
15304 enum dwarf_access_attribute accessibility
;
15305 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15307 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15309 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15310 switch (accessibility
)
15312 case DW_ACCESS_public
:
15313 /* The assumed value if neither private nor protected. */
15315 case DW_ACCESS_private
:
15318 case DW_ACCESS_protected
:
15319 fp
.is_protected
= 1;
15322 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15325 if (die
->tag
== DW_TAG_typedef
)
15326 fip
->typedef_field_list
.push_back (fp
);
15328 fip
->nested_types_list
.push_back (fp
);
15331 /* Create the vector of fields, and attach it to the type. */
15334 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15335 struct dwarf2_cu
*cu
)
15337 int nfields
= fip
->nfields
;
15339 /* Record the field count, allocate space for the array of fields,
15340 and create blank accessibility bitfields if necessary. */
15341 TYPE_NFIELDS (type
) = nfields
;
15342 TYPE_FIELDS (type
) = (struct field
*)
15343 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15345 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15347 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15349 TYPE_FIELD_PRIVATE_BITS (type
) =
15350 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15351 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15353 TYPE_FIELD_PROTECTED_BITS (type
) =
15354 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15355 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15357 TYPE_FIELD_IGNORE_BITS (type
) =
15358 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15359 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15362 /* If the type has baseclasses, allocate and clear a bit vector for
15363 TYPE_FIELD_VIRTUAL_BITS. */
15364 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15366 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15367 unsigned char *pointer
;
15369 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15370 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15371 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15372 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15373 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15376 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15378 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15380 for (int index
= 0; index
< nfields
; ++index
)
15382 struct nextfield
&field
= fip
->fields
[index
];
15384 if (field
.variant
.is_discriminant
)
15385 di
->discriminant_index
= index
;
15386 else if (field
.variant
.default_branch
)
15387 di
->default_index
= index
;
15389 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15393 /* Copy the saved-up fields into the field vector. */
15394 for (int i
= 0; i
< nfields
; ++i
)
15396 struct nextfield
&field
15397 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15398 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15400 TYPE_FIELD (type
, i
) = field
.field
;
15401 switch (field
.accessibility
)
15403 case DW_ACCESS_private
:
15404 if (cu
->language
!= language_ada
)
15405 SET_TYPE_FIELD_PRIVATE (type
, i
);
15408 case DW_ACCESS_protected
:
15409 if (cu
->language
!= language_ada
)
15410 SET_TYPE_FIELD_PROTECTED (type
, i
);
15413 case DW_ACCESS_public
:
15417 /* Unknown accessibility. Complain and treat it as public. */
15419 complaint (_("unsupported accessibility %d"),
15420 field
.accessibility
);
15424 if (i
< fip
->baseclasses
.size ())
15426 switch (field
.virtuality
)
15428 case DW_VIRTUALITY_virtual
:
15429 case DW_VIRTUALITY_pure_virtual
:
15430 if (cu
->language
== language_ada
)
15431 error (_("unexpected virtuality in component of Ada type"));
15432 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15439 /* Return true if this member function is a constructor, false
15443 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15445 const char *fieldname
;
15446 const char *type_name
;
15449 if (die
->parent
== NULL
)
15452 if (die
->parent
->tag
!= DW_TAG_structure_type
15453 && die
->parent
->tag
!= DW_TAG_union_type
15454 && die
->parent
->tag
!= DW_TAG_class_type
)
15457 fieldname
= dwarf2_name (die
, cu
);
15458 type_name
= dwarf2_name (die
->parent
, cu
);
15459 if (fieldname
== NULL
|| type_name
== NULL
)
15462 len
= strlen (fieldname
);
15463 return (strncmp (fieldname
, type_name
, len
) == 0
15464 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15467 /* Add a member function to the proper fieldlist. */
15470 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15471 struct type
*type
, struct dwarf2_cu
*cu
)
15473 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15474 struct attribute
*attr
;
15476 struct fnfieldlist
*flp
= nullptr;
15477 struct fn_field
*fnp
;
15478 const char *fieldname
;
15479 struct type
*this_type
;
15480 enum dwarf_access_attribute accessibility
;
15482 if (cu
->language
== language_ada
)
15483 error (_("unexpected member function in Ada type"));
15485 /* Get name of member function. */
15486 fieldname
= dwarf2_name (die
, cu
);
15487 if (fieldname
== NULL
)
15490 /* Look up member function name in fieldlist. */
15491 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15493 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15495 flp
= &fip
->fnfieldlists
[i
];
15500 /* Create a new fnfieldlist if necessary. */
15501 if (flp
== nullptr)
15503 fip
->fnfieldlists
.emplace_back ();
15504 flp
= &fip
->fnfieldlists
.back ();
15505 flp
->name
= fieldname
;
15506 i
= fip
->fnfieldlists
.size () - 1;
15509 /* Create a new member function field and add it to the vector of
15511 flp
->fnfields
.emplace_back ();
15512 fnp
= &flp
->fnfields
.back ();
15514 /* Delay processing of the physname until later. */
15515 if (cu
->language
== language_cplus
)
15516 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15520 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15521 fnp
->physname
= physname
? physname
: "";
15524 fnp
->type
= alloc_type (objfile
);
15525 this_type
= read_type_die (die
, cu
);
15526 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15528 int nparams
= TYPE_NFIELDS (this_type
);
15530 /* TYPE is the domain of this method, and THIS_TYPE is the type
15531 of the method itself (TYPE_CODE_METHOD). */
15532 smash_to_method_type (fnp
->type
, type
,
15533 TYPE_TARGET_TYPE (this_type
),
15534 TYPE_FIELDS (this_type
),
15535 TYPE_NFIELDS (this_type
),
15536 TYPE_VARARGS (this_type
));
15538 /* Handle static member functions.
15539 Dwarf2 has no clean way to discern C++ static and non-static
15540 member functions. G++ helps GDB by marking the first
15541 parameter for non-static member functions (which is the this
15542 pointer) as artificial. We obtain this information from
15543 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15544 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15545 fnp
->voffset
= VOFFSET_STATIC
;
15548 complaint (_("member function type missing for '%s'"),
15549 dwarf2_full_name (fieldname
, die
, cu
));
15551 /* Get fcontext from DW_AT_containing_type if present. */
15552 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15553 fnp
->fcontext
= die_containing_type (die
, cu
);
15555 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15556 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15558 /* Get accessibility. */
15559 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15560 if (attr
!= nullptr)
15561 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15563 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15564 switch (accessibility
)
15566 case DW_ACCESS_private
:
15567 fnp
->is_private
= 1;
15569 case DW_ACCESS_protected
:
15570 fnp
->is_protected
= 1;
15574 /* Check for artificial methods. */
15575 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15576 if (attr
&& DW_UNSND (attr
) != 0)
15577 fnp
->is_artificial
= 1;
15579 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15581 /* Get index in virtual function table if it is a virtual member
15582 function. For older versions of GCC, this is an offset in the
15583 appropriate virtual table, as specified by DW_AT_containing_type.
15584 For everyone else, it is an expression to be evaluated relative
15585 to the object address. */
15587 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15588 if (attr
!= nullptr)
15590 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15592 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15594 /* Old-style GCC. */
15595 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15597 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15598 || (DW_BLOCK (attr
)->size
> 1
15599 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15600 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15602 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15603 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15604 dwarf2_complex_location_expr_complaint ();
15606 fnp
->voffset
/= cu
->header
.addr_size
;
15610 dwarf2_complex_location_expr_complaint ();
15612 if (!fnp
->fcontext
)
15614 /* If there is no `this' field and no DW_AT_containing_type,
15615 we cannot actually find a base class context for the
15617 if (TYPE_NFIELDS (this_type
) == 0
15618 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15620 complaint (_("cannot determine context for virtual member "
15621 "function \"%s\" (offset %s)"),
15622 fieldname
, sect_offset_str (die
->sect_off
));
15627 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15631 else if (attr_form_is_section_offset (attr
))
15633 dwarf2_complex_location_expr_complaint ();
15637 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15643 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15644 if (attr
&& DW_UNSND (attr
))
15646 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15647 complaint (_("Member function \"%s\" (offset %s) is virtual "
15648 "but the vtable offset is not specified"),
15649 fieldname
, sect_offset_str (die
->sect_off
));
15650 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15651 TYPE_CPLUS_DYNAMIC (type
) = 1;
15656 /* Create the vector of member function fields, and attach it to the type. */
15659 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15660 struct dwarf2_cu
*cu
)
15662 if (cu
->language
== language_ada
)
15663 error (_("unexpected member functions in Ada type"));
15665 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15666 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15668 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15670 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15672 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15673 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15675 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15676 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15677 fn_flp
->fn_fields
= (struct fn_field
*)
15678 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15680 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15681 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15684 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15687 /* Returns non-zero if NAME is the name of a vtable member in CU's
15688 language, zero otherwise. */
15690 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15692 static const char vptr
[] = "_vptr";
15694 /* Look for the C++ form of the vtable. */
15695 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15701 /* GCC outputs unnamed structures that are really pointers to member
15702 functions, with the ABI-specified layout. If TYPE describes
15703 such a structure, smash it into a member function type.
15705 GCC shouldn't do this; it should just output pointer to member DIEs.
15706 This is GCC PR debug/28767. */
15709 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15711 struct type
*pfn_type
, *self_type
, *new_type
;
15713 /* Check for a structure with no name and two children. */
15714 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15717 /* Check for __pfn and __delta members. */
15718 if (TYPE_FIELD_NAME (type
, 0) == NULL
15719 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15720 || TYPE_FIELD_NAME (type
, 1) == NULL
15721 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15724 /* Find the type of the method. */
15725 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15726 if (pfn_type
== NULL
15727 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15728 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15731 /* Look for the "this" argument. */
15732 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15733 if (TYPE_NFIELDS (pfn_type
) == 0
15734 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15735 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15738 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15739 new_type
= alloc_type (objfile
);
15740 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15741 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15742 TYPE_VARARGS (pfn_type
));
15743 smash_to_methodptr_type (type
, new_type
);
15746 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15747 appropriate error checking and issuing complaints if there is a
15751 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15753 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15755 if (attr
== nullptr)
15758 if (!attr_form_is_constant (attr
))
15760 complaint (_("DW_AT_alignment must have constant form"
15761 " - DIE at %s [in module %s]"),
15762 sect_offset_str (die
->sect_off
),
15763 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15768 if (attr
->form
== DW_FORM_sdata
)
15770 LONGEST val
= DW_SND (attr
);
15773 complaint (_("DW_AT_alignment value must not be negative"
15774 " - DIE at %s [in module %s]"),
15775 sect_offset_str (die
->sect_off
),
15776 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15782 align
= DW_UNSND (attr
);
15786 complaint (_("DW_AT_alignment value must not be zero"
15787 " - DIE at %s [in module %s]"),
15788 sect_offset_str (die
->sect_off
),
15789 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15792 if ((align
& (align
- 1)) != 0)
15794 complaint (_("DW_AT_alignment value must be a power of 2"
15795 " - DIE at %s [in module %s]"),
15796 sect_offset_str (die
->sect_off
),
15797 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15804 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15805 the alignment for TYPE. */
15808 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15811 if (!set_type_align (type
, get_alignment (cu
, die
)))
15812 complaint (_("DW_AT_alignment value too large"
15813 " - DIE at %s [in module %s]"),
15814 sect_offset_str (die
->sect_off
),
15815 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15818 /* Called when we find the DIE that starts a structure or union scope
15819 (definition) to create a type for the structure or union. Fill in
15820 the type's name and general properties; the members will not be
15821 processed until process_structure_scope. A symbol table entry for
15822 the type will also not be done until process_structure_scope (assuming
15823 the type has a name).
15825 NOTE: we need to call these functions regardless of whether or not the
15826 DIE has a DW_AT_name attribute, since it might be an anonymous
15827 structure or union. This gets the type entered into our set of
15828 user defined types. */
15830 static struct type
*
15831 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15833 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15835 struct attribute
*attr
;
15838 /* If the definition of this type lives in .debug_types, read that type.
15839 Don't follow DW_AT_specification though, that will take us back up
15840 the chain and we want to go down. */
15841 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15842 if (attr
!= nullptr)
15844 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15846 /* The type's CU may not be the same as CU.
15847 Ensure TYPE is recorded with CU in die_type_hash. */
15848 return set_die_type (die
, type
, cu
);
15851 type
= alloc_type (objfile
);
15852 INIT_CPLUS_SPECIFIC (type
);
15854 name
= dwarf2_name (die
, cu
);
15857 if (cu
->language
== language_cplus
15858 || cu
->language
== language_d
15859 || cu
->language
== language_rust
)
15861 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15863 /* dwarf2_full_name might have already finished building the DIE's
15864 type. If so, there is no need to continue. */
15865 if (get_die_type (die
, cu
) != NULL
)
15866 return get_die_type (die
, cu
);
15868 TYPE_NAME (type
) = full_name
;
15872 /* The name is already allocated along with this objfile, so
15873 we don't need to duplicate it for the type. */
15874 TYPE_NAME (type
) = name
;
15878 if (die
->tag
== DW_TAG_structure_type
)
15880 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15882 else if (die
->tag
== DW_TAG_union_type
)
15884 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15886 else if (die
->tag
== DW_TAG_variant_part
)
15888 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15889 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15893 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15896 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15897 TYPE_DECLARED_CLASS (type
) = 1;
15899 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15900 if (attr
!= nullptr)
15902 if (attr_form_is_constant (attr
))
15903 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15906 /* For the moment, dynamic type sizes are not supported
15907 by GDB's struct type. The actual size is determined
15908 on-demand when resolving the type of a given object,
15909 so set the type's length to zero for now. Otherwise,
15910 we record an expression as the length, and that expression
15911 could lead to a very large value, which could eventually
15912 lead to us trying to allocate that much memory when creating
15913 a value of that type. */
15914 TYPE_LENGTH (type
) = 0;
15919 TYPE_LENGTH (type
) = 0;
15922 maybe_set_alignment (cu
, die
, type
);
15924 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15926 /* ICC<14 does not output the required DW_AT_declaration on
15927 incomplete types, but gives them a size of zero. */
15928 TYPE_STUB (type
) = 1;
15931 TYPE_STUB_SUPPORTED (type
) = 1;
15933 if (die_is_declaration (die
, cu
))
15934 TYPE_STUB (type
) = 1;
15935 else if (attr
== NULL
&& die
->child
== NULL
15936 && producer_is_realview (cu
->producer
))
15937 /* RealView does not output the required DW_AT_declaration
15938 on incomplete types. */
15939 TYPE_STUB (type
) = 1;
15941 /* We need to add the type field to the die immediately so we don't
15942 infinitely recurse when dealing with pointers to the structure
15943 type within the structure itself. */
15944 set_die_type (die
, type
, cu
);
15946 /* set_die_type should be already done. */
15947 set_descriptive_type (type
, die
, cu
);
15952 /* A helper for process_structure_scope that handles a single member
15956 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15957 struct field_info
*fi
,
15958 std::vector
<struct symbol
*> *template_args
,
15959 struct dwarf2_cu
*cu
)
15961 if (child_die
->tag
== DW_TAG_member
15962 || child_die
->tag
== DW_TAG_variable
15963 || child_die
->tag
== DW_TAG_variant_part
)
15965 /* NOTE: carlton/2002-11-05: A C++ static data member
15966 should be a DW_TAG_member that is a declaration, but
15967 all versions of G++ as of this writing (so through at
15968 least 3.2.1) incorrectly generate DW_TAG_variable
15969 tags for them instead. */
15970 dwarf2_add_field (fi
, child_die
, cu
);
15972 else if (child_die
->tag
== DW_TAG_subprogram
)
15974 /* Rust doesn't have member functions in the C++ sense.
15975 However, it does emit ordinary functions as children
15976 of a struct DIE. */
15977 if (cu
->language
== language_rust
)
15978 read_func_scope (child_die
, cu
);
15981 /* C++ member function. */
15982 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15985 else if (child_die
->tag
== DW_TAG_inheritance
)
15987 /* C++ base class field. */
15988 dwarf2_add_field (fi
, child_die
, cu
);
15990 else if (type_can_define_types (child_die
))
15991 dwarf2_add_type_defn (fi
, child_die
, cu
);
15992 else if (child_die
->tag
== DW_TAG_template_type_param
15993 || child_die
->tag
== DW_TAG_template_value_param
)
15995 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15998 template_args
->push_back (arg
);
16000 else if (child_die
->tag
== DW_TAG_variant
)
16002 /* In a variant we want to get the discriminant and also add a
16003 field for our sole member child. */
16004 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
16006 for (die_info
*variant_child
= child_die
->child
;
16007 variant_child
!= NULL
;
16008 variant_child
= sibling_die (variant_child
))
16010 if (variant_child
->tag
== DW_TAG_member
)
16012 handle_struct_member_die (variant_child
, type
, fi
,
16013 template_args
, cu
);
16014 /* Only handle the one. */
16019 /* We don't handle this but we might as well report it if we see
16021 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
16022 complaint (_("DW_AT_discr_list is not supported yet"
16023 " - DIE at %s [in module %s]"),
16024 sect_offset_str (child_die
->sect_off
),
16025 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16027 /* The first field was just added, so we can stash the
16028 discriminant there. */
16029 gdb_assert (!fi
->fields
.empty ());
16031 fi
->fields
.back ().variant
.default_branch
= true;
16033 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16037 /* Finish creating a structure or union type, including filling in
16038 its members and creating a symbol for it. */
16041 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16043 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16044 struct die_info
*child_die
;
16047 type
= get_die_type (die
, cu
);
16049 type
= read_structure_type (die
, cu
);
16051 /* When reading a DW_TAG_variant_part, we need to notice when we
16052 read the discriminant member, so we can record it later in the
16053 discriminant_info. */
16054 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16055 sect_offset discr_offset
;
16056 bool has_template_parameters
= false;
16058 if (is_variant_part
)
16060 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16063 /* Maybe it's a univariant form, an extension we support.
16064 In this case arrange not to check the offset. */
16065 is_variant_part
= false;
16067 else if (attr_form_is_ref (discr
))
16069 struct dwarf2_cu
*target_cu
= cu
;
16070 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16072 discr_offset
= target_die
->sect_off
;
16076 complaint (_("DW_AT_discr does not have DIE reference form"
16077 " - DIE at %s [in module %s]"),
16078 sect_offset_str (die
->sect_off
),
16079 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16080 is_variant_part
= false;
16084 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16086 struct field_info fi
;
16087 std::vector
<struct symbol
*> template_args
;
16089 child_die
= die
->child
;
16091 while (child_die
&& child_die
->tag
)
16093 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16095 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16096 fi
.fields
.back ().variant
.is_discriminant
= true;
16098 child_die
= sibling_die (child_die
);
16101 /* Attach template arguments to type. */
16102 if (!template_args
.empty ())
16104 has_template_parameters
= true;
16105 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16106 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16107 TYPE_TEMPLATE_ARGUMENTS (type
)
16108 = XOBNEWVEC (&objfile
->objfile_obstack
,
16110 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16111 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16112 template_args
.data (),
16113 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16114 * sizeof (struct symbol
*)));
16117 /* Attach fields and member functions to the type. */
16119 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16120 if (!fi
.fnfieldlists
.empty ())
16122 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16124 /* Get the type which refers to the base class (possibly this
16125 class itself) which contains the vtable pointer for the current
16126 class from the DW_AT_containing_type attribute. This use of
16127 DW_AT_containing_type is a GNU extension. */
16129 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16131 struct type
*t
= die_containing_type (die
, cu
);
16133 set_type_vptr_basetype (type
, t
);
16138 /* Our own class provides vtbl ptr. */
16139 for (i
= TYPE_NFIELDS (t
) - 1;
16140 i
>= TYPE_N_BASECLASSES (t
);
16143 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16145 if (is_vtable_name (fieldname
, cu
))
16147 set_type_vptr_fieldno (type
, i
);
16152 /* Complain if virtual function table field not found. */
16153 if (i
< TYPE_N_BASECLASSES (t
))
16154 complaint (_("virtual function table pointer "
16155 "not found when defining class '%s'"),
16156 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16160 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16163 else if (cu
->producer
16164 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16166 /* The IBM XLC compiler does not provide direct indication
16167 of the containing type, but the vtable pointer is
16168 always named __vfp. */
16172 for (i
= TYPE_NFIELDS (type
) - 1;
16173 i
>= TYPE_N_BASECLASSES (type
);
16176 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16178 set_type_vptr_fieldno (type
, i
);
16179 set_type_vptr_basetype (type
, type
);
16186 /* Copy fi.typedef_field_list linked list elements content into the
16187 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16188 if (!fi
.typedef_field_list
.empty ())
16190 int count
= fi
.typedef_field_list
.size ();
16192 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16193 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16194 = ((struct decl_field
*)
16196 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16197 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16199 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16200 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16203 /* Copy fi.nested_types_list linked list elements content into the
16204 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16205 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16207 int count
= fi
.nested_types_list
.size ();
16209 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16210 TYPE_NESTED_TYPES_ARRAY (type
)
16211 = ((struct decl_field
*)
16212 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16213 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16215 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16216 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16220 quirk_gcc_member_function_pointer (type
, objfile
);
16221 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16222 cu
->rust_unions
.push_back (type
);
16224 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16225 snapshots) has been known to create a die giving a declaration
16226 for a class that has, as a child, a die giving a definition for a
16227 nested class. So we have to process our children even if the
16228 current die is a declaration. Normally, of course, a declaration
16229 won't have any children at all. */
16231 child_die
= die
->child
;
16233 while (child_die
!= NULL
&& child_die
->tag
)
16235 if (child_die
->tag
== DW_TAG_member
16236 || child_die
->tag
== DW_TAG_variable
16237 || child_die
->tag
== DW_TAG_inheritance
16238 || child_die
->tag
== DW_TAG_template_value_param
16239 || child_die
->tag
== DW_TAG_template_type_param
)
16244 process_die (child_die
, cu
);
16246 child_die
= sibling_die (child_die
);
16249 /* Do not consider external references. According to the DWARF standard,
16250 these DIEs are identified by the fact that they have no byte_size
16251 attribute, and a declaration attribute. */
16252 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16253 || !die_is_declaration (die
, cu
))
16255 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16257 if (has_template_parameters
)
16259 struct symtab
*symtab
;
16260 if (sym
!= nullptr)
16261 symtab
= symbol_symtab (sym
);
16262 else if (cu
->line_header
!= nullptr)
16264 /* Any related symtab will do. */
16266 = cu
->line_header
->file_names ()[0].symtab
;
16271 complaint (_("could not find suitable "
16272 "symtab for template parameter"
16273 " - DIE at %s [in module %s]"),
16274 sect_offset_str (die
->sect_off
),
16275 objfile_name (objfile
));
16278 if (symtab
!= nullptr)
16280 /* Make sure that the symtab is set on the new symbols.
16281 Even though they don't appear in this symtab directly,
16282 other parts of gdb assume that symbols do, and this is
16283 reasonably true. */
16284 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16285 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16291 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16292 update TYPE using some information only available in DIE's children. */
16295 update_enumeration_type_from_children (struct die_info
*die
,
16297 struct dwarf2_cu
*cu
)
16299 struct die_info
*child_die
;
16300 int unsigned_enum
= 1;
16304 auto_obstack obstack
;
16306 for (child_die
= die
->child
;
16307 child_die
!= NULL
&& child_die
->tag
;
16308 child_die
= sibling_die (child_die
))
16310 struct attribute
*attr
;
16312 const gdb_byte
*bytes
;
16313 struct dwarf2_locexpr_baton
*baton
;
16316 if (child_die
->tag
!= DW_TAG_enumerator
)
16319 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16323 name
= dwarf2_name (child_die
, cu
);
16325 name
= "<anonymous enumerator>";
16327 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16328 &value
, &bytes
, &baton
);
16334 else if ((mask
& value
) != 0)
16339 /* If we already know that the enum type is neither unsigned, nor
16340 a flag type, no need to look at the rest of the enumerates. */
16341 if (!unsigned_enum
&& !flag_enum
)
16346 TYPE_UNSIGNED (type
) = 1;
16348 TYPE_FLAG_ENUM (type
) = 1;
16351 /* Given a DW_AT_enumeration_type die, set its type. We do not
16352 complete the type's fields yet, or create any symbols. */
16354 static struct type
*
16355 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16357 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16359 struct attribute
*attr
;
16362 /* If the definition of this type lives in .debug_types, read that type.
16363 Don't follow DW_AT_specification though, that will take us back up
16364 the chain and we want to go down. */
16365 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16366 if (attr
!= nullptr)
16368 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16370 /* The type's CU may not be the same as CU.
16371 Ensure TYPE is recorded with CU in die_type_hash. */
16372 return set_die_type (die
, type
, cu
);
16375 type
= alloc_type (objfile
);
16377 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16378 name
= dwarf2_full_name (NULL
, die
, cu
);
16380 TYPE_NAME (type
) = name
;
16382 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16385 struct type
*underlying_type
= die_type (die
, cu
);
16387 TYPE_TARGET_TYPE (type
) = underlying_type
;
16390 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16391 if (attr
!= nullptr)
16393 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16397 TYPE_LENGTH (type
) = 0;
16400 maybe_set_alignment (cu
, die
, type
);
16402 /* The enumeration DIE can be incomplete. In Ada, any type can be
16403 declared as private in the package spec, and then defined only
16404 inside the package body. Such types are known as Taft Amendment
16405 Types. When another package uses such a type, an incomplete DIE
16406 may be generated by the compiler. */
16407 if (die_is_declaration (die
, cu
))
16408 TYPE_STUB (type
) = 1;
16410 /* Finish the creation of this type by using the enum's children.
16411 We must call this even when the underlying type has been provided
16412 so that we can determine if we're looking at a "flag" enum. */
16413 update_enumeration_type_from_children (die
, type
, cu
);
16415 /* If this type has an underlying type that is not a stub, then we
16416 may use its attributes. We always use the "unsigned" attribute
16417 in this situation, because ordinarily we guess whether the type
16418 is unsigned -- but the guess can be wrong and the underlying type
16419 can tell us the reality. However, we defer to a local size
16420 attribute if one exists, because this lets the compiler override
16421 the underlying type if needed. */
16422 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16424 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16425 if (TYPE_LENGTH (type
) == 0)
16426 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16427 if (TYPE_RAW_ALIGN (type
) == 0
16428 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16429 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16432 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16434 return set_die_type (die
, type
, cu
);
16437 /* Given a pointer to a die which begins an enumeration, process all
16438 the dies that define the members of the enumeration, and create the
16439 symbol for the enumeration type.
16441 NOTE: We reverse the order of the element list. */
16444 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16446 struct type
*this_type
;
16448 this_type
= get_die_type (die
, cu
);
16449 if (this_type
== NULL
)
16450 this_type
= read_enumeration_type (die
, cu
);
16452 if (die
->child
!= NULL
)
16454 struct die_info
*child_die
;
16455 struct symbol
*sym
;
16456 struct field
*fields
= NULL
;
16457 int num_fields
= 0;
16460 child_die
= die
->child
;
16461 while (child_die
&& child_die
->tag
)
16463 if (child_die
->tag
!= DW_TAG_enumerator
)
16465 process_die (child_die
, cu
);
16469 name
= dwarf2_name (child_die
, cu
);
16472 sym
= new_symbol (child_die
, this_type
, cu
);
16474 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16476 fields
= (struct field
*)
16478 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16479 * sizeof (struct field
));
16482 FIELD_NAME (fields
[num_fields
]) = sym
->linkage_name ();
16483 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16484 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16485 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16491 child_die
= sibling_die (child_die
);
16496 TYPE_NFIELDS (this_type
) = num_fields
;
16497 TYPE_FIELDS (this_type
) = (struct field
*)
16498 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16499 memcpy (TYPE_FIELDS (this_type
), fields
,
16500 sizeof (struct field
) * num_fields
);
16505 /* If we are reading an enum from a .debug_types unit, and the enum
16506 is a declaration, and the enum is not the signatured type in the
16507 unit, then we do not want to add a symbol for it. Adding a
16508 symbol would in some cases obscure the true definition of the
16509 enum, giving users an incomplete type when the definition is
16510 actually available. Note that we do not want to do this for all
16511 enums which are just declarations, because C++0x allows forward
16512 enum declarations. */
16513 if (cu
->per_cu
->is_debug_types
16514 && die_is_declaration (die
, cu
))
16516 struct signatured_type
*sig_type
;
16518 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16519 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16520 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16524 new_symbol (die
, this_type
, cu
);
16527 /* Extract all information from a DW_TAG_array_type DIE and put it in
16528 the DIE's type field. For now, this only handles one dimensional
16531 static struct type
*
16532 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16534 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16535 struct die_info
*child_die
;
16537 struct type
*element_type
, *range_type
, *index_type
;
16538 struct attribute
*attr
;
16540 struct dynamic_prop
*byte_stride_prop
= NULL
;
16541 unsigned int bit_stride
= 0;
16543 element_type
= die_type (die
, cu
);
16545 /* The die_type call above may have already set the type for this DIE. */
16546 type
= get_die_type (die
, cu
);
16550 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16554 struct type
*prop_type
16555 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16558 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16559 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16563 complaint (_("unable to read array DW_AT_byte_stride "
16564 " - DIE at %s [in module %s]"),
16565 sect_offset_str (die
->sect_off
),
16566 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16567 /* Ignore this attribute. We will likely not be able to print
16568 arrays of this type correctly, but there is little we can do
16569 to help if we cannot read the attribute's value. */
16570 byte_stride_prop
= NULL
;
16574 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16576 bit_stride
= DW_UNSND (attr
);
16578 /* Irix 6.2 native cc creates array types without children for
16579 arrays with unspecified length. */
16580 if (die
->child
== NULL
)
16582 index_type
= objfile_type (objfile
)->builtin_int
;
16583 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16584 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16585 byte_stride_prop
, bit_stride
);
16586 return set_die_type (die
, type
, cu
);
16589 std::vector
<struct type
*> range_types
;
16590 child_die
= die
->child
;
16591 while (child_die
&& child_die
->tag
)
16593 if (child_die
->tag
== DW_TAG_subrange_type
)
16595 struct type
*child_type
= read_type_die (child_die
, cu
);
16597 if (child_type
!= NULL
)
16599 /* The range type was succesfully read. Save it for the
16600 array type creation. */
16601 range_types
.push_back (child_type
);
16604 child_die
= sibling_die (child_die
);
16607 /* Dwarf2 dimensions are output from left to right, create the
16608 necessary array types in backwards order. */
16610 type
= element_type
;
16612 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16616 while (i
< range_types
.size ())
16617 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16618 byte_stride_prop
, bit_stride
);
16622 size_t ndim
= range_types
.size ();
16624 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16625 byte_stride_prop
, bit_stride
);
16628 /* Understand Dwarf2 support for vector types (like they occur on
16629 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16630 array type. This is not part of the Dwarf2/3 standard yet, but a
16631 custom vendor extension. The main difference between a regular
16632 array and the vector variant is that vectors are passed by value
16634 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16635 if (attr
!= nullptr)
16636 make_vector_type (type
);
16638 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16639 implementation may choose to implement triple vectors using this
16641 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16642 if (attr
!= nullptr)
16644 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16645 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16647 complaint (_("DW_AT_byte_size for array type smaller "
16648 "than the total size of elements"));
16651 name
= dwarf2_name (die
, cu
);
16653 TYPE_NAME (type
) = name
;
16655 maybe_set_alignment (cu
, die
, type
);
16657 /* Install the type in the die. */
16658 set_die_type (die
, type
, cu
);
16660 /* set_die_type should be already done. */
16661 set_descriptive_type (type
, die
, cu
);
16666 static enum dwarf_array_dim_ordering
16667 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16669 struct attribute
*attr
;
16671 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16673 if (attr
!= nullptr)
16674 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16676 /* GNU F77 is a special case, as at 08/2004 array type info is the
16677 opposite order to the dwarf2 specification, but data is still
16678 laid out as per normal fortran.
16680 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16681 version checking. */
16683 if (cu
->language
== language_fortran
16684 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16686 return DW_ORD_row_major
;
16689 switch (cu
->language_defn
->la_array_ordering
)
16691 case array_column_major
:
16692 return DW_ORD_col_major
;
16693 case array_row_major
:
16695 return DW_ORD_row_major
;
16699 /* Extract all information from a DW_TAG_set_type DIE and put it in
16700 the DIE's type field. */
16702 static struct type
*
16703 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16705 struct type
*domain_type
, *set_type
;
16706 struct attribute
*attr
;
16708 domain_type
= die_type (die
, cu
);
16710 /* The die_type call above may have already set the type for this DIE. */
16711 set_type
= get_die_type (die
, cu
);
16715 set_type
= create_set_type (NULL
, domain_type
);
16717 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16718 if (attr
!= nullptr)
16719 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16721 maybe_set_alignment (cu
, die
, set_type
);
16723 return set_die_type (die
, set_type
, cu
);
16726 /* A helper for read_common_block that creates a locexpr baton.
16727 SYM is the symbol which we are marking as computed.
16728 COMMON_DIE is the DIE for the common block.
16729 COMMON_LOC is the location expression attribute for the common
16731 MEMBER_LOC is the location expression attribute for the particular
16732 member of the common block that we are processing.
16733 CU is the CU from which the above come. */
16736 mark_common_block_symbol_computed (struct symbol
*sym
,
16737 struct die_info
*common_die
,
16738 struct attribute
*common_loc
,
16739 struct attribute
*member_loc
,
16740 struct dwarf2_cu
*cu
)
16742 struct dwarf2_per_objfile
*dwarf2_per_objfile
16743 = cu
->per_cu
->dwarf2_per_objfile
;
16744 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16745 struct dwarf2_locexpr_baton
*baton
;
16747 unsigned int cu_off
;
16748 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16749 LONGEST offset
= 0;
16751 gdb_assert (common_loc
&& member_loc
);
16752 gdb_assert (attr_form_is_block (common_loc
));
16753 gdb_assert (attr_form_is_block (member_loc
)
16754 || attr_form_is_constant (member_loc
));
16756 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16757 baton
->per_cu
= cu
->per_cu
;
16758 gdb_assert (baton
->per_cu
);
16760 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16762 if (attr_form_is_constant (member_loc
))
16764 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16765 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16768 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16770 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16773 *ptr
++ = DW_OP_call4
;
16774 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16775 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16778 if (attr_form_is_constant (member_loc
))
16780 *ptr
++ = DW_OP_addr
;
16781 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16782 ptr
+= cu
->header
.addr_size
;
16786 /* We have to copy the data here, because DW_OP_call4 will only
16787 use a DW_AT_location attribute. */
16788 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16789 ptr
+= DW_BLOCK (member_loc
)->size
;
16792 *ptr
++ = DW_OP_plus
;
16793 gdb_assert (ptr
- baton
->data
== baton
->size
);
16795 SYMBOL_LOCATION_BATON (sym
) = baton
;
16796 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16799 /* Create appropriate locally-scoped variables for all the
16800 DW_TAG_common_block entries. Also create a struct common_block
16801 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16802 is used to separate the common blocks name namespace from regular
16806 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16808 struct attribute
*attr
;
16810 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16811 if (attr
!= nullptr)
16813 /* Support the .debug_loc offsets. */
16814 if (attr_form_is_block (attr
))
16818 else if (attr_form_is_section_offset (attr
))
16820 dwarf2_complex_location_expr_complaint ();
16825 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16826 "common block member");
16831 if (die
->child
!= NULL
)
16833 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16834 struct die_info
*child_die
;
16835 size_t n_entries
= 0, size
;
16836 struct common_block
*common_block
;
16837 struct symbol
*sym
;
16839 for (child_die
= die
->child
;
16840 child_die
&& child_die
->tag
;
16841 child_die
= sibling_die (child_die
))
16844 size
= (sizeof (struct common_block
)
16845 + (n_entries
- 1) * sizeof (struct symbol
*));
16847 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16849 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16850 common_block
->n_entries
= 0;
16852 for (child_die
= die
->child
;
16853 child_die
&& child_die
->tag
;
16854 child_die
= sibling_die (child_die
))
16856 /* Create the symbol in the DW_TAG_common_block block in the current
16858 sym
= new_symbol (child_die
, NULL
, cu
);
16861 struct attribute
*member_loc
;
16863 common_block
->contents
[common_block
->n_entries
++] = sym
;
16865 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16869 /* GDB has handled this for a long time, but it is
16870 not specified by DWARF. It seems to have been
16871 emitted by gfortran at least as recently as:
16872 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16873 complaint (_("Variable in common block has "
16874 "DW_AT_data_member_location "
16875 "- DIE at %s [in module %s]"),
16876 sect_offset_str (child_die
->sect_off
),
16877 objfile_name (objfile
));
16879 if (attr_form_is_section_offset (member_loc
))
16880 dwarf2_complex_location_expr_complaint ();
16881 else if (attr_form_is_constant (member_loc
)
16882 || attr_form_is_block (member_loc
))
16884 if (attr
!= nullptr)
16885 mark_common_block_symbol_computed (sym
, die
, attr
,
16889 dwarf2_complex_location_expr_complaint ();
16894 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16895 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16899 /* Create a type for a C++ namespace. */
16901 static struct type
*
16902 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16904 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16905 const char *previous_prefix
, *name
;
16909 /* For extensions, reuse the type of the original namespace. */
16910 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16912 struct die_info
*ext_die
;
16913 struct dwarf2_cu
*ext_cu
= cu
;
16915 ext_die
= dwarf2_extension (die
, &ext_cu
);
16916 type
= read_type_die (ext_die
, ext_cu
);
16918 /* EXT_CU may not be the same as CU.
16919 Ensure TYPE is recorded with CU in die_type_hash. */
16920 return set_die_type (die
, type
, cu
);
16923 name
= namespace_name (die
, &is_anonymous
, cu
);
16925 /* Now build the name of the current namespace. */
16927 previous_prefix
= determine_prefix (die
, cu
);
16928 if (previous_prefix
[0] != '\0')
16929 name
= typename_concat (&objfile
->objfile_obstack
,
16930 previous_prefix
, name
, 0, cu
);
16932 /* Create the type. */
16933 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16935 return set_die_type (die
, type
, cu
);
16938 /* Read a namespace scope. */
16941 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16943 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16946 /* Add a symbol associated to this if we haven't seen the namespace
16947 before. Also, add a using directive if it's an anonymous
16950 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16954 type
= read_type_die (die
, cu
);
16955 new_symbol (die
, type
, cu
);
16957 namespace_name (die
, &is_anonymous
, cu
);
16960 const char *previous_prefix
= determine_prefix (die
, cu
);
16962 std::vector
<const char *> excludes
;
16963 add_using_directive (using_directives (cu
),
16964 previous_prefix
, TYPE_NAME (type
), NULL
,
16965 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16969 if (die
->child
!= NULL
)
16971 struct die_info
*child_die
= die
->child
;
16973 while (child_die
&& child_die
->tag
)
16975 process_die (child_die
, cu
);
16976 child_die
= sibling_die (child_die
);
16981 /* Read a Fortran module as type. This DIE can be only a declaration used for
16982 imported module. Still we need that type as local Fortran "use ... only"
16983 declaration imports depend on the created type in determine_prefix. */
16985 static struct type
*
16986 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16988 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16989 const char *module_name
;
16992 module_name
= dwarf2_name (die
, cu
);
16993 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16995 return set_die_type (die
, type
, cu
);
16998 /* Read a Fortran module. */
17001 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17003 struct die_info
*child_die
= die
->child
;
17006 type
= read_type_die (die
, cu
);
17007 new_symbol (die
, type
, cu
);
17009 while (child_die
&& child_die
->tag
)
17011 process_die (child_die
, cu
);
17012 child_die
= sibling_die (child_die
);
17016 /* Return the name of the namespace represented by DIE. Set
17017 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17020 static const char *
17021 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17023 struct die_info
*current_die
;
17024 const char *name
= NULL
;
17026 /* Loop through the extensions until we find a name. */
17028 for (current_die
= die
;
17029 current_die
!= NULL
;
17030 current_die
= dwarf2_extension (die
, &cu
))
17032 /* We don't use dwarf2_name here so that we can detect the absence
17033 of a name -> anonymous namespace. */
17034 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17040 /* Is it an anonymous namespace? */
17042 *is_anonymous
= (name
== NULL
);
17044 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17049 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17050 the user defined type vector. */
17052 static struct type
*
17053 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17055 struct gdbarch
*gdbarch
17056 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17057 struct comp_unit_head
*cu_header
= &cu
->header
;
17059 struct attribute
*attr_byte_size
;
17060 struct attribute
*attr_address_class
;
17061 int byte_size
, addr_class
;
17062 struct type
*target_type
;
17064 target_type
= die_type (die
, cu
);
17066 /* The die_type call above may have already set the type for this DIE. */
17067 type
= get_die_type (die
, cu
);
17071 type
= lookup_pointer_type (target_type
);
17073 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17074 if (attr_byte_size
)
17075 byte_size
= DW_UNSND (attr_byte_size
);
17077 byte_size
= cu_header
->addr_size
;
17079 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17080 if (attr_address_class
)
17081 addr_class
= DW_UNSND (attr_address_class
);
17083 addr_class
= DW_ADDR_none
;
17085 ULONGEST alignment
= get_alignment (cu
, die
);
17087 /* If the pointer size, alignment, or address class is different
17088 than the default, create a type variant marked as such and set
17089 the length accordingly. */
17090 if (TYPE_LENGTH (type
) != byte_size
17091 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17092 && alignment
!= TYPE_RAW_ALIGN (type
))
17093 || addr_class
!= DW_ADDR_none
)
17095 if (gdbarch_address_class_type_flags_p (gdbarch
))
17099 type_flags
= gdbarch_address_class_type_flags
17100 (gdbarch
, byte_size
, addr_class
);
17101 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17103 type
= make_type_with_address_space (type
, type_flags
);
17105 else if (TYPE_LENGTH (type
) != byte_size
)
17107 complaint (_("invalid pointer size %d"), byte_size
);
17109 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17111 complaint (_("Invalid DW_AT_alignment"
17112 " - DIE at %s [in module %s]"),
17113 sect_offset_str (die
->sect_off
),
17114 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17118 /* Should we also complain about unhandled address classes? */
17122 TYPE_LENGTH (type
) = byte_size
;
17123 set_type_align (type
, alignment
);
17124 return set_die_type (die
, type
, cu
);
17127 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17128 the user defined type vector. */
17130 static struct type
*
17131 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17134 struct type
*to_type
;
17135 struct type
*domain
;
17137 to_type
= die_type (die
, cu
);
17138 domain
= die_containing_type (die
, cu
);
17140 /* The calls above may have already set the type for this DIE. */
17141 type
= get_die_type (die
, cu
);
17145 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17146 type
= lookup_methodptr_type (to_type
);
17147 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17149 struct type
*new_type
17150 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17152 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17153 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17154 TYPE_VARARGS (to_type
));
17155 type
= lookup_methodptr_type (new_type
);
17158 type
= lookup_memberptr_type (to_type
, domain
);
17160 return set_die_type (die
, type
, cu
);
17163 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17164 the user defined type vector. */
17166 static struct type
*
17167 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17168 enum type_code refcode
)
17170 struct comp_unit_head
*cu_header
= &cu
->header
;
17171 struct type
*type
, *target_type
;
17172 struct attribute
*attr
;
17174 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17176 target_type
= die_type (die
, cu
);
17178 /* The die_type call above may have already set the type for this DIE. */
17179 type
= get_die_type (die
, cu
);
17183 type
= lookup_reference_type (target_type
, refcode
);
17184 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17185 if (attr
!= nullptr)
17187 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17191 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17193 maybe_set_alignment (cu
, die
, type
);
17194 return set_die_type (die
, type
, cu
);
17197 /* Add the given cv-qualifiers to the element type of the array. GCC
17198 outputs DWARF type qualifiers that apply to an array, not the
17199 element type. But GDB relies on the array element type to carry
17200 the cv-qualifiers. This mimics section 6.7.3 of the C99
17203 static struct type
*
17204 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17205 struct type
*base_type
, int cnst
, int voltl
)
17207 struct type
*el_type
, *inner_array
;
17209 base_type
= copy_type (base_type
);
17210 inner_array
= base_type
;
17212 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17214 TYPE_TARGET_TYPE (inner_array
) =
17215 copy_type (TYPE_TARGET_TYPE (inner_array
));
17216 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17219 el_type
= TYPE_TARGET_TYPE (inner_array
);
17220 cnst
|= TYPE_CONST (el_type
);
17221 voltl
|= TYPE_VOLATILE (el_type
);
17222 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17224 return set_die_type (die
, base_type
, cu
);
17227 static struct type
*
17228 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17230 struct type
*base_type
, *cv_type
;
17232 base_type
= die_type (die
, cu
);
17234 /* The die_type call above may have already set the type for this DIE. */
17235 cv_type
= get_die_type (die
, cu
);
17239 /* In case the const qualifier is applied to an array type, the element type
17240 is so qualified, not the array type (section 6.7.3 of C99). */
17241 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17242 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17244 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17245 return set_die_type (die
, cv_type
, cu
);
17248 static struct type
*
17249 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17251 struct type
*base_type
, *cv_type
;
17253 base_type
= die_type (die
, cu
);
17255 /* The die_type call above may have already set the type for this DIE. */
17256 cv_type
= get_die_type (die
, cu
);
17260 /* In case the volatile qualifier is applied to an array type, the
17261 element type is so qualified, not the array type (section 6.7.3
17263 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17264 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17266 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17267 return set_die_type (die
, cv_type
, cu
);
17270 /* Handle DW_TAG_restrict_type. */
17272 static struct type
*
17273 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17275 struct type
*base_type
, *cv_type
;
17277 base_type
= die_type (die
, cu
);
17279 /* The die_type call above may have already set the type for this DIE. */
17280 cv_type
= get_die_type (die
, cu
);
17284 cv_type
= make_restrict_type (base_type
);
17285 return set_die_type (die
, cv_type
, cu
);
17288 /* Handle DW_TAG_atomic_type. */
17290 static struct type
*
17291 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17293 struct type
*base_type
, *cv_type
;
17295 base_type
= die_type (die
, cu
);
17297 /* The die_type call above may have already set the type for this DIE. */
17298 cv_type
= get_die_type (die
, cu
);
17302 cv_type
= make_atomic_type (base_type
);
17303 return set_die_type (die
, cv_type
, cu
);
17306 /* Extract all information from a DW_TAG_string_type DIE and add to
17307 the user defined type vector. It isn't really a user defined type,
17308 but it behaves like one, with other DIE's using an AT_user_def_type
17309 attribute to reference it. */
17311 static struct type
*
17312 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17314 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17315 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17316 struct type
*type
, *range_type
, *index_type
, *char_type
;
17317 struct attribute
*attr
;
17318 unsigned int length
;
17320 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17321 if (attr
!= nullptr)
17323 length
= DW_UNSND (attr
);
17327 /* Check for the DW_AT_byte_size attribute. */
17328 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17329 if (attr
!= nullptr)
17331 length
= DW_UNSND (attr
);
17339 index_type
= objfile_type (objfile
)->builtin_int
;
17340 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17341 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17342 type
= create_string_type (NULL
, char_type
, range_type
);
17344 return set_die_type (die
, type
, cu
);
17347 /* Assuming that DIE corresponds to a function, returns nonzero
17348 if the function is prototyped. */
17351 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17353 struct attribute
*attr
;
17355 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17356 if (attr
&& (DW_UNSND (attr
) != 0))
17359 /* The DWARF standard implies that the DW_AT_prototyped attribute
17360 is only meaningful for C, but the concept also extends to other
17361 languages that allow unprototyped functions (Eg: Objective C).
17362 For all other languages, assume that functions are always
17364 if (cu
->language
!= language_c
17365 && cu
->language
!= language_objc
17366 && cu
->language
!= language_opencl
)
17369 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17370 prototyped and unprototyped functions; default to prototyped,
17371 since that is more common in modern code (and RealView warns
17372 about unprototyped functions). */
17373 if (producer_is_realview (cu
->producer
))
17379 /* Handle DIES due to C code like:
17383 int (*funcp)(int a, long l);
17387 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17389 static struct type
*
17390 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17392 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17393 struct type
*type
; /* Type that this function returns. */
17394 struct type
*ftype
; /* Function that returns above type. */
17395 struct attribute
*attr
;
17397 type
= die_type (die
, cu
);
17399 /* The die_type call above may have already set the type for this DIE. */
17400 ftype
= get_die_type (die
, cu
);
17404 ftype
= lookup_function_type (type
);
17406 if (prototyped_function_p (die
, cu
))
17407 TYPE_PROTOTYPED (ftype
) = 1;
17409 /* Store the calling convention in the type if it's available in
17410 the subroutine die. Otherwise set the calling convention to
17411 the default value DW_CC_normal. */
17412 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17413 if (attr
!= nullptr)
17414 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17415 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17416 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17418 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17420 /* Record whether the function returns normally to its caller or not
17421 if the DWARF producer set that information. */
17422 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17423 if (attr
&& (DW_UNSND (attr
) != 0))
17424 TYPE_NO_RETURN (ftype
) = 1;
17426 /* We need to add the subroutine type to the die immediately so
17427 we don't infinitely recurse when dealing with parameters
17428 declared as the same subroutine type. */
17429 set_die_type (die
, ftype
, cu
);
17431 if (die
->child
!= NULL
)
17433 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17434 struct die_info
*child_die
;
17435 int nparams
, iparams
;
17437 /* Count the number of parameters.
17438 FIXME: GDB currently ignores vararg functions, but knows about
17439 vararg member functions. */
17441 child_die
= die
->child
;
17442 while (child_die
&& child_die
->tag
)
17444 if (child_die
->tag
== DW_TAG_formal_parameter
)
17446 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17447 TYPE_VARARGS (ftype
) = 1;
17448 child_die
= sibling_die (child_die
);
17451 /* Allocate storage for parameters and fill them in. */
17452 TYPE_NFIELDS (ftype
) = nparams
;
17453 TYPE_FIELDS (ftype
) = (struct field
*)
17454 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17456 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17457 even if we error out during the parameters reading below. */
17458 for (iparams
= 0; iparams
< nparams
; iparams
++)
17459 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17462 child_die
= die
->child
;
17463 while (child_die
&& child_die
->tag
)
17465 if (child_die
->tag
== DW_TAG_formal_parameter
)
17467 struct type
*arg_type
;
17469 /* DWARF version 2 has no clean way to discern C++
17470 static and non-static member functions. G++ helps
17471 GDB by marking the first parameter for non-static
17472 member functions (which is the this pointer) as
17473 artificial. We pass this information to
17474 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17476 DWARF version 3 added DW_AT_object_pointer, which GCC
17477 4.5 does not yet generate. */
17478 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17479 if (attr
!= nullptr)
17480 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17482 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17483 arg_type
= die_type (child_die
, cu
);
17485 /* RealView does not mark THIS as const, which the testsuite
17486 expects. GCC marks THIS as const in method definitions,
17487 but not in the class specifications (GCC PR 43053). */
17488 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17489 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17492 struct dwarf2_cu
*arg_cu
= cu
;
17493 const char *name
= dwarf2_name (child_die
, cu
);
17495 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17496 if (attr
!= nullptr)
17498 /* If the compiler emits this, use it. */
17499 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17502 else if (name
&& strcmp (name
, "this") == 0)
17503 /* Function definitions will have the argument names. */
17505 else if (name
== NULL
&& iparams
== 0)
17506 /* Declarations may not have the names, so like
17507 elsewhere in GDB, assume an artificial first
17508 argument is "this". */
17512 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17516 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17519 child_die
= sibling_die (child_die
);
17526 static struct type
*
17527 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17529 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17530 const char *name
= NULL
;
17531 struct type
*this_type
, *target_type
;
17533 name
= dwarf2_full_name (NULL
, die
, cu
);
17534 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17535 TYPE_TARGET_STUB (this_type
) = 1;
17536 set_die_type (die
, this_type
, cu
);
17537 target_type
= die_type (die
, cu
);
17538 if (target_type
!= this_type
)
17539 TYPE_TARGET_TYPE (this_type
) = target_type
;
17542 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17543 spec and cause infinite loops in GDB. */
17544 complaint (_("Self-referential DW_TAG_typedef "
17545 "- DIE at %s [in module %s]"),
17546 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17547 TYPE_TARGET_TYPE (this_type
) = NULL
;
17552 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17553 (which may be different from NAME) to the architecture back-end to allow
17554 it to guess the correct format if necessary. */
17556 static struct type
*
17557 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17558 const char *name_hint
)
17560 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17561 const struct floatformat
**format
;
17564 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17566 type
= init_float_type (objfile
, bits
, name
, format
);
17568 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17573 /* Allocate an integer type of size BITS and name NAME. */
17575 static struct type
*
17576 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17577 int bits
, int unsigned_p
, const char *name
)
17581 /* Versions of Intel's C Compiler generate an integer type called "void"
17582 instead of using DW_TAG_unspecified_type. This has been seen on
17583 at least versions 14, 17, and 18. */
17584 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17585 && strcmp (name
, "void") == 0)
17586 type
= objfile_type (objfile
)->builtin_void
;
17588 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17593 /* Initialise and return a floating point type of size BITS suitable for
17594 use as a component of a complex number. The NAME_HINT is passed through
17595 when initialising the floating point type and is the name of the complex
17598 As DWARF doesn't currently provide an explicit name for the components
17599 of a complex number, but it can be helpful to have these components
17600 named, we try to select a suitable name based on the size of the
17602 static struct type
*
17603 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17604 struct objfile
*objfile
,
17605 int bits
, const char *name_hint
)
17607 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17608 struct type
*tt
= nullptr;
17610 /* Try to find a suitable floating point builtin type of size BITS.
17611 We're going to use the name of this type as the name for the complex
17612 target type that we are about to create. */
17613 switch (cu
->language
)
17615 case language_fortran
:
17619 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17622 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17624 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17626 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17634 tt
= builtin_type (gdbarch
)->builtin_float
;
17637 tt
= builtin_type (gdbarch
)->builtin_double
;
17639 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17641 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17647 /* If the type we found doesn't match the size we were looking for, then
17648 pretend we didn't find a type at all, the complex target type we
17649 create will then be nameless. */
17650 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17653 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17654 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
);
17657 /* Find a representation of a given base type and install
17658 it in the TYPE field of the die. */
17660 static struct type
*
17661 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17663 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17665 struct attribute
*attr
;
17666 int encoding
= 0, bits
= 0;
17671 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17672 if (attr
!= nullptr)
17673 encoding
= DW_UNSND (attr
);
17674 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17675 if (attr
!= nullptr)
17676 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17677 name
= dwarf2_name (die
, cu
);
17679 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17680 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17682 endianity
= DW_UNSND (attr
);
17684 arch
= get_objfile_arch (objfile
);
17687 case DW_ATE_address
:
17688 /* Turn DW_ATE_address into a void * pointer. */
17689 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17690 type
= init_pointer_type (objfile
, bits
, name
, type
);
17692 case DW_ATE_boolean
:
17693 type
= init_boolean_type (objfile
, bits
, 1, name
);
17695 case DW_ATE_complex_float
:
17696 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
);
17697 type
= init_complex_type (objfile
, name
, type
);
17699 case DW_ATE_decimal_float
:
17700 type
= init_decfloat_type (objfile
, bits
, name
);
17703 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17705 case DW_ATE_signed
:
17706 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17708 case DW_ATE_unsigned
:
17709 if (cu
->language
== language_fortran
17711 && startswith (name
, "character("))
17712 type
= init_character_type (objfile
, bits
, 1, name
);
17714 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17716 case DW_ATE_signed_char
:
17717 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17718 || cu
->language
== language_pascal
17719 || cu
->language
== language_fortran
)
17720 type
= init_character_type (objfile
, bits
, 0, name
);
17722 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17724 case DW_ATE_unsigned_char
:
17725 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17726 || cu
->language
== language_pascal
17727 || cu
->language
== language_fortran
17728 || cu
->language
== language_rust
)
17729 type
= init_character_type (objfile
, bits
, 1, name
);
17731 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17736 type
= builtin_type (arch
)->builtin_char16
;
17737 else if (bits
== 32)
17738 type
= builtin_type (arch
)->builtin_char32
;
17741 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17743 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17745 return set_die_type (die
, type
, cu
);
17750 complaint (_("unsupported DW_AT_encoding: '%s'"),
17751 dwarf_type_encoding_name (encoding
));
17752 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17756 if (name
&& strcmp (name
, "char") == 0)
17757 TYPE_NOSIGN (type
) = 1;
17759 maybe_set_alignment (cu
, die
, type
);
17764 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_LITTLE
)
17765 TYPE_ENDIANITY_NOT_DEFAULT (type
) = 1;
17767 case DW_END_little
:
17768 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
)
17769 TYPE_ENDIANITY_NOT_DEFAULT (type
) = 1;
17773 return set_die_type (die
, type
, cu
);
17776 /* Parse dwarf attribute if it's a block, reference or constant and put the
17777 resulting value of the attribute into struct bound_prop.
17778 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17781 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17782 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17783 struct type
*default_type
)
17785 struct dwarf2_property_baton
*baton
;
17786 struct obstack
*obstack
17787 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17789 gdb_assert (default_type
!= NULL
);
17791 if (attr
== NULL
|| prop
== NULL
)
17794 if (attr_form_is_block (attr
))
17796 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17797 baton
->property_type
= default_type
;
17798 baton
->locexpr
.per_cu
= cu
->per_cu
;
17799 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17800 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17801 baton
->locexpr
.is_reference
= false;
17802 prop
->data
.baton
= baton
;
17803 prop
->kind
= PROP_LOCEXPR
;
17804 gdb_assert (prop
->data
.baton
!= NULL
);
17806 else if (attr_form_is_ref (attr
))
17808 struct dwarf2_cu
*target_cu
= cu
;
17809 struct die_info
*target_die
;
17810 struct attribute
*target_attr
;
17812 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17813 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17814 if (target_attr
== NULL
)
17815 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17817 if (target_attr
== NULL
)
17820 switch (target_attr
->name
)
17822 case DW_AT_location
:
17823 if (attr_form_is_section_offset (target_attr
))
17825 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17826 baton
->property_type
= die_type (target_die
, target_cu
);
17827 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17828 prop
->data
.baton
= baton
;
17829 prop
->kind
= PROP_LOCLIST
;
17830 gdb_assert (prop
->data
.baton
!= NULL
);
17832 else if (attr_form_is_block (target_attr
))
17834 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17835 baton
->property_type
= die_type (target_die
, target_cu
);
17836 baton
->locexpr
.per_cu
= cu
->per_cu
;
17837 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17838 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17839 baton
->locexpr
.is_reference
= true;
17840 prop
->data
.baton
= baton
;
17841 prop
->kind
= PROP_LOCEXPR
;
17842 gdb_assert (prop
->data
.baton
!= NULL
);
17846 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17847 "dynamic property");
17851 case DW_AT_data_member_location
:
17855 if (!handle_data_member_location (target_die
, target_cu
,
17859 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17860 baton
->property_type
= read_type_die (target_die
->parent
,
17862 baton
->offset_info
.offset
= offset
;
17863 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17864 prop
->data
.baton
= baton
;
17865 prop
->kind
= PROP_ADDR_OFFSET
;
17870 else if (attr_form_is_constant (attr
))
17872 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17873 prop
->kind
= PROP_CONST
;
17877 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17878 dwarf2_name (die
, cu
));
17885 /* Find an integer type the same size as the address size given in the
17886 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
17887 is unsigned or not. */
17889 static struct type
*
17890 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
17893 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
17894 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
17895 struct type
*int_type
;
17897 /* Helper macro to examine the various builtin types. */
17898 #define TRY_TYPE(F) \
17899 int_type = (unsigned_p \
17900 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17901 : objfile_type (objfile)->builtin_ ## F); \
17902 if (int_type != NULL && TYPE_LENGTH (int_type) == addr_size) \
17909 TRY_TYPE (long_long
);
17913 gdb_assert_not_reached ("unable to find suitable integer type");
17916 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17917 present (which is valid) then compute the default type based on the
17918 compilation units address size. */
17920 static struct type
*
17921 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17923 struct type
*index_type
= die_type (die
, cu
);
17925 /* Dwarf-2 specifications explicitly allows to create subrange types
17926 without specifying a base type.
17927 In that case, the base type must be set to the type of
17928 the lower bound, upper bound or count, in that order, if any of these
17929 three attributes references an object that has a type.
17930 If no base type is found, the Dwarf-2 specifications say that
17931 a signed integer type of size equal to the size of an address should
17933 For the following C code: `extern char gdb_int [];'
17934 GCC produces an empty range DIE.
17935 FIXME: muller/2010-05-28: Possible references to object for low bound,
17936 high bound or count are not yet handled by this code. */
17937 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17938 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
17943 /* Read the given DW_AT_subrange DIE. */
17945 static struct type
*
17946 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17948 struct type
*base_type
, *orig_base_type
;
17949 struct type
*range_type
;
17950 struct attribute
*attr
;
17951 struct dynamic_prop low
, high
;
17952 int low_default_is_valid
;
17953 int high_bound_is_count
= 0;
17955 ULONGEST negative_mask
;
17957 orig_base_type
= read_subrange_index_type (die
, cu
);
17959 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17960 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17961 creating the range type, but we use the result of check_typedef
17962 when examining properties of the type. */
17963 base_type
= check_typedef (orig_base_type
);
17965 /* The die_type call above may have already set the type for this DIE. */
17966 range_type
= get_die_type (die
, cu
);
17970 low
.kind
= PROP_CONST
;
17971 high
.kind
= PROP_CONST
;
17972 high
.data
.const_val
= 0;
17974 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17975 omitting DW_AT_lower_bound. */
17976 switch (cu
->language
)
17979 case language_cplus
:
17980 low
.data
.const_val
= 0;
17981 low_default_is_valid
= 1;
17983 case language_fortran
:
17984 low
.data
.const_val
= 1;
17985 low_default_is_valid
= 1;
17988 case language_objc
:
17989 case language_rust
:
17990 low
.data
.const_val
= 0;
17991 low_default_is_valid
= (cu
->header
.version
>= 4);
17995 case language_pascal
:
17996 low
.data
.const_val
= 1;
17997 low_default_is_valid
= (cu
->header
.version
>= 4);
18000 low
.data
.const_val
= 0;
18001 low_default_is_valid
= 0;
18005 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18006 if (attr
!= nullptr)
18007 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18008 else if (!low_default_is_valid
)
18009 complaint (_("Missing DW_AT_lower_bound "
18010 "- DIE at %s [in module %s]"),
18011 sect_offset_str (die
->sect_off
),
18012 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18014 struct attribute
*attr_ub
, *attr_count
;
18015 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18016 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18018 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18019 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18021 /* If bounds are constant do the final calculation here. */
18022 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
18023 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
18025 high_bound_is_count
= 1;
18029 if (attr_ub
!= NULL
)
18030 complaint (_("Unresolved DW_AT_upper_bound "
18031 "- DIE at %s [in module %s]"),
18032 sect_offset_str (die
->sect_off
),
18033 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18034 if (attr_count
!= NULL
)
18035 complaint (_("Unresolved DW_AT_count "
18036 "- DIE at %s [in module %s]"),
18037 sect_offset_str (die
->sect_off
),
18038 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18043 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18044 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
18045 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
18047 /* Normally, the DWARF producers are expected to use a signed
18048 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18049 But this is unfortunately not always the case, as witnessed
18050 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18051 is used instead. To work around that ambiguity, we treat
18052 the bounds as signed, and thus sign-extend their values, when
18053 the base type is signed. */
18055 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18056 if (low
.kind
== PROP_CONST
18057 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18058 low
.data
.const_val
|= negative_mask
;
18059 if (high
.kind
== PROP_CONST
18060 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18061 high
.data
.const_val
|= negative_mask
;
18063 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18065 if (high_bound_is_count
)
18066 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18068 /* Ada expects an empty array on no boundary attributes. */
18069 if (attr
== NULL
&& cu
->language
!= language_ada
)
18070 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18072 name
= dwarf2_name (die
, cu
);
18074 TYPE_NAME (range_type
) = name
;
18076 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18077 if (attr
!= nullptr)
18078 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18080 maybe_set_alignment (cu
, die
, range_type
);
18082 set_die_type (die
, range_type
, cu
);
18084 /* set_die_type should be already done. */
18085 set_descriptive_type (range_type
, die
, cu
);
18090 static struct type
*
18091 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18095 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18097 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18099 /* In Ada, an unspecified type is typically used when the description
18100 of the type is deferred to a different unit. When encountering
18101 such a type, we treat it as a stub, and try to resolve it later on,
18103 if (cu
->language
== language_ada
)
18104 TYPE_STUB (type
) = 1;
18106 return set_die_type (die
, type
, cu
);
18109 /* Read a single die and all its descendents. Set the die's sibling
18110 field to NULL; set other fields in the die correctly, and set all
18111 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18112 location of the info_ptr after reading all of those dies. PARENT
18113 is the parent of the die in question. */
18115 static struct die_info
*
18116 read_die_and_children (const struct die_reader_specs
*reader
,
18117 const gdb_byte
*info_ptr
,
18118 const gdb_byte
**new_info_ptr
,
18119 struct die_info
*parent
)
18121 struct die_info
*die
;
18122 const gdb_byte
*cur_ptr
;
18125 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18128 *new_info_ptr
= cur_ptr
;
18131 store_in_ref_table (die
, reader
->cu
);
18134 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18138 *new_info_ptr
= cur_ptr
;
18141 die
->sibling
= NULL
;
18142 die
->parent
= parent
;
18146 /* Read a die, all of its descendents, and all of its siblings; set
18147 all of the fields of all of the dies correctly. Arguments are as
18148 in read_die_and_children. */
18150 static struct die_info
*
18151 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18152 const gdb_byte
*info_ptr
,
18153 const gdb_byte
**new_info_ptr
,
18154 struct die_info
*parent
)
18156 struct die_info
*first_die
, *last_sibling
;
18157 const gdb_byte
*cur_ptr
;
18159 cur_ptr
= info_ptr
;
18160 first_die
= last_sibling
= NULL
;
18164 struct die_info
*die
18165 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18169 *new_info_ptr
= cur_ptr
;
18176 last_sibling
->sibling
= die
;
18178 last_sibling
= die
;
18182 /* Read a die, all of its descendents, and all of its siblings; set
18183 all of the fields of all of the dies correctly. Arguments are as
18184 in read_die_and_children.
18185 This the main entry point for reading a DIE and all its children. */
18187 static struct die_info
*
18188 read_die_and_siblings (const struct die_reader_specs
*reader
,
18189 const gdb_byte
*info_ptr
,
18190 const gdb_byte
**new_info_ptr
,
18191 struct die_info
*parent
)
18193 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18194 new_info_ptr
, parent
);
18196 if (dwarf_die_debug
)
18198 fprintf_unfiltered (gdb_stdlog
,
18199 "Read die from %s@0x%x of %s:\n",
18200 get_section_name (reader
->die_section
),
18201 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18202 bfd_get_filename (reader
->abfd
));
18203 dump_die (die
, dwarf_die_debug
);
18209 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18211 The caller is responsible for filling in the extra attributes
18212 and updating (*DIEP)->num_attrs.
18213 Set DIEP to point to a newly allocated die with its information,
18214 except for its child, sibling, and parent fields.
18215 Set HAS_CHILDREN to tell whether the die has children or not. */
18217 static const gdb_byte
*
18218 read_full_die_1 (const struct die_reader_specs
*reader
,
18219 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18220 int *has_children
, int num_extra_attrs
)
18222 unsigned int abbrev_number
, bytes_read
, i
;
18223 struct abbrev_info
*abbrev
;
18224 struct die_info
*die
;
18225 struct dwarf2_cu
*cu
= reader
->cu
;
18226 bfd
*abfd
= reader
->abfd
;
18228 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18229 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18230 info_ptr
+= bytes_read
;
18231 if (!abbrev_number
)
18238 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18240 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18242 bfd_get_filename (abfd
));
18244 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18245 die
->sect_off
= sect_off
;
18246 die
->tag
= abbrev
->tag
;
18247 die
->abbrev
= abbrev_number
;
18249 /* Make the result usable.
18250 The caller needs to update num_attrs after adding the extra
18252 die
->num_attrs
= abbrev
->num_attrs
;
18254 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18255 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18259 *has_children
= abbrev
->has_children
;
18263 /* Read a die and all its attributes.
18264 Set DIEP to point to a newly allocated die with its information,
18265 except for its child, sibling, and parent fields.
18266 Set HAS_CHILDREN to tell whether the die has children or not. */
18268 static const gdb_byte
*
18269 read_full_die (const struct die_reader_specs
*reader
,
18270 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18273 const gdb_byte
*result
;
18275 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18277 if (dwarf_die_debug
)
18279 fprintf_unfiltered (gdb_stdlog
,
18280 "Read die from %s@0x%x of %s:\n",
18281 get_section_name (reader
->die_section
),
18282 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18283 bfd_get_filename (reader
->abfd
));
18284 dump_die (*diep
, dwarf_die_debug
);
18290 /* Abbreviation tables.
18292 In DWARF version 2, the description of the debugging information is
18293 stored in a separate .debug_abbrev section. Before we read any
18294 dies from a section we read in all abbreviations and install them
18295 in a hash table. */
18297 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18299 struct abbrev_info
*
18300 abbrev_table::alloc_abbrev ()
18302 struct abbrev_info
*abbrev
;
18304 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18305 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18310 /* Add an abbreviation to the table. */
18313 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18314 struct abbrev_info
*abbrev
)
18316 unsigned int hash_number
;
18318 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18319 abbrev
->next
= m_abbrevs
[hash_number
];
18320 m_abbrevs
[hash_number
] = abbrev
;
18323 /* Look up an abbrev in the table.
18324 Returns NULL if the abbrev is not found. */
18326 struct abbrev_info
*
18327 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18329 unsigned int hash_number
;
18330 struct abbrev_info
*abbrev
;
18332 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18333 abbrev
= m_abbrevs
[hash_number
];
18337 if (abbrev
->number
== abbrev_number
)
18339 abbrev
= abbrev
->next
;
18344 /* Read in an abbrev table. */
18346 static abbrev_table_up
18347 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18348 struct dwarf2_section_info
*section
,
18349 sect_offset sect_off
)
18351 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18352 bfd
*abfd
= get_section_bfd_owner (section
);
18353 const gdb_byte
*abbrev_ptr
;
18354 struct abbrev_info
*cur_abbrev
;
18355 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18356 unsigned int abbrev_form
;
18357 struct attr_abbrev
*cur_attrs
;
18358 unsigned int allocated_attrs
;
18360 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18362 dwarf2_read_section (objfile
, section
);
18363 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18364 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18365 abbrev_ptr
+= bytes_read
;
18367 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18368 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18370 /* Loop until we reach an abbrev number of 0. */
18371 while (abbrev_number
)
18373 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18375 /* read in abbrev header */
18376 cur_abbrev
->number
= abbrev_number
;
18378 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18379 abbrev_ptr
+= bytes_read
;
18380 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18383 /* now read in declarations */
18386 LONGEST implicit_const
;
18388 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18389 abbrev_ptr
+= bytes_read
;
18390 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18391 abbrev_ptr
+= bytes_read
;
18392 if (abbrev_form
== DW_FORM_implicit_const
)
18394 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18396 abbrev_ptr
+= bytes_read
;
18400 /* Initialize it due to a false compiler warning. */
18401 implicit_const
= -1;
18404 if (abbrev_name
== 0)
18407 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18409 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18411 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18414 cur_attrs
[cur_abbrev
->num_attrs
].name
18415 = (enum dwarf_attribute
) abbrev_name
;
18416 cur_attrs
[cur_abbrev
->num_attrs
].form
18417 = (enum dwarf_form
) abbrev_form
;
18418 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18419 ++cur_abbrev
->num_attrs
;
18422 cur_abbrev
->attrs
=
18423 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18424 cur_abbrev
->num_attrs
);
18425 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18426 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18428 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18430 /* Get next abbreviation.
18431 Under Irix6 the abbreviations for a compilation unit are not
18432 always properly terminated with an abbrev number of 0.
18433 Exit loop if we encounter an abbreviation which we have
18434 already read (which means we are about to read the abbreviations
18435 for the next compile unit) or if the end of the abbreviation
18436 table is reached. */
18437 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18439 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18440 abbrev_ptr
+= bytes_read
;
18441 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18446 return abbrev_table
;
18449 /* Returns nonzero if TAG represents a type that we might generate a partial
18453 is_type_tag_for_partial (int tag
)
18458 /* Some types that would be reasonable to generate partial symbols for,
18459 that we don't at present. */
18460 case DW_TAG_array_type
:
18461 case DW_TAG_file_type
:
18462 case DW_TAG_ptr_to_member_type
:
18463 case DW_TAG_set_type
:
18464 case DW_TAG_string_type
:
18465 case DW_TAG_subroutine_type
:
18467 case DW_TAG_base_type
:
18468 case DW_TAG_class_type
:
18469 case DW_TAG_interface_type
:
18470 case DW_TAG_enumeration_type
:
18471 case DW_TAG_structure_type
:
18472 case DW_TAG_subrange_type
:
18473 case DW_TAG_typedef
:
18474 case DW_TAG_union_type
:
18481 /* Load all DIEs that are interesting for partial symbols into memory. */
18483 static struct partial_die_info
*
18484 load_partial_dies (const struct die_reader_specs
*reader
,
18485 const gdb_byte
*info_ptr
, int building_psymtab
)
18487 struct dwarf2_cu
*cu
= reader
->cu
;
18488 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18489 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18490 unsigned int bytes_read
;
18491 unsigned int load_all
= 0;
18492 int nesting_level
= 1;
18497 gdb_assert (cu
->per_cu
!= NULL
);
18498 if (cu
->per_cu
->load_all_dies
)
18502 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18506 &cu
->comp_unit_obstack
,
18507 hashtab_obstack_allocate
,
18508 dummy_obstack_deallocate
);
18512 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18514 /* A NULL abbrev means the end of a series of children. */
18515 if (abbrev
== NULL
)
18517 if (--nesting_level
== 0)
18520 info_ptr
+= bytes_read
;
18521 last_die
= parent_die
;
18522 parent_die
= parent_die
->die_parent
;
18526 /* Check for template arguments. We never save these; if
18527 they're seen, we just mark the parent, and go on our way. */
18528 if (parent_die
!= NULL
18529 && cu
->language
== language_cplus
18530 && (abbrev
->tag
== DW_TAG_template_type_param
18531 || abbrev
->tag
== DW_TAG_template_value_param
))
18533 parent_die
->has_template_arguments
= 1;
18537 /* We don't need a partial DIE for the template argument. */
18538 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18543 /* We only recurse into c++ subprograms looking for template arguments.
18544 Skip their other children. */
18546 && cu
->language
== language_cplus
18547 && parent_die
!= NULL
18548 && parent_die
->tag
== DW_TAG_subprogram
)
18550 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18554 /* Check whether this DIE is interesting enough to save. Normally
18555 we would not be interested in members here, but there may be
18556 later variables referencing them via DW_AT_specification (for
18557 static members). */
18559 && !is_type_tag_for_partial (abbrev
->tag
)
18560 && abbrev
->tag
!= DW_TAG_constant
18561 && abbrev
->tag
!= DW_TAG_enumerator
18562 && abbrev
->tag
!= DW_TAG_subprogram
18563 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18564 && abbrev
->tag
!= DW_TAG_lexical_block
18565 && abbrev
->tag
!= DW_TAG_variable
18566 && abbrev
->tag
!= DW_TAG_namespace
18567 && abbrev
->tag
!= DW_TAG_module
18568 && abbrev
->tag
!= DW_TAG_member
18569 && abbrev
->tag
!= DW_TAG_imported_unit
18570 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18572 /* Otherwise we skip to the next sibling, if any. */
18573 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18577 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18580 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18582 /* This two-pass algorithm for processing partial symbols has a
18583 high cost in cache pressure. Thus, handle some simple cases
18584 here which cover the majority of C partial symbols. DIEs
18585 which neither have specification tags in them, nor could have
18586 specification tags elsewhere pointing at them, can simply be
18587 processed and discarded.
18589 This segment is also optional; scan_partial_symbols and
18590 add_partial_symbol will handle these DIEs if we chain
18591 them in normally. When compilers which do not emit large
18592 quantities of duplicate debug information are more common,
18593 this code can probably be removed. */
18595 /* Any complete simple types at the top level (pretty much all
18596 of them, for a language without namespaces), can be processed
18598 if (parent_die
== NULL
18599 && pdi
.has_specification
== 0
18600 && pdi
.is_declaration
== 0
18601 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18602 || pdi
.tag
== DW_TAG_base_type
18603 || pdi
.tag
== DW_TAG_subrange_type
))
18605 if (building_psymtab
&& pdi
.name
!= NULL
)
18606 add_psymbol_to_list (pdi
.name
, false,
18607 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18608 psymbol_placement::STATIC
,
18609 0, cu
->language
, objfile
);
18610 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18614 /* The exception for DW_TAG_typedef with has_children above is
18615 a workaround of GCC PR debug/47510. In the case of this complaint
18616 type_name_or_error will error on such types later.
18618 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18619 it could not find the child DIEs referenced later, this is checked
18620 above. In correct DWARF DW_TAG_typedef should have no children. */
18622 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18623 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18624 "- DIE at %s [in module %s]"),
18625 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18627 /* If we're at the second level, and we're an enumerator, and
18628 our parent has no specification (meaning possibly lives in a
18629 namespace elsewhere), then we can add the partial symbol now
18630 instead of queueing it. */
18631 if (pdi
.tag
== DW_TAG_enumerator
18632 && parent_die
!= NULL
18633 && parent_die
->die_parent
== NULL
18634 && parent_die
->tag
== DW_TAG_enumeration_type
18635 && parent_die
->has_specification
== 0)
18637 if (pdi
.name
== NULL
)
18638 complaint (_("malformed enumerator DIE ignored"));
18639 else if (building_psymtab
)
18640 add_psymbol_to_list (pdi
.name
, false,
18641 VAR_DOMAIN
, LOC_CONST
, -1,
18642 cu
->language
== language_cplus
18643 ? psymbol_placement::GLOBAL
18644 : psymbol_placement::STATIC
,
18645 0, cu
->language
, objfile
);
18647 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18651 struct partial_die_info
*part_die
18652 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18654 /* We'll save this DIE so link it in. */
18655 part_die
->die_parent
= parent_die
;
18656 part_die
->die_sibling
= NULL
;
18657 part_die
->die_child
= NULL
;
18659 if (last_die
&& last_die
== parent_die
)
18660 last_die
->die_child
= part_die
;
18662 last_die
->die_sibling
= part_die
;
18664 last_die
= part_die
;
18666 if (first_die
== NULL
)
18667 first_die
= part_die
;
18669 /* Maybe add the DIE to the hash table. Not all DIEs that we
18670 find interesting need to be in the hash table, because we
18671 also have the parent/sibling/child chains; only those that we
18672 might refer to by offset later during partial symbol reading.
18674 For now this means things that might have be the target of a
18675 DW_AT_specification, DW_AT_abstract_origin, or
18676 DW_AT_extension. DW_AT_extension will refer only to
18677 namespaces; DW_AT_abstract_origin refers to functions (and
18678 many things under the function DIE, but we do not recurse
18679 into function DIEs during partial symbol reading) and
18680 possibly variables as well; DW_AT_specification refers to
18681 declarations. Declarations ought to have the DW_AT_declaration
18682 flag. It happens that GCC forgets to put it in sometimes, but
18683 only for functions, not for types.
18685 Adding more things than necessary to the hash table is harmless
18686 except for the performance cost. Adding too few will result in
18687 wasted time in find_partial_die, when we reread the compilation
18688 unit with load_all_dies set. */
18691 || abbrev
->tag
== DW_TAG_constant
18692 || abbrev
->tag
== DW_TAG_subprogram
18693 || abbrev
->tag
== DW_TAG_variable
18694 || abbrev
->tag
== DW_TAG_namespace
18695 || part_die
->is_declaration
)
18699 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18700 to_underlying (part_die
->sect_off
),
18705 /* For some DIEs we want to follow their children (if any). For C
18706 we have no reason to follow the children of structures; for other
18707 languages we have to, so that we can get at method physnames
18708 to infer fully qualified class names, for DW_AT_specification,
18709 and for C++ template arguments. For C++, we also look one level
18710 inside functions to find template arguments (if the name of the
18711 function does not already contain the template arguments).
18713 For Ada and Fortran, we need to scan the children of subprograms
18714 and lexical blocks as well because these languages allow the
18715 definition of nested entities that could be interesting for the
18716 debugger, such as nested subprograms for instance. */
18717 if (last_die
->has_children
18719 || last_die
->tag
== DW_TAG_namespace
18720 || last_die
->tag
== DW_TAG_module
18721 || last_die
->tag
== DW_TAG_enumeration_type
18722 || (cu
->language
== language_cplus
18723 && last_die
->tag
== DW_TAG_subprogram
18724 && (last_die
->name
== NULL
18725 || strchr (last_die
->name
, '<') == NULL
))
18726 || (cu
->language
!= language_c
18727 && (last_die
->tag
== DW_TAG_class_type
18728 || last_die
->tag
== DW_TAG_interface_type
18729 || last_die
->tag
== DW_TAG_structure_type
18730 || last_die
->tag
== DW_TAG_union_type
))
18731 || ((cu
->language
== language_ada
18732 || cu
->language
== language_fortran
)
18733 && (last_die
->tag
== DW_TAG_subprogram
18734 || last_die
->tag
== DW_TAG_lexical_block
))))
18737 parent_die
= last_die
;
18741 /* Otherwise we skip to the next sibling, if any. */
18742 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18744 /* Back to the top, do it again. */
18748 partial_die_info::partial_die_info (sect_offset sect_off_
,
18749 struct abbrev_info
*abbrev
)
18750 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18754 /* Read a minimal amount of information into the minimal die structure.
18755 INFO_PTR should point just after the initial uleb128 of a DIE. */
18758 partial_die_info::read (const struct die_reader_specs
*reader
,
18759 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18761 struct dwarf2_cu
*cu
= reader
->cu
;
18762 struct dwarf2_per_objfile
*dwarf2_per_objfile
18763 = cu
->per_cu
->dwarf2_per_objfile
;
18765 int has_low_pc_attr
= 0;
18766 int has_high_pc_attr
= 0;
18767 int high_pc_relative
= 0;
18769 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18771 struct attribute attr
;
18773 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18775 /* Store the data if it is of an attribute we want to keep in a
18776 partial symbol table. */
18782 case DW_TAG_compile_unit
:
18783 case DW_TAG_partial_unit
:
18784 case DW_TAG_type_unit
:
18785 /* Compilation units have a DW_AT_name that is a filename, not
18786 a source language identifier. */
18787 case DW_TAG_enumeration_type
:
18788 case DW_TAG_enumerator
:
18789 /* These tags always have simple identifiers already; no need
18790 to canonicalize them. */
18791 name
= DW_STRING (&attr
);
18795 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18798 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18799 &objfile
->per_bfd
->storage_obstack
);
18804 case DW_AT_linkage_name
:
18805 case DW_AT_MIPS_linkage_name
:
18806 /* Note that both forms of linkage name might appear. We
18807 assume they will be the same, and we only store the last
18809 linkage_name
= DW_STRING (&attr
);
18812 has_low_pc_attr
= 1;
18813 lowpc
= attr_value_as_address (&attr
);
18815 case DW_AT_high_pc
:
18816 has_high_pc_attr
= 1;
18817 highpc
= attr_value_as_address (&attr
);
18818 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18819 high_pc_relative
= 1;
18821 case DW_AT_location
:
18822 /* Support the .debug_loc offsets. */
18823 if (attr_form_is_block (&attr
))
18825 d
.locdesc
= DW_BLOCK (&attr
);
18827 else if (attr_form_is_section_offset (&attr
))
18829 dwarf2_complex_location_expr_complaint ();
18833 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18834 "partial symbol information");
18837 case DW_AT_external
:
18838 is_external
= DW_UNSND (&attr
);
18840 case DW_AT_declaration
:
18841 is_declaration
= DW_UNSND (&attr
);
18846 case DW_AT_abstract_origin
:
18847 case DW_AT_specification
:
18848 case DW_AT_extension
:
18849 has_specification
= 1;
18850 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18851 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18852 || cu
->per_cu
->is_dwz
);
18854 case DW_AT_sibling
:
18855 /* Ignore absolute siblings, they might point outside of
18856 the current compile unit. */
18857 if (attr
.form
== DW_FORM_ref_addr
)
18858 complaint (_("ignoring absolute DW_AT_sibling"));
18861 const gdb_byte
*buffer
= reader
->buffer
;
18862 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18863 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18865 if (sibling_ptr
< info_ptr
)
18866 complaint (_("DW_AT_sibling points backwards"));
18867 else if (sibling_ptr
> reader
->buffer_end
)
18868 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18870 sibling
= sibling_ptr
;
18873 case DW_AT_byte_size
:
18876 case DW_AT_const_value
:
18877 has_const_value
= 1;
18879 case DW_AT_calling_convention
:
18880 /* DWARF doesn't provide a way to identify a program's source-level
18881 entry point. DW_AT_calling_convention attributes are only meant
18882 to describe functions' calling conventions.
18884 However, because it's a necessary piece of information in
18885 Fortran, and before DWARF 4 DW_CC_program was the only
18886 piece of debugging information whose definition refers to
18887 a 'main program' at all, several compilers marked Fortran
18888 main programs with DW_CC_program --- even when those
18889 functions use the standard calling conventions.
18891 Although DWARF now specifies a way to provide this
18892 information, we support this practice for backward
18894 if (DW_UNSND (&attr
) == DW_CC_program
18895 && cu
->language
== language_fortran
)
18896 main_subprogram
= 1;
18899 if (DW_UNSND (&attr
) == DW_INL_inlined
18900 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18901 may_be_inlined
= 1;
18905 if (tag
== DW_TAG_imported_unit
)
18907 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18908 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18909 || cu
->per_cu
->is_dwz
);
18913 case DW_AT_main_subprogram
:
18914 main_subprogram
= DW_UNSND (&attr
);
18919 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18920 but that requires a full DIE, so instead we just
18922 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18923 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18924 + (need_ranges_base
18928 /* Value of the DW_AT_ranges attribute is the offset in the
18929 .debug_ranges section. */
18930 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18941 /* For Ada, if both the name and the linkage name appear, we prefer
18942 the latter. This lets "catch exception" work better, regardless
18943 of the order in which the name and linkage name were emitted.
18944 Really, though, this is just a workaround for the fact that gdb
18945 doesn't store both the name and the linkage name. */
18946 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18947 name
= linkage_name
;
18949 if (high_pc_relative
)
18952 if (has_low_pc_attr
&& has_high_pc_attr
)
18954 /* When using the GNU linker, .gnu.linkonce. sections are used to
18955 eliminate duplicate copies of functions and vtables and such.
18956 The linker will arbitrarily choose one and discard the others.
18957 The AT_*_pc values for such functions refer to local labels in
18958 these sections. If the section from that file was discarded, the
18959 labels are not in the output, so the relocs get a value of 0.
18960 If this is a discarded function, mark the pc bounds as invalid,
18961 so that GDB will ignore it. */
18962 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18964 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18965 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18967 complaint (_("DW_AT_low_pc %s is zero "
18968 "for DIE at %s [in module %s]"),
18969 paddress (gdbarch
, lowpc
),
18970 sect_offset_str (sect_off
),
18971 objfile_name (objfile
));
18973 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18974 else if (lowpc
>= highpc
)
18976 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18977 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18979 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18980 "for DIE at %s [in module %s]"),
18981 paddress (gdbarch
, lowpc
),
18982 paddress (gdbarch
, highpc
),
18983 sect_offset_str (sect_off
),
18984 objfile_name (objfile
));
18993 /* Find a cached partial DIE at OFFSET in CU. */
18995 struct partial_die_info
*
18996 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18998 struct partial_die_info
*lookup_die
= NULL
;
18999 struct partial_die_info
part_die (sect_off
);
19001 lookup_die
= ((struct partial_die_info
*)
19002 htab_find_with_hash (partial_dies
, &part_die
,
19003 to_underlying (sect_off
)));
19008 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19009 except in the case of .debug_types DIEs which do not reference
19010 outside their CU (they do however referencing other types via
19011 DW_FORM_ref_sig8). */
19013 static const struct cu_partial_die_info
19014 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19016 struct dwarf2_per_objfile
*dwarf2_per_objfile
19017 = cu
->per_cu
->dwarf2_per_objfile
;
19018 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19019 struct dwarf2_per_cu_data
*per_cu
= NULL
;
19020 struct partial_die_info
*pd
= NULL
;
19022 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19023 && offset_in_cu_p (&cu
->header
, sect_off
))
19025 pd
= cu
->find_partial_die (sect_off
);
19028 /* We missed recording what we needed.
19029 Load all dies and try again. */
19030 per_cu
= cu
->per_cu
;
19034 /* TUs don't reference other CUs/TUs (except via type signatures). */
19035 if (cu
->per_cu
->is_debug_types
)
19037 error (_("Dwarf Error: Type Unit at offset %s contains"
19038 " external reference to offset %s [in module %s].\n"),
19039 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19040 bfd_get_filename (objfile
->obfd
));
19042 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19043 dwarf2_per_objfile
);
19045 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
19046 load_partial_comp_unit (per_cu
);
19048 per_cu
->cu
->last_used
= 0;
19049 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19052 /* If we didn't find it, and not all dies have been loaded,
19053 load them all and try again. */
19055 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
19057 per_cu
->load_all_dies
= 1;
19059 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19060 THIS_CU->cu may already be in use. So we can't just free it and
19061 replace its DIEs with the ones we read in. Instead, we leave those
19062 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19063 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19065 load_partial_comp_unit (per_cu
);
19067 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19071 internal_error (__FILE__
, __LINE__
,
19072 _("could not find partial DIE %s "
19073 "in cache [from module %s]\n"),
19074 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19075 return { per_cu
->cu
, pd
};
19078 /* See if we can figure out if the class lives in a namespace. We do
19079 this by looking for a member function; its demangled name will
19080 contain namespace info, if there is any. */
19083 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19084 struct dwarf2_cu
*cu
)
19086 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19087 what template types look like, because the demangler
19088 frequently doesn't give the same name as the debug info. We
19089 could fix this by only using the demangled name to get the
19090 prefix (but see comment in read_structure_type). */
19092 struct partial_die_info
*real_pdi
;
19093 struct partial_die_info
*child_pdi
;
19095 /* If this DIE (this DIE's specification, if any) has a parent, then
19096 we should not do this. We'll prepend the parent's fully qualified
19097 name when we create the partial symbol. */
19099 real_pdi
= struct_pdi
;
19100 while (real_pdi
->has_specification
)
19102 auto res
= find_partial_die (real_pdi
->spec_offset
,
19103 real_pdi
->spec_is_dwz
, cu
);
19104 real_pdi
= res
.pdi
;
19108 if (real_pdi
->die_parent
!= NULL
)
19111 for (child_pdi
= struct_pdi
->die_child
;
19113 child_pdi
= child_pdi
->die_sibling
)
19115 if (child_pdi
->tag
== DW_TAG_subprogram
19116 && child_pdi
->linkage_name
!= NULL
)
19118 char *actual_class_name
19119 = language_class_name_from_physname (cu
->language_defn
,
19120 child_pdi
->linkage_name
);
19121 if (actual_class_name
!= NULL
)
19123 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19125 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
19126 actual_class_name
);
19127 xfree (actual_class_name
);
19135 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19137 /* Once we've fixed up a die, there's no point in doing so again.
19138 This also avoids a memory leak if we were to call
19139 guess_partial_die_structure_name multiple times. */
19143 /* If we found a reference attribute and the DIE has no name, try
19144 to find a name in the referred to DIE. */
19146 if (name
== NULL
&& has_specification
)
19148 struct partial_die_info
*spec_die
;
19150 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19151 spec_die
= res
.pdi
;
19154 spec_die
->fixup (cu
);
19156 if (spec_die
->name
)
19158 name
= spec_die
->name
;
19160 /* Copy DW_AT_external attribute if it is set. */
19161 if (spec_die
->is_external
)
19162 is_external
= spec_die
->is_external
;
19166 /* Set default names for some unnamed DIEs. */
19168 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19169 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19171 /* If there is no parent die to provide a namespace, and there are
19172 children, see if we can determine the namespace from their linkage
19174 if (cu
->language
== language_cplus
19175 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
19176 && die_parent
== NULL
19178 && (tag
== DW_TAG_class_type
19179 || tag
== DW_TAG_structure_type
19180 || tag
== DW_TAG_union_type
))
19181 guess_partial_die_structure_name (this, cu
);
19183 /* GCC might emit a nameless struct or union that has a linkage
19184 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19186 && (tag
== DW_TAG_class_type
19187 || tag
== DW_TAG_interface_type
19188 || tag
== DW_TAG_structure_type
19189 || tag
== DW_TAG_union_type
)
19190 && linkage_name
!= NULL
)
19194 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
19199 /* Strip any leading namespaces/classes, keep only the base name.
19200 DW_AT_name for named DIEs does not contain the prefixes. */
19201 base
= strrchr (demangled
, ':');
19202 if (base
&& base
> demangled
&& base
[-1] == ':')
19207 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19208 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
19216 /* Read an attribute value described by an attribute form. */
19218 static const gdb_byte
*
19219 read_attribute_value (const struct die_reader_specs
*reader
,
19220 struct attribute
*attr
, unsigned form
,
19221 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19223 struct dwarf2_cu
*cu
= reader
->cu
;
19224 struct dwarf2_per_objfile
*dwarf2_per_objfile
19225 = cu
->per_cu
->dwarf2_per_objfile
;
19226 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19227 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19228 bfd
*abfd
= reader
->abfd
;
19229 struct comp_unit_head
*cu_header
= &cu
->header
;
19230 unsigned int bytes_read
;
19231 struct dwarf_block
*blk
;
19233 attr
->form
= (enum dwarf_form
) form
;
19236 case DW_FORM_ref_addr
:
19237 if (cu
->header
.version
== 2)
19238 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19240 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19241 &cu
->header
, &bytes_read
);
19242 info_ptr
+= bytes_read
;
19244 case DW_FORM_GNU_ref_alt
:
19245 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19246 info_ptr
+= bytes_read
;
19249 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19250 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19251 info_ptr
+= bytes_read
;
19253 case DW_FORM_block2
:
19254 blk
= dwarf_alloc_block (cu
);
19255 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19257 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19258 info_ptr
+= blk
->size
;
19259 DW_BLOCK (attr
) = blk
;
19261 case DW_FORM_block4
:
19262 blk
= dwarf_alloc_block (cu
);
19263 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19265 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19266 info_ptr
+= blk
->size
;
19267 DW_BLOCK (attr
) = blk
;
19269 case DW_FORM_data2
:
19270 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19273 case DW_FORM_data4
:
19274 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19277 case DW_FORM_data8
:
19278 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19281 case DW_FORM_data16
:
19282 blk
= dwarf_alloc_block (cu
);
19284 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19286 DW_BLOCK (attr
) = blk
;
19288 case DW_FORM_sec_offset
:
19289 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19290 info_ptr
+= bytes_read
;
19292 case DW_FORM_string
:
19293 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19294 DW_STRING_IS_CANONICAL (attr
) = 0;
19295 info_ptr
+= bytes_read
;
19298 if (!cu
->per_cu
->is_dwz
)
19300 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19301 abfd
, info_ptr
, cu_header
,
19303 DW_STRING_IS_CANONICAL (attr
) = 0;
19304 info_ptr
+= bytes_read
;
19308 case DW_FORM_line_strp
:
19309 if (!cu
->per_cu
->is_dwz
)
19311 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19313 cu_header
, &bytes_read
);
19314 DW_STRING_IS_CANONICAL (attr
) = 0;
19315 info_ptr
+= bytes_read
;
19319 case DW_FORM_GNU_strp_alt
:
19321 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19322 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19325 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19327 DW_STRING_IS_CANONICAL (attr
) = 0;
19328 info_ptr
+= bytes_read
;
19331 case DW_FORM_exprloc
:
19332 case DW_FORM_block
:
19333 blk
= dwarf_alloc_block (cu
);
19334 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19335 info_ptr
+= bytes_read
;
19336 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19337 info_ptr
+= blk
->size
;
19338 DW_BLOCK (attr
) = blk
;
19340 case DW_FORM_block1
:
19341 blk
= dwarf_alloc_block (cu
);
19342 blk
->size
= read_1_byte (abfd
, info_ptr
);
19344 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19345 info_ptr
+= blk
->size
;
19346 DW_BLOCK (attr
) = blk
;
19348 case DW_FORM_data1
:
19349 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19353 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19356 case DW_FORM_flag_present
:
19357 DW_UNSND (attr
) = 1;
19359 case DW_FORM_sdata
:
19360 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19361 info_ptr
+= bytes_read
;
19363 case DW_FORM_udata
:
19364 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19365 info_ptr
+= bytes_read
;
19368 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19369 + read_1_byte (abfd
, info_ptr
));
19373 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19374 + read_2_bytes (abfd
, info_ptr
));
19378 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19379 + read_4_bytes (abfd
, info_ptr
));
19383 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19384 + read_8_bytes (abfd
, info_ptr
));
19387 case DW_FORM_ref_sig8
:
19388 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19391 case DW_FORM_ref_udata
:
19392 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19393 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19394 info_ptr
+= bytes_read
;
19396 case DW_FORM_indirect
:
19397 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19398 info_ptr
+= bytes_read
;
19399 if (form
== DW_FORM_implicit_const
)
19401 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19402 info_ptr
+= bytes_read
;
19404 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19407 case DW_FORM_implicit_const
:
19408 DW_SND (attr
) = implicit_const
;
19410 case DW_FORM_addrx
:
19411 case DW_FORM_GNU_addr_index
:
19412 if (reader
->dwo_file
== NULL
)
19414 /* For now flag a hard error.
19415 Later we can turn this into a complaint. */
19416 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19417 dwarf_form_name (form
),
19418 bfd_get_filename (abfd
));
19420 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19421 info_ptr
+= bytes_read
;
19424 case DW_FORM_strx1
:
19425 case DW_FORM_strx2
:
19426 case DW_FORM_strx3
:
19427 case DW_FORM_strx4
:
19428 case DW_FORM_GNU_str_index
:
19429 if (reader
->dwo_file
== NULL
)
19431 /* For now flag a hard error.
19432 Later we can turn this into a complaint if warranted. */
19433 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19434 dwarf_form_name (form
),
19435 bfd_get_filename (abfd
));
19438 ULONGEST str_index
;
19439 if (form
== DW_FORM_strx1
)
19441 str_index
= read_1_byte (abfd
, info_ptr
);
19444 else if (form
== DW_FORM_strx2
)
19446 str_index
= read_2_bytes (abfd
, info_ptr
);
19449 else if (form
== DW_FORM_strx3
)
19451 str_index
= read_3_bytes (abfd
, info_ptr
);
19454 else if (form
== DW_FORM_strx4
)
19456 str_index
= read_4_bytes (abfd
, info_ptr
);
19461 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19462 info_ptr
+= bytes_read
;
19464 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19465 DW_STRING_IS_CANONICAL (attr
) = 0;
19469 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19470 dwarf_form_name (form
),
19471 bfd_get_filename (abfd
));
19475 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19476 attr
->form
= DW_FORM_GNU_ref_alt
;
19478 /* We have seen instances where the compiler tried to emit a byte
19479 size attribute of -1 which ended up being encoded as an unsigned
19480 0xffffffff. Although 0xffffffff is technically a valid size value,
19481 an object of this size seems pretty unlikely so we can relatively
19482 safely treat these cases as if the size attribute was invalid and
19483 treat them as zero by default. */
19484 if (attr
->name
== DW_AT_byte_size
19485 && form
== DW_FORM_data4
19486 && DW_UNSND (attr
) >= 0xffffffff)
19489 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19490 hex_string (DW_UNSND (attr
)));
19491 DW_UNSND (attr
) = 0;
19497 /* Read an attribute described by an abbreviated attribute. */
19499 static const gdb_byte
*
19500 read_attribute (const struct die_reader_specs
*reader
,
19501 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19502 const gdb_byte
*info_ptr
)
19504 attr
->name
= abbrev
->name
;
19505 return read_attribute_value (reader
, attr
, abbrev
->form
,
19506 abbrev
->implicit_const
, info_ptr
);
19509 /* Read dwarf information from a buffer. */
19511 static unsigned int
19512 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19514 return bfd_get_8 (abfd
, buf
);
19518 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19520 return bfd_get_signed_8 (abfd
, buf
);
19523 static unsigned int
19524 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19526 return bfd_get_16 (abfd
, buf
);
19530 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19532 return bfd_get_signed_16 (abfd
, buf
);
19535 static unsigned int
19536 read_3_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19538 unsigned int result
= 0;
19539 for (int i
= 0; i
< 3; ++i
)
19541 unsigned char byte
= bfd_get_8 (abfd
, buf
);
19543 result
|= ((unsigned int) byte
<< (i
* 8));
19548 static unsigned int
19549 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19551 return bfd_get_32 (abfd
, buf
);
19555 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19557 return bfd_get_signed_32 (abfd
, buf
);
19561 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19563 return bfd_get_64 (abfd
, buf
);
19567 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19568 unsigned int *bytes_read
)
19570 struct comp_unit_head
*cu_header
= &cu
->header
;
19571 CORE_ADDR retval
= 0;
19573 if (cu_header
->signed_addr_p
)
19575 switch (cu_header
->addr_size
)
19578 retval
= bfd_get_signed_16 (abfd
, buf
);
19581 retval
= bfd_get_signed_32 (abfd
, buf
);
19584 retval
= bfd_get_signed_64 (abfd
, buf
);
19587 internal_error (__FILE__
, __LINE__
,
19588 _("read_address: bad switch, signed [in module %s]"),
19589 bfd_get_filename (abfd
));
19594 switch (cu_header
->addr_size
)
19597 retval
= bfd_get_16 (abfd
, buf
);
19600 retval
= bfd_get_32 (abfd
, buf
);
19603 retval
= bfd_get_64 (abfd
, buf
);
19606 internal_error (__FILE__
, __LINE__
,
19607 _("read_address: bad switch, "
19608 "unsigned [in module %s]"),
19609 bfd_get_filename (abfd
));
19613 *bytes_read
= cu_header
->addr_size
;
19617 /* Read the initial length from a section. The (draft) DWARF 3
19618 specification allows the initial length to take up either 4 bytes
19619 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19620 bytes describe the length and all offsets will be 8 bytes in length
19623 An older, non-standard 64-bit format is also handled by this
19624 function. The older format in question stores the initial length
19625 as an 8-byte quantity without an escape value. Lengths greater
19626 than 2^32 aren't very common which means that the initial 4 bytes
19627 is almost always zero. Since a length value of zero doesn't make
19628 sense for the 32-bit format, this initial zero can be considered to
19629 be an escape value which indicates the presence of the older 64-bit
19630 format. As written, the code can't detect (old format) lengths
19631 greater than 4GB. If it becomes necessary to handle lengths
19632 somewhat larger than 4GB, we could allow other small values (such
19633 as the non-sensical values of 1, 2, and 3) to also be used as
19634 escape values indicating the presence of the old format.
19636 The value returned via bytes_read should be used to increment the
19637 relevant pointer after calling read_initial_length().
19639 [ Note: read_initial_length() and read_offset() are based on the
19640 document entitled "DWARF Debugging Information Format", revision
19641 3, draft 8, dated November 19, 2001. This document was obtained
19644 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19646 This document is only a draft and is subject to change. (So beware.)
19648 Details regarding the older, non-standard 64-bit format were
19649 determined empirically by examining 64-bit ELF files produced by
19650 the SGI toolchain on an IRIX 6.5 machine.
19652 - Kevin, July 16, 2002
19656 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19658 LONGEST length
= bfd_get_32 (abfd
, buf
);
19660 if (length
== 0xffffffff)
19662 length
= bfd_get_64 (abfd
, buf
+ 4);
19665 else if (length
== 0)
19667 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19668 length
= bfd_get_64 (abfd
, buf
);
19679 /* Cover function for read_initial_length.
19680 Returns the length of the object at BUF, and stores the size of the
19681 initial length in *BYTES_READ and stores the size that offsets will be in
19683 If the initial length size is not equivalent to that specified in
19684 CU_HEADER then issue a complaint.
19685 This is useful when reading non-comp-unit headers. */
19688 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19689 const struct comp_unit_head
*cu_header
,
19690 unsigned int *bytes_read
,
19691 unsigned int *offset_size
)
19693 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19695 gdb_assert (cu_header
->initial_length_size
== 4
19696 || cu_header
->initial_length_size
== 8
19697 || cu_header
->initial_length_size
== 12);
19699 if (cu_header
->initial_length_size
!= *bytes_read
)
19700 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19702 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19706 /* Read an offset from the data stream. The size of the offset is
19707 given by cu_header->offset_size. */
19710 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19711 const struct comp_unit_head
*cu_header
,
19712 unsigned int *bytes_read
)
19714 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19716 *bytes_read
= cu_header
->offset_size
;
19720 /* Read an offset from the data stream. */
19723 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19725 LONGEST retval
= 0;
19727 switch (offset_size
)
19730 retval
= bfd_get_32 (abfd
, buf
);
19733 retval
= bfd_get_64 (abfd
, buf
);
19736 internal_error (__FILE__
, __LINE__
,
19737 _("read_offset_1: bad switch [in module %s]"),
19738 bfd_get_filename (abfd
));
19744 static const gdb_byte
*
19745 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19747 /* If the size of a host char is 8 bits, we can return a pointer
19748 to the buffer, otherwise we have to copy the data to a buffer
19749 allocated on the temporary obstack. */
19750 gdb_assert (HOST_CHAR_BIT
== 8);
19754 static const char *
19755 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19756 unsigned int *bytes_read_ptr
)
19758 /* If the size of a host char is 8 bits, we can return a pointer
19759 to the string, otherwise we have to copy the string to a buffer
19760 allocated on the temporary obstack. */
19761 gdb_assert (HOST_CHAR_BIT
== 8);
19764 *bytes_read_ptr
= 1;
19767 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19768 return (const char *) buf
;
19771 /* Return pointer to string at section SECT offset STR_OFFSET with error
19772 reporting strings FORM_NAME and SECT_NAME. */
19774 static const char *
19775 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19776 bfd
*abfd
, LONGEST str_offset
,
19777 struct dwarf2_section_info
*sect
,
19778 const char *form_name
,
19779 const char *sect_name
)
19781 dwarf2_read_section (objfile
, sect
);
19782 if (sect
->buffer
== NULL
)
19783 error (_("%s used without %s section [in module %s]"),
19784 form_name
, sect_name
, bfd_get_filename (abfd
));
19785 if (str_offset
>= sect
->size
)
19786 error (_("%s pointing outside of %s section [in module %s]"),
19787 form_name
, sect_name
, bfd_get_filename (abfd
));
19788 gdb_assert (HOST_CHAR_BIT
== 8);
19789 if (sect
->buffer
[str_offset
] == '\0')
19791 return (const char *) (sect
->buffer
+ str_offset
);
19794 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19796 static const char *
19797 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19798 bfd
*abfd
, LONGEST str_offset
)
19800 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19802 &dwarf2_per_objfile
->str
,
19803 "DW_FORM_strp", ".debug_str");
19806 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19808 static const char *
19809 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19810 bfd
*abfd
, LONGEST str_offset
)
19812 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19814 &dwarf2_per_objfile
->line_str
,
19815 "DW_FORM_line_strp",
19816 ".debug_line_str");
19819 /* Read a string at offset STR_OFFSET in the .debug_str section from
19820 the .dwz file DWZ. Throw an error if the offset is too large. If
19821 the string consists of a single NUL byte, return NULL; otherwise
19822 return a pointer to the string. */
19824 static const char *
19825 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19826 LONGEST str_offset
)
19828 dwarf2_read_section (objfile
, &dwz
->str
);
19830 if (dwz
->str
.buffer
== NULL
)
19831 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19832 "section [in module %s]"),
19833 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19834 if (str_offset
>= dwz
->str
.size
)
19835 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19836 ".debug_str section [in module %s]"),
19837 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19838 gdb_assert (HOST_CHAR_BIT
== 8);
19839 if (dwz
->str
.buffer
[str_offset
] == '\0')
19841 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19844 /* Return pointer to string at .debug_str offset as read from BUF.
19845 BUF is assumed to be in a compilation unit described by CU_HEADER.
19846 Return *BYTES_READ_PTR count of bytes read from BUF. */
19848 static const char *
19849 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19850 const gdb_byte
*buf
,
19851 const struct comp_unit_head
*cu_header
,
19852 unsigned int *bytes_read_ptr
)
19854 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19856 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19859 /* Return pointer to string at .debug_line_str offset as read from BUF.
19860 BUF is assumed to be in a compilation unit described by CU_HEADER.
19861 Return *BYTES_READ_PTR count of bytes read from BUF. */
19863 static const char *
19864 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19865 bfd
*abfd
, const gdb_byte
*buf
,
19866 const struct comp_unit_head
*cu_header
,
19867 unsigned int *bytes_read_ptr
)
19869 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19871 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19876 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19877 unsigned int *bytes_read_ptr
)
19880 unsigned int num_read
;
19882 unsigned char byte
;
19889 byte
= bfd_get_8 (abfd
, buf
);
19892 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19893 if ((byte
& 128) == 0)
19899 *bytes_read_ptr
= num_read
;
19904 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19905 unsigned int *bytes_read_ptr
)
19908 int shift
, num_read
;
19909 unsigned char byte
;
19916 byte
= bfd_get_8 (abfd
, buf
);
19919 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19921 if ((byte
& 128) == 0)
19926 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19927 result
|= -(((ULONGEST
) 1) << shift
);
19928 *bytes_read_ptr
= num_read
;
19932 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19933 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
19934 ADDR_SIZE is the size of addresses from the CU header. */
19937 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19938 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
19940 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19941 bfd
*abfd
= objfile
->obfd
;
19942 const gdb_byte
*info_ptr
;
19944 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
19945 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19946 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19947 objfile_name (objfile
));
19948 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
19949 error (_("DW_FORM_addr_index pointing outside of "
19950 ".debug_addr section [in module %s]"),
19951 objfile_name (objfile
));
19952 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19953 + addr_base
+ addr_index
* addr_size
);
19954 if (addr_size
== 4)
19955 return bfd_get_32 (abfd
, info_ptr
);
19957 return bfd_get_64 (abfd
, info_ptr
);
19960 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19963 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19965 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19966 cu
->addr_base
, cu
->header
.addr_size
);
19969 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19972 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19973 unsigned int *bytes_read
)
19975 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19976 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19978 return read_addr_index (cu
, addr_index
);
19981 /* Data structure to pass results from dwarf2_read_addr_index_reader
19982 back to dwarf2_read_addr_index. */
19984 struct dwarf2_read_addr_index_data
19986 ULONGEST addr_base
;
19990 /* die_reader_func for dwarf2_read_addr_index. */
19993 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
19994 const gdb_byte
*info_ptr
,
19995 struct die_info
*comp_unit_die
,
19999 struct dwarf2_cu
*cu
= reader
->cu
;
20000 struct dwarf2_read_addr_index_data
*aidata
=
20001 (struct dwarf2_read_addr_index_data
*) data
;
20003 aidata
->addr_base
= cu
->addr_base
;
20004 aidata
->addr_size
= cu
->header
.addr_size
;
20007 /* Given an index in .debug_addr, fetch the value.
20008 NOTE: This can be called during dwarf expression evaluation,
20009 long after the debug information has been read, and thus per_cu->cu
20010 may no longer exist. */
20013 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
20014 unsigned int addr_index
)
20016 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
20017 struct dwarf2_cu
*cu
= per_cu
->cu
;
20018 ULONGEST addr_base
;
20021 /* We need addr_base and addr_size.
20022 If we don't have PER_CU->cu, we have to get it.
20023 Nasty, but the alternative is storing the needed info in PER_CU,
20024 which at this point doesn't seem justified: it's not clear how frequently
20025 it would get used and it would increase the size of every PER_CU.
20026 Entry points like dwarf2_per_cu_addr_size do a similar thing
20027 so we're not in uncharted territory here.
20028 Alas we need to be a bit more complicated as addr_base is contained
20031 We don't need to read the entire CU(/TU).
20032 We just need the header and top level die.
20034 IWBN to use the aging mechanism to let us lazily later discard the CU.
20035 For now we skip this optimization. */
20039 addr_base
= cu
->addr_base
;
20040 addr_size
= cu
->header
.addr_size
;
20044 struct dwarf2_read_addr_index_data aidata
;
20046 /* Note: We can't use init_cutu_and_read_dies_simple here,
20047 we need addr_base. */
20048 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0, false,
20049 dwarf2_read_addr_index_reader
, &aidata
);
20050 addr_base
= aidata
.addr_base
;
20051 addr_size
= aidata
.addr_size
;
20054 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20058 /* Given a DW_FORM_GNU_str_index or DW_FORM_strx, fetch the string.
20059 This is only used by the Fission support. */
20061 static const char *
20062 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20064 struct dwarf2_cu
*cu
= reader
->cu
;
20065 struct dwarf2_per_objfile
*dwarf2_per_objfile
20066 = cu
->per_cu
->dwarf2_per_objfile
;
20067 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20068 const char *objf_name
= objfile_name (objfile
);
20069 bfd
*abfd
= objfile
->obfd
;
20070 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
20071 struct dwarf2_section_info
*str_offsets_section
=
20072 &reader
->dwo_file
->sections
.str_offsets
;
20073 const gdb_byte
*info_ptr
;
20074 ULONGEST str_offset
;
20075 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20077 dwarf2_read_section (objfile
, str_section
);
20078 dwarf2_read_section (objfile
, str_offsets_section
);
20079 if (str_section
->buffer
== NULL
)
20080 error (_("%s used without .debug_str.dwo section"
20081 " in CU at offset %s [in module %s]"),
20082 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20083 if (str_offsets_section
->buffer
== NULL
)
20084 error (_("%s used without .debug_str_offsets.dwo section"
20085 " in CU at offset %s [in module %s]"),
20086 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20087 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
20088 error (_("%s pointing outside of .debug_str_offsets.dwo"
20089 " section in CU at offset %s [in module %s]"),
20090 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20091 info_ptr
= (str_offsets_section
->buffer
20092 + str_index
* cu
->header
.offset_size
);
20093 if (cu
->header
.offset_size
== 4)
20094 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20096 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20097 if (str_offset
>= str_section
->size
)
20098 error (_("Offset from %s pointing outside of"
20099 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20100 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20101 return (const char *) (str_section
->buffer
+ str_offset
);
20104 /* Return the length of an LEB128 number in BUF. */
20107 leb128_size (const gdb_byte
*buf
)
20109 const gdb_byte
*begin
= buf
;
20115 if ((byte
& 128) == 0)
20116 return buf
- begin
;
20121 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20130 cu
->language
= language_c
;
20133 case DW_LANG_C_plus_plus
:
20134 case DW_LANG_C_plus_plus_11
:
20135 case DW_LANG_C_plus_plus_14
:
20136 cu
->language
= language_cplus
;
20139 cu
->language
= language_d
;
20141 case DW_LANG_Fortran77
:
20142 case DW_LANG_Fortran90
:
20143 case DW_LANG_Fortran95
:
20144 case DW_LANG_Fortran03
:
20145 case DW_LANG_Fortran08
:
20146 cu
->language
= language_fortran
;
20149 cu
->language
= language_go
;
20151 case DW_LANG_Mips_Assembler
:
20152 cu
->language
= language_asm
;
20154 case DW_LANG_Ada83
:
20155 case DW_LANG_Ada95
:
20156 cu
->language
= language_ada
;
20158 case DW_LANG_Modula2
:
20159 cu
->language
= language_m2
;
20161 case DW_LANG_Pascal83
:
20162 cu
->language
= language_pascal
;
20165 cu
->language
= language_objc
;
20168 case DW_LANG_Rust_old
:
20169 cu
->language
= language_rust
;
20171 case DW_LANG_Cobol74
:
20172 case DW_LANG_Cobol85
:
20174 cu
->language
= language_minimal
;
20177 cu
->language_defn
= language_def (cu
->language
);
20180 /* Return the named attribute or NULL if not there. */
20182 static struct attribute
*
20183 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20188 struct attribute
*spec
= NULL
;
20190 for (i
= 0; i
< die
->num_attrs
; ++i
)
20192 if (die
->attrs
[i
].name
== name
)
20193 return &die
->attrs
[i
];
20194 if (die
->attrs
[i
].name
== DW_AT_specification
20195 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20196 spec
= &die
->attrs
[i
];
20202 die
= follow_die_ref (die
, spec
, &cu
);
20208 /* Return the named attribute or NULL if not there,
20209 but do not follow DW_AT_specification, etc.
20210 This is for use in contexts where we're reading .debug_types dies.
20211 Following DW_AT_specification, DW_AT_abstract_origin will take us
20212 back up the chain, and we want to go down. */
20214 static struct attribute
*
20215 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20219 for (i
= 0; i
< die
->num_attrs
; ++i
)
20220 if (die
->attrs
[i
].name
== name
)
20221 return &die
->attrs
[i
];
20226 /* Return the string associated with a string-typed attribute, or NULL if it
20227 is either not found or is of an incorrect type. */
20229 static const char *
20230 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20232 struct attribute
*attr
;
20233 const char *str
= NULL
;
20235 attr
= dwarf2_attr (die
, name
, cu
);
20239 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20240 || attr
->form
== DW_FORM_string
20241 || attr
->form
== DW_FORM_strx
20242 || attr
->form
== DW_FORM_strx1
20243 || attr
->form
== DW_FORM_strx2
20244 || attr
->form
== DW_FORM_strx3
20245 || attr
->form
== DW_FORM_strx4
20246 || attr
->form
== DW_FORM_GNU_str_index
20247 || attr
->form
== DW_FORM_GNU_strp_alt
)
20248 str
= DW_STRING (attr
);
20250 complaint (_("string type expected for attribute %s for "
20251 "DIE at %s in module %s"),
20252 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20253 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20259 /* Return the dwo name or NULL if not present. If present, it is in either
20260 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20261 static const char *
20262 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20264 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20265 if (dwo_name
== nullptr)
20266 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20270 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20271 and holds a non-zero value. This function should only be used for
20272 DW_FORM_flag or DW_FORM_flag_present attributes. */
20275 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20277 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20279 return (attr
&& DW_UNSND (attr
));
20283 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20285 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20286 which value is non-zero. However, we have to be careful with
20287 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20288 (via dwarf2_flag_true_p) follows this attribute. So we may
20289 end up accidently finding a declaration attribute that belongs
20290 to a different DIE referenced by the specification attribute,
20291 even though the given DIE does not have a declaration attribute. */
20292 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20293 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20296 /* Return the die giving the specification for DIE, if there is
20297 one. *SPEC_CU is the CU containing DIE on input, and the CU
20298 containing the return value on output. If there is no
20299 specification, but there is an abstract origin, that is
20302 static struct die_info
*
20303 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20305 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20308 if (spec_attr
== NULL
)
20309 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20311 if (spec_attr
== NULL
)
20314 return follow_die_ref (die
, spec_attr
, spec_cu
);
20317 /* Stub for free_line_header to match void * callback types. */
20320 free_line_header_voidp (void *arg
)
20322 struct line_header
*lh
= (struct line_header
*) arg
;
20328 line_header::add_include_dir (const char *include_dir
)
20330 if (dwarf_line_debug
>= 2)
20334 new_size
= m_include_dirs
.size ();
20336 new_size
= m_include_dirs
.size () + 1;
20337 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20338 new_size
, include_dir
);
20340 m_include_dirs
.push_back (include_dir
);
20344 line_header::add_file_name (const char *name
,
20346 unsigned int mod_time
,
20347 unsigned int length
)
20349 if (dwarf_line_debug
>= 2)
20353 new_size
= file_names_size ();
20355 new_size
= file_names_size () + 1;
20356 fprintf_unfiltered (gdb_stdlog
, "Adding file %zu: %s\n",
20359 m_file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20362 /* A convenience function to find the proper .debug_line section for a CU. */
20364 static struct dwarf2_section_info
*
20365 get_debug_line_section (struct dwarf2_cu
*cu
)
20367 struct dwarf2_section_info
*section
;
20368 struct dwarf2_per_objfile
*dwarf2_per_objfile
20369 = cu
->per_cu
->dwarf2_per_objfile
;
20371 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20373 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20374 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20375 else if (cu
->per_cu
->is_dwz
)
20377 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20379 section
= &dwz
->line
;
20382 section
= &dwarf2_per_objfile
->line
;
20387 /* Read directory or file name entry format, starting with byte of
20388 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20389 entries count and the entries themselves in the described entry
20393 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20394 bfd
*abfd
, const gdb_byte
**bufp
,
20395 struct line_header
*lh
,
20396 const struct comp_unit_head
*cu_header
,
20397 void (*callback
) (struct line_header
*lh
,
20400 unsigned int mod_time
,
20401 unsigned int length
))
20403 gdb_byte format_count
, formati
;
20404 ULONGEST data_count
, datai
;
20405 const gdb_byte
*buf
= *bufp
;
20406 const gdb_byte
*format_header_data
;
20407 unsigned int bytes_read
;
20409 format_count
= read_1_byte (abfd
, buf
);
20411 format_header_data
= buf
;
20412 for (formati
= 0; formati
< format_count
; formati
++)
20414 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20416 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20420 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20422 for (datai
= 0; datai
< data_count
; datai
++)
20424 const gdb_byte
*format
= format_header_data
;
20425 struct file_entry fe
;
20427 for (formati
= 0; formati
< format_count
; formati
++)
20429 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20430 format
+= bytes_read
;
20432 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20433 format
+= bytes_read
;
20435 gdb::optional
<const char *> string
;
20436 gdb::optional
<unsigned int> uint
;
20440 case DW_FORM_string
:
20441 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20445 case DW_FORM_line_strp
:
20446 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20453 case DW_FORM_data1
:
20454 uint
.emplace (read_1_byte (abfd
, buf
));
20458 case DW_FORM_data2
:
20459 uint
.emplace (read_2_bytes (abfd
, buf
));
20463 case DW_FORM_data4
:
20464 uint
.emplace (read_4_bytes (abfd
, buf
));
20468 case DW_FORM_data8
:
20469 uint
.emplace (read_8_bytes (abfd
, buf
));
20473 case DW_FORM_data16
:
20474 /* This is used for MD5, but file_entry does not record MD5s. */
20478 case DW_FORM_udata
:
20479 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20483 case DW_FORM_block
:
20484 /* It is valid only for DW_LNCT_timestamp which is ignored by
20489 switch (content_type
)
20492 if (string
.has_value ())
20495 case DW_LNCT_directory_index
:
20496 if (uint
.has_value ())
20497 fe
.d_index
= (dir_index
) *uint
;
20499 case DW_LNCT_timestamp
:
20500 if (uint
.has_value ())
20501 fe
.mod_time
= *uint
;
20504 if (uint
.has_value ())
20510 complaint (_("Unknown format content type %s"),
20511 pulongest (content_type
));
20515 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20521 /* Read the statement program header starting at OFFSET in
20522 .debug_line, or .debug_line.dwo. Return a pointer
20523 to a struct line_header, allocated using xmalloc.
20524 Returns NULL if there is a problem reading the header, e.g., if it
20525 has a version we don't understand.
20527 NOTE: the strings in the include directory and file name tables of
20528 the returned object point into the dwarf line section buffer,
20529 and must not be freed. */
20531 static line_header_up
20532 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20534 const gdb_byte
*line_ptr
;
20535 unsigned int bytes_read
, offset_size
;
20537 const char *cur_dir
, *cur_file
;
20538 struct dwarf2_section_info
*section
;
20540 struct dwarf2_per_objfile
*dwarf2_per_objfile
20541 = cu
->per_cu
->dwarf2_per_objfile
;
20543 section
= get_debug_line_section (cu
);
20544 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20545 if (section
->buffer
== NULL
)
20547 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20548 complaint (_("missing .debug_line.dwo section"));
20550 complaint (_("missing .debug_line section"));
20554 /* We can't do this until we know the section is non-empty.
20555 Only then do we know we have such a section. */
20556 abfd
= get_section_bfd_owner (section
);
20558 /* Make sure that at least there's room for the total_length field.
20559 That could be 12 bytes long, but we're just going to fudge that. */
20560 if (to_underlying (sect_off
) + 4 >= section
->size
)
20562 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20566 line_header_up
lh (new line_header ());
20568 lh
->sect_off
= sect_off
;
20569 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20571 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20573 /* Read in the header. */
20575 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20576 &bytes_read
, &offset_size
);
20577 line_ptr
+= bytes_read
;
20579 const gdb_byte
*start_here
= line_ptr
;
20581 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20583 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20586 lh
->statement_program_end
= start_here
+ lh
->total_length
;
20587 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20589 if (lh
->version
> 5)
20591 /* This is a version we don't understand. The format could have
20592 changed in ways we don't handle properly so just punt. */
20593 complaint (_("unsupported version in .debug_line section"));
20596 if (lh
->version
>= 5)
20598 gdb_byte segment_selector_size
;
20600 /* Skip address size. */
20601 read_1_byte (abfd
, line_ptr
);
20604 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20606 if (segment_selector_size
!= 0)
20608 complaint (_("unsupported segment selector size %u "
20609 "in .debug_line section"),
20610 segment_selector_size
);
20614 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20615 line_ptr
+= offset_size
;
20616 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
20617 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20619 if (lh
->version
>= 4)
20621 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20625 lh
->maximum_ops_per_instruction
= 1;
20627 if (lh
->maximum_ops_per_instruction
== 0)
20629 lh
->maximum_ops_per_instruction
= 1;
20630 complaint (_("invalid maximum_ops_per_instruction "
20631 "in `.debug_line' section"));
20634 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20636 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20638 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20640 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20642 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20644 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20645 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20647 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20651 if (lh
->version
>= 5)
20653 /* Read directory table. */
20654 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20656 [] (struct line_header
*header
, const char *name
,
20657 dir_index d_index
, unsigned int mod_time
,
20658 unsigned int length
)
20660 header
->add_include_dir (name
);
20663 /* Read file name table. */
20664 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20666 [] (struct line_header
*header
, const char *name
,
20667 dir_index d_index
, unsigned int mod_time
,
20668 unsigned int length
)
20670 header
->add_file_name (name
, d_index
, mod_time
, length
);
20675 /* Read directory table. */
20676 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20678 line_ptr
+= bytes_read
;
20679 lh
->add_include_dir (cur_dir
);
20681 line_ptr
+= bytes_read
;
20683 /* Read file name table. */
20684 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20686 unsigned int mod_time
, length
;
20689 line_ptr
+= bytes_read
;
20690 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20691 line_ptr
+= bytes_read
;
20692 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20693 line_ptr
+= bytes_read
;
20694 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20695 line_ptr
+= bytes_read
;
20697 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20699 line_ptr
+= bytes_read
;
20702 if (line_ptr
> (section
->buffer
+ section
->size
))
20703 complaint (_("line number info header doesn't "
20704 "fit in `.debug_line' section"));
20709 /* Subroutine of dwarf_decode_lines to simplify it.
20710 Return the file name of the psymtab for the given file_entry.
20711 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20712 If space for the result is malloc'd, *NAME_HOLDER will be set.
20713 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20715 static const char *
20716 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20717 const struct partial_symtab
*pst
,
20718 const char *comp_dir
,
20719 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20721 const char *include_name
= fe
.name
;
20722 const char *include_name_to_compare
= include_name
;
20723 const char *pst_filename
;
20726 const char *dir_name
= fe
.include_dir (lh
);
20728 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20729 if (!IS_ABSOLUTE_PATH (include_name
)
20730 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20732 /* Avoid creating a duplicate psymtab for PST.
20733 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20734 Before we do the comparison, however, we need to account
20735 for DIR_NAME and COMP_DIR.
20736 First prepend dir_name (if non-NULL). If we still don't
20737 have an absolute path prepend comp_dir (if non-NULL).
20738 However, the directory we record in the include-file's
20739 psymtab does not contain COMP_DIR (to match the
20740 corresponding symtab(s)).
20745 bash$ gcc -g ./hello.c
20746 include_name = "hello.c"
20748 DW_AT_comp_dir = comp_dir = "/tmp"
20749 DW_AT_name = "./hello.c"
20753 if (dir_name
!= NULL
)
20755 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20756 include_name
, (char *) NULL
));
20757 include_name
= name_holder
->get ();
20758 include_name_to_compare
= include_name
;
20760 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20762 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20763 include_name
, (char *) NULL
));
20764 include_name_to_compare
= hold_compare
.get ();
20768 pst_filename
= pst
->filename
;
20769 gdb::unique_xmalloc_ptr
<char> copied_name
;
20770 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20772 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20773 pst_filename
, (char *) NULL
));
20774 pst_filename
= copied_name
.get ();
20777 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20781 return include_name
;
20784 /* State machine to track the state of the line number program. */
20786 class lnp_state_machine
20789 /* Initialize a machine state for the start of a line number
20791 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20792 bool record_lines_p
);
20794 file_entry
*current_file ()
20796 /* lh->file_names is 0-based, but the file name numbers in the
20797 statement program are 1-based. */
20798 return m_line_header
->file_name_at (m_file
);
20801 /* Record the line in the state machine. END_SEQUENCE is true if
20802 we're processing the end of a sequence. */
20803 void record_line (bool end_sequence
);
20805 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
20806 nop-out rest of the lines in this sequence. */
20807 void check_line_address (struct dwarf2_cu
*cu
,
20808 const gdb_byte
*line_ptr
,
20809 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20811 void handle_set_discriminator (unsigned int discriminator
)
20813 m_discriminator
= discriminator
;
20814 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20817 /* Handle DW_LNE_set_address. */
20818 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20821 address
+= baseaddr
;
20822 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20825 /* Handle DW_LNS_advance_pc. */
20826 void handle_advance_pc (CORE_ADDR adjust
);
20828 /* Handle a special opcode. */
20829 void handle_special_opcode (unsigned char op_code
);
20831 /* Handle DW_LNS_advance_line. */
20832 void handle_advance_line (int line_delta
)
20834 advance_line (line_delta
);
20837 /* Handle DW_LNS_set_file. */
20838 void handle_set_file (file_name_index file
);
20840 /* Handle DW_LNS_negate_stmt. */
20841 void handle_negate_stmt ()
20843 m_is_stmt
= !m_is_stmt
;
20846 /* Handle DW_LNS_const_add_pc. */
20847 void handle_const_add_pc ();
20849 /* Handle DW_LNS_fixed_advance_pc. */
20850 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20852 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20856 /* Handle DW_LNS_copy. */
20857 void handle_copy ()
20859 record_line (false);
20860 m_discriminator
= 0;
20863 /* Handle DW_LNE_end_sequence. */
20864 void handle_end_sequence ()
20866 m_currently_recording_lines
= true;
20870 /* Advance the line by LINE_DELTA. */
20871 void advance_line (int line_delta
)
20873 m_line
+= line_delta
;
20875 if (line_delta
!= 0)
20876 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20879 struct dwarf2_cu
*m_cu
;
20881 gdbarch
*m_gdbarch
;
20883 /* True if we're recording lines.
20884 Otherwise we're building partial symtabs and are just interested in
20885 finding include files mentioned by the line number program. */
20886 bool m_record_lines_p
;
20888 /* The line number header. */
20889 line_header
*m_line_header
;
20891 /* These are part of the standard DWARF line number state machine,
20892 and initialized according to the DWARF spec. */
20894 unsigned char m_op_index
= 0;
20895 /* The line table index of the current file. */
20896 file_name_index m_file
= 1;
20897 unsigned int m_line
= 1;
20899 /* These are initialized in the constructor. */
20901 CORE_ADDR m_address
;
20903 unsigned int m_discriminator
;
20905 /* Additional bits of state we need to track. */
20907 /* The last file that we called dwarf2_start_subfile for.
20908 This is only used for TLLs. */
20909 unsigned int m_last_file
= 0;
20910 /* The last file a line number was recorded for. */
20911 struct subfile
*m_last_subfile
= NULL
;
20913 /* When true, record the lines we decode. */
20914 bool m_currently_recording_lines
= false;
20916 /* The last line number that was recorded, used to coalesce
20917 consecutive entries for the same line. This can happen, for
20918 example, when discriminators are present. PR 17276. */
20919 unsigned int m_last_line
= 0;
20920 bool m_line_has_non_zero_discriminator
= false;
20924 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20926 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20927 / m_line_header
->maximum_ops_per_instruction
)
20928 * m_line_header
->minimum_instruction_length
);
20929 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20930 m_op_index
= ((m_op_index
+ adjust
)
20931 % m_line_header
->maximum_ops_per_instruction
);
20935 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20937 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20938 CORE_ADDR addr_adj
= (((m_op_index
20939 + (adj_opcode
/ m_line_header
->line_range
))
20940 / m_line_header
->maximum_ops_per_instruction
)
20941 * m_line_header
->minimum_instruction_length
);
20942 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20943 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20944 % m_line_header
->maximum_ops_per_instruction
);
20946 int line_delta
= (m_line_header
->line_base
20947 + (adj_opcode
% m_line_header
->line_range
));
20948 advance_line (line_delta
);
20949 record_line (false);
20950 m_discriminator
= 0;
20954 lnp_state_machine::handle_set_file (file_name_index file
)
20958 const file_entry
*fe
= current_file ();
20960 dwarf2_debug_line_missing_file_complaint ();
20961 else if (m_record_lines_p
)
20963 const char *dir
= fe
->include_dir (m_line_header
);
20965 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20966 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20967 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20972 lnp_state_machine::handle_const_add_pc ()
20975 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20978 = (((m_op_index
+ adjust
)
20979 / m_line_header
->maximum_ops_per_instruction
)
20980 * m_line_header
->minimum_instruction_length
);
20982 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20983 m_op_index
= ((m_op_index
+ adjust
)
20984 % m_line_header
->maximum_ops_per_instruction
);
20987 /* Return non-zero if we should add LINE to the line number table.
20988 LINE is the line to add, LAST_LINE is the last line that was added,
20989 LAST_SUBFILE is the subfile for LAST_LINE.
20990 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20991 had a non-zero discriminator.
20993 We have to be careful in the presence of discriminators.
20994 E.g., for this line:
20996 for (i = 0; i < 100000; i++);
20998 clang can emit four line number entries for that one line,
20999 each with a different discriminator.
21000 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21002 However, we want gdb to coalesce all four entries into one.
21003 Otherwise the user could stepi into the middle of the line and
21004 gdb would get confused about whether the pc really was in the
21005 middle of the line.
21007 Things are further complicated by the fact that two consecutive
21008 line number entries for the same line is a heuristic used by gcc
21009 to denote the end of the prologue. So we can't just discard duplicate
21010 entries, we have to be selective about it. The heuristic we use is
21011 that we only collapse consecutive entries for the same line if at least
21012 one of those entries has a non-zero discriminator. PR 17276.
21014 Note: Addresses in the line number state machine can never go backwards
21015 within one sequence, thus this coalescing is ok. */
21018 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21019 unsigned int line
, unsigned int last_line
,
21020 int line_has_non_zero_discriminator
,
21021 struct subfile
*last_subfile
)
21023 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21025 if (line
!= last_line
)
21027 /* Same line for the same file that we've seen already.
21028 As a last check, for pr 17276, only record the line if the line
21029 has never had a non-zero discriminator. */
21030 if (!line_has_non_zero_discriminator
)
21035 /* Use the CU's builder to record line number LINE beginning at
21036 address ADDRESS in the line table of subfile SUBFILE. */
21039 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21040 unsigned int line
, CORE_ADDR address
,
21041 struct dwarf2_cu
*cu
)
21043 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21045 if (dwarf_line_debug
)
21047 fprintf_unfiltered (gdb_stdlog
,
21048 "Recording line %u, file %s, address %s\n",
21049 line
, lbasename (subfile
->name
),
21050 paddress (gdbarch
, address
));
21054 cu
->get_builder ()->record_line (subfile
, line
, addr
);
21057 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21058 Mark the end of a set of line number records.
21059 The arguments are the same as for dwarf_record_line_1.
21060 If SUBFILE is NULL the request is ignored. */
21063 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21064 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21066 if (subfile
== NULL
)
21069 if (dwarf_line_debug
)
21071 fprintf_unfiltered (gdb_stdlog
,
21072 "Finishing current line, file %s, address %s\n",
21073 lbasename (subfile
->name
),
21074 paddress (gdbarch
, address
));
21077 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
21081 lnp_state_machine::record_line (bool end_sequence
)
21083 if (dwarf_line_debug
)
21085 fprintf_unfiltered (gdb_stdlog
,
21086 "Processing actual line %u: file %u,"
21087 " address %s, is_stmt %u, discrim %u\n",
21089 paddress (m_gdbarch
, m_address
),
21090 m_is_stmt
, m_discriminator
);
21093 file_entry
*fe
= current_file ();
21096 dwarf2_debug_line_missing_file_complaint ();
21097 /* For now we ignore lines not starting on an instruction boundary.
21098 But not when processing end_sequence for compatibility with the
21099 previous version of the code. */
21100 else if (m_op_index
== 0 || end_sequence
)
21102 fe
->included_p
= 1;
21103 if (m_record_lines_p
&& (producer_is_codewarrior (m_cu
) || m_is_stmt
))
21105 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
21108 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21109 m_currently_recording_lines
? m_cu
: nullptr);
21114 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21115 m_line_has_non_zero_discriminator
,
21118 buildsym_compunit
*builder
= m_cu
->get_builder ();
21119 dwarf_record_line_1 (m_gdbarch
,
21120 builder
->get_current_subfile (),
21122 m_currently_recording_lines
? m_cu
: nullptr);
21124 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21125 m_last_line
= m_line
;
21131 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21132 line_header
*lh
, bool record_lines_p
)
21136 m_record_lines_p
= record_lines_p
;
21137 m_line_header
= lh
;
21139 m_currently_recording_lines
= true;
21141 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21142 was a line entry for it so that the backend has a chance to adjust it
21143 and also record it in case it needs it. This is currently used by MIPS
21144 code, cf. `mips_adjust_dwarf2_line'. */
21145 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21146 m_is_stmt
= lh
->default_is_stmt
;
21147 m_discriminator
= 0;
21151 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21152 const gdb_byte
*line_ptr
,
21153 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21155 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
21156 the pc range of the CU. However, we restrict the test to only ADDRESS
21157 values of zero to preserve GDB's previous behaviour which is to handle
21158 the specific case of a function being GC'd by the linker. */
21160 if (address
== 0 && address
< unrelocated_lowpc
)
21162 /* This line table is for a function which has been
21163 GCd by the linker. Ignore it. PR gdb/12528 */
21165 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21166 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21168 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21169 line_offset
, objfile_name (objfile
));
21170 m_currently_recording_lines
= false;
21171 /* Note: m_currently_recording_lines is left as false until we see
21172 DW_LNE_end_sequence. */
21176 /* Subroutine of dwarf_decode_lines to simplify it.
21177 Process the line number information in LH.
21178 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21179 program in order to set included_p for every referenced header. */
21182 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21183 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21185 const gdb_byte
*line_ptr
, *extended_end
;
21186 const gdb_byte
*line_end
;
21187 unsigned int bytes_read
, extended_len
;
21188 unsigned char op_code
, extended_op
;
21189 CORE_ADDR baseaddr
;
21190 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21191 bfd
*abfd
= objfile
->obfd
;
21192 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21193 /* True if we're recording line info (as opposed to building partial
21194 symtabs and just interested in finding include files mentioned by
21195 the line number program). */
21196 bool record_lines_p
= !decode_for_pst_p
;
21198 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21200 line_ptr
= lh
->statement_program_start
;
21201 line_end
= lh
->statement_program_end
;
21203 /* Read the statement sequences until there's nothing left. */
21204 while (line_ptr
< line_end
)
21206 /* The DWARF line number program state machine. Reset the state
21207 machine at the start of each sequence. */
21208 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21209 bool end_sequence
= false;
21211 if (record_lines_p
)
21213 /* Start a subfile for the current file of the state
21215 const file_entry
*fe
= state_machine
.current_file ();
21218 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21221 /* Decode the table. */
21222 while (line_ptr
< line_end
&& !end_sequence
)
21224 op_code
= read_1_byte (abfd
, line_ptr
);
21227 if (op_code
>= lh
->opcode_base
)
21229 /* Special opcode. */
21230 state_machine
.handle_special_opcode (op_code
);
21232 else switch (op_code
)
21234 case DW_LNS_extended_op
:
21235 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21237 line_ptr
+= bytes_read
;
21238 extended_end
= line_ptr
+ extended_len
;
21239 extended_op
= read_1_byte (abfd
, line_ptr
);
21241 switch (extended_op
)
21243 case DW_LNE_end_sequence
:
21244 state_machine
.handle_end_sequence ();
21245 end_sequence
= true;
21247 case DW_LNE_set_address
:
21250 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21251 line_ptr
+= bytes_read
;
21253 state_machine
.check_line_address (cu
, line_ptr
,
21254 lowpc
- baseaddr
, address
);
21255 state_machine
.handle_set_address (baseaddr
, address
);
21258 case DW_LNE_define_file
:
21260 const char *cur_file
;
21261 unsigned int mod_time
, length
;
21264 cur_file
= read_direct_string (abfd
, line_ptr
,
21266 line_ptr
+= bytes_read
;
21267 dindex
= (dir_index
)
21268 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21269 line_ptr
+= bytes_read
;
21271 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21272 line_ptr
+= bytes_read
;
21274 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21275 line_ptr
+= bytes_read
;
21276 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21279 case DW_LNE_set_discriminator
:
21281 /* The discriminator is not interesting to the
21282 debugger; just ignore it. We still need to
21283 check its value though:
21284 if there are consecutive entries for the same
21285 (non-prologue) line we want to coalesce them.
21288 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21289 line_ptr
+= bytes_read
;
21291 state_machine
.handle_set_discriminator (discr
);
21295 complaint (_("mangled .debug_line section"));
21298 /* Make sure that we parsed the extended op correctly. If e.g.
21299 we expected a different address size than the producer used,
21300 we may have read the wrong number of bytes. */
21301 if (line_ptr
!= extended_end
)
21303 complaint (_("mangled .debug_line section"));
21308 state_machine
.handle_copy ();
21310 case DW_LNS_advance_pc
:
21313 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21314 line_ptr
+= bytes_read
;
21316 state_machine
.handle_advance_pc (adjust
);
21319 case DW_LNS_advance_line
:
21322 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21323 line_ptr
+= bytes_read
;
21325 state_machine
.handle_advance_line (line_delta
);
21328 case DW_LNS_set_file
:
21330 file_name_index file
21331 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21333 line_ptr
+= bytes_read
;
21335 state_machine
.handle_set_file (file
);
21338 case DW_LNS_set_column
:
21339 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21340 line_ptr
+= bytes_read
;
21342 case DW_LNS_negate_stmt
:
21343 state_machine
.handle_negate_stmt ();
21345 case DW_LNS_set_basic_block
:
21347 /* Add to the address register of the state machine the
21348 address increment value corresponding to special opcode
21349 255. I.e., this value is scaled by the minimum
21350 instruction length since special opcode 255 would have
21351 scaled the increment. */
21352 case DW_LNS_const_add_pc
:
21353 state_machine
.handle_const_add_pc ();
21355 case DW_LNS_fixed_advance_pc
:
21357 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21360 state_machine
.handle_fixed_advance_pc (addr_adj
);
21365 /* Unknown standard opcode, ignore it. */
21368 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21370 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21371 line_ptr
+= bytes_read
;
21378 dwarf2_debug_line_missing_end_sequence_complaint ();
21380 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21381 in which case we still finish recording the last line). */
21382 state_machine
.record_line (true);
21386 /* Decode the Line Number Program (LNP) for the given line_header
21387 structure and CU. The actual information extracted and the type
21388 of structures created from the LNP depends on the value of PST.
21390 1. If PST is NULL, then this procedure uses the data from the program
21391 to create all necessary symbol tables, and their linetables.
21393 2. If PST is not NULL, this procedure reads the program to determine
21394 the list of files included by the unit represented by PST, and
21395 builds all the associated partial symbol tables.
21397 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21398 It is used for relative paths in the line table.
21399 NOTE: When processing partial symtabs (pst != NULL),
21400 comp_dir == pst->dirname.
21402 NOTE: It is important that psymtabs have the same file name (via strcmp)
21403 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21404 symtab we don't use it in the name of the psymtabs we create.
21405 E.g. expand_line_sal requires this when finding psymtabs to expand.
21406 A good testcase for this is mb-inline.exp.
21408 LOWPC is the lowest address in CU (or 0 if not known).
21410 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21411 for its PC<->lines mapping information. Otherwise only the filename
21412 table is read in. */
21415 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21416 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21417 CORE_ADDR lowpc
, int decode_mapping
)
21419 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21420 const int decode_for_pst_p
= (pst
!= NULL
);
21422 if (decode_mapping
)
21423 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21425 if (decode_for_pst_p
)
21427 /* Now that we're done scanning the Line Header Program, we can
21428 create the psymtab of each included file. */
21429 for (auto &file_entry
: lh
->file_names ())
21430 if (file_entry
.included_p
== 1)
21432 gdb::unique_xmalloc_ptr
<char> name_holder
;
21433 const char *include_name
=
21434 psymtab_include_file_name (lh
, file_entry
, pst
,
21435 comp_dir
, &name_holder
);
21436 if (include_name
!= NULL
)
21437 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21442 /* Make sure a symtab is created for every file, even files
21443 which contain only variables (i.e. no code with associated
21445 buildsym_compunit
*builder
= cu
->get_builder ();
21446 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21448 for (auto &fe
: lh
->file_names ())
21450 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21451 if (builder
->get_current_subfile ()->symtab
== NULL
)
21453 builder
->get_current_subfile ()->symtab
21454 = allocate_symtab (cust
,
21455 builder
->get_current_subfile ()->name
);
21457 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21462 /* Start a subfile for DWARF. FILENAME is the name of the file and
21463 DIRNAME the name of the source directory which contains FILENAME
21464 or NULL if not known.
21465 This routine tries to keep line numbers from identical absolute and
21466 relative file names in a common subfile.
21468 Using the `list' example from the GDB testsuite, which resides in
21469 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21470 of /srcdir/list0.c yields the following debugging information for list0.c:
21472 DW_AT_name: /srcdir/list0.c
21473 DW_AT_comp_dir: /compdir
21474 files.files[0].name: list0.h
21475 files.files[0].dir: /srcdir
21476 files.files[1].name: list0.c
21477 files.files[1].dir: /srcdir
21479 The line number information for list0.c has to end up in a single
21480 subfile, so that `break /srcdir/list0.c:1' works as expected.
21481 start_subfile will ensure that this happens provided that we pass the
21482 concatenation of files.files[1].dir and files.files[1].name as the
21486 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21487 const char *dirname
)
21491 /* In order not to lose the line information directory,
21492 we concatenate it to the filename when it makes sense.
21493 Note that the Dwarf3 standard says (speaking of filenames in line
21494 information): ``The directory index is ignored for file names
21495 that represent full path names''. Thus ignoring dirname in the
21496 `else' branch below isn't an issue. */
21498 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21500 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21504 cu
->get_builder ()->start_subfile (filename
);
21510 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21511 buildsym_compunit constructor. */
21513 struct compunit_symtab
*
21514 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21517 gdb_assert (m_builder
== nullptr);
21519 m_builder
.reset (new struct buildsym_compunit
21520 (per_cu
->dwarf2_per_objfile
->objfile
,
21521 name
, comp_dir
, language
, low_pc
));
21523 list_in_scope
= get_builder ()->get_file_symbols ();
21525 get_builder ()->record_debugformat ("DWARF 2");
21526 get_builder ()->record_producer (producer
);
21528 processing_has_namespace_info
= false;
21530 return get_builder ()->get_compunit_symtab ();
21534 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21535 struct dwarf2_cu
*cu
)
21537 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21538 struct comp_unit_head
*cu_header
= &cu
->header
;
21540 /* NOTE drow/2003-01-30: There used to be a comment and some special
21541 code here to turn a symbol with DW_AT_external and a
21542 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21543 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21544 with some versions of binutils) where shared libraries could have
21545 relocations against symbols in their debug information - the
21546 minimal symbol would have the right address, but the debug info
21547 would not. It's no longer necessary, because we will explicitly
21548 apply relocations when we read in the debug information now. */
21550 /* A DW_AT_location attribute with no contents indicates that a
21551 variable has been optimized away. */
21552 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21554 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21558 /* Handle one degenerate form of location expression specially, to
21559 preserve GDB's previous behavior when section offsets are
21560 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21561 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21563 if (attr_form_is_block (attr
)
21564 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21565 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21566 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21567 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21568 && (DW_BLOCK (attr
)->size
21569 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21571 unsigned int dummy
;
21573 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21574 SET_SYMBOL_VALUE_ADDRESS (sym
,
21575 read_address (objfile
->obfd
,
21576 DW_BLOCK (attr
)->data
+ 1,
21579 SET_SYMBOL_VALUE_ADDRESS
21580 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21582 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21583 fixup_symbol_section (sym
, objfile
);
21584 SET_SYMBOL_VALUE_ADDRESS (sym
,
21585 SYMBOL_VALUE_ADDRESS (sym
)
21586 + ANOFFSET (objfile
->section_offsets
,
21587 SYMBOL_SECTION (sym
)));
21591 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21592 expression evaluator, and use LOC_COMPUTED only when necessary
21593 (i.e. when the value of a register or memory location is
21594 referenced, or a thread-local block, etc.). Then again, it might
21595 not be worthwhile. I'm assuming that it isn't unless performance
21596 or memory numbers show me otherwise. */
21598 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21600 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21601 cu
->has_loclist
= true;
21604 /* Given a pointer to a DWARF information entry, figure out if we need
21605 to make a symbol table entry for it, and if so, create a new entry
21606 and return a pointer to it.
21607 If TYPE is NULL, determine symbol type from the die, otherwise
21608 used the passed type.
21609 If SPACE is not NULL, use it to hold the new symbol. If it is
21610 NULL, allocate a new symbol on the objfile's obstack. */
21612 static struct symbol
*
21613 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21614 struct symbol
*space
)
21616 struct dwarf2_per_objfile
*dwarf2_per_objfile
21617 = cu
->per_cu
->dwarf2_per_objfile
;
21618 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21619 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21620 struct symbol
*sym
= NULL
;
21622 struct attribute
*attr
= NULL
;
21623 struct attribute
*attr2
= NULL
;
21624 CORE_ADDR baseaddr
;
21625 struct pending
**list_to_add
= NULL
;
21627 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21629 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21631 name
= dwarf2_name (die
, cu
);
21634 const char *linkagename
;
21635 int suppress_add
= 0;
21640 sym
= allocate_symbol (objfile
);
21641 OBJSTAT (objfile
, n_syms
++);
21643 /* Cache this symbol's name and the name's demangled form (if any). */
21644 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21645 linkagename
= dwarf2_physname (name
, die
, cu
);
21646 SYMBOL_SET_NAMES (sym
, linkagename
, false, objfile
);
21648 /* Fortran does not have mangling standard and the mangling does differ
21649 between gfortran, iFort etc. */
21650 if (cu
->language
== language_fortran
21651 && symbol_get_demangled_name (sym
) == NULL
)
21652 symbol_set_demangled_name (sym
,
21653 dwarf2_full_name (name
, die
, cu
),
21656 /* Default assumptions.
21657 Use the passed type or decode it from the die. */
21658 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21659 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21661 SYMBOL_TYPE (sym
) = type
;
21663 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21664 attr
= dwarf2_attr (die
,
21665 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21667 if (attr
!= nullptr)
21669 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21672 attr
= dwarf2_attr (die
,
21673 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21675 if (attr
!= nullptr)
21677 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21678 struct file_entry
*fe
;
21680 if (cu
->line_header
!= NULL
)
21681 fe
= cu
->line_header
->file_name_at (file_index
);
21686 complaint (_("file index out of range"));
21688 symbol_set_symtab (sym
, fe
->symtab
);
21694 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21695 if (attr
!= nullptr)
21699 addr
= attr_value_as_address (attr
);
21700 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21701 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21703 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21704 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21705 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21706 add_symbol_to_list (sym
, cu
->list_in_scope
);
21708 case DW_TAG_subprogram
:
21709 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21711 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21712 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21713 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21714 || cu
->language
== language_ada
21715 || cu
->language
== language_fortran
)
21717 /* Subprograms marked external are stored as a global symbol.
21718 Ada and Fortran subprograms, whether marked external or
21719 not, are always stored as a global symbol, because we want
21720 to be able to access them globally. For instance, we want
21721 to be able to break on a nested subprogram without having
21722 to specify the context. */
21723 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21727 list_to_add
= cu
->list_in_scope
;
21730 case DW_TAG_inlined_subroutine
:
21731 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21733 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21734 SYMBOL_INLINED (sym
) = 1;
21735 list_to_add
= cu
->list_in_scope
;
21737 case DW_TAG_template_value_param
:
21739 /* Fall through. */
21740 case DW_TAG_constant
:
21741 case DW_TAG_variable
:
21742 case DW_TAG_member
:
21743 /* Compilation with minimal debug info may result in
21744 variables with missing type entries. Change the
21745 misleading `void' type to something sensible. */
21746 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21747 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21749 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21750 /* In the case of DW_TAG_member, we should only be called for
21751 static const members. */
21752 if (die
->tag
== DW_TAG_member
)
21754 /* dwarf2_add_field uses die_is_declaration,
21755 so we do the same. */
21756 gdb_assert (die_is_declaration (die
, cu
));
21759 if (attr
!= nullptr)
21761 dwarf2_const_value (attr
, sym
, cu
);
21762 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21765 if (attr2
&& (DW_UNSND (attr2
) != 0))
21766 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21768 list_to_add
= cu
->list_in_scope
;
21772 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21773 if (attr
!= nullptr)
21775 var_decode_location (attr
, sym
, cu
);
21776 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21778 /* Fortran explicitly imports any global symbols to the local
21779 scope by DW_TAG_common_block. */
21780 if (cu
->language
== language_fortran
&& die
->parent
21781 && die
->parent
->tag
== DW_TAG_common_block
)
21784 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21785 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21786 && !dwarf2_per_objfile
->has_section_at_zero
)
21788 /* When a static variable is eliminated by the linker,
21789 the corresponding debug information is not stripped
21790 out, but the variable address is set to null;
21791 do not add such variables into symbol table. */
21793 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21795 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21796 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21797 && dwarf2_per_objfile
->can_copy
)
21799 /* A global static variable might be subject to
21800 copy relocation. We first check for a local
21801 minsym, though, because maybe the symbol was
21802 marked hidden, in which case this would not
21804 bound_minimal_symbol found
21805 = (lookup_minimal_symbol_linkage
21806 (sym
->linkage_name (), objfile
));
21807 if (found
.minsym
!= nullptr)
21808 sym
->maybe_copied
= 1;
21811 /* A variable with DW_AT_external is never static,
21812 but it may be block-scoped. */
21814 = ((cu
->list_in_scope
21815 == cu
->get_builder ()->get_file_symbols ())
21816 ? cu
->get_builder ()->get_global_symbols ()
21817 : cu
->list_in_scope
);
21820 list_to_add
= cu
->list_in_scope
;
21824 /* We do not know the address of this symbol.
21825 If it is an external symbol and we have type information
21826 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21827 The address of the variable will then be determined from
21828 the minimal symbol table whenever the variable is
21830 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21832 /* Fortran explicitly imports any global symbols to the local
21833 scope by DW_TAG_common_block. */
21834 if (cu
->language
== language_fortran
&& die
->parent
21835 && die
->parent
->tag
== DW_TAG_common_block
)
21837 /* SYMBOL_CLASS doesn't matter here because
21838 read_common_block is going to reset it. */
21840 list_to_add
= cu
->list_in_scope
;
21842 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21843 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21845 /* A variable with DW_AT_external is never static, but it
21846 may be block-scoped. */
21848 = ((cu
->list_in_scope
21849 == cu
->get_builder ()->get_file_symbols ())
21850 ? cu
->get_builder ()->get_global_symbols ()
21851 : cu
->list_in_scope
);
21853 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21855 else if (!die_is_declaration (die
, cu
))
21857 /* Use the default LOC_OPTIMIZED_OUT class. */
21858 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21860 list_to_add
= cu
->list_in_scope
;
21864 case DW_TAG_formal_parameter
:
21866 /* If we are inside a function, mark this as an argument. If
21867 not, we might be looking at an argument to an inlined function
21868 when we do not have enough information to show inlined frames;
21869 pretend it's a local variable in that case so that the user can
21871 struct context_stack
*curr
21872 = cu
->get_builder ()->get_current_context_stack ();
21873 if (curr
!= nullptr && curr
->name
!= nullptr)
21874 SYMBOL_IS_ARGUMENT (sym
) = 1;
21875 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21876 if (attr
!= nullptr)
21878 var_decode_location (attr
, sym
, cu
);
21880 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21881 if (attr
!= nullptr)
21883 dwarf2_const_value (attr
, sym
, cu
);
21886 list_to_add
= cu
->list_in_scope
;
21889 case DW_TAG_unspecified_parameters
:
21890 /* From varargs functions; gdb doesn't seem to have any
21891 interest in this information, so just ignore it for now.
21894 case DW_TAG_template_type_param
:
21896 /* Fall through. */
21897 case DW_TAG_class_type
:
21898 case DW_TAG_interface_type
:
21899 case DW_TAG_structure_type
:
21900 case DW_TAG_union_type
:
21901 case DW_TAG_set_type
:
21902 case DW_TAG_enumeration_type
:
21903 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21904 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21907 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21908 really ever be static objects: otherwise, if you try
21909 to, say, break of a class's method and you're in a file
21910 which doesn't mention that class, it won't work unless
21911 the check for all static symbols in lookup_symbol_aux
21912 saves you. See the OtherFileClass tests in
21913 gdb.c++/namespace.exp. */
21917 buildsym_compunit
*builder
= cu
->get_builder ();
21919 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21920 && cu
->language
== language_cplus
21921 ? builder
->get_global_symbols ()
21922 : cu
->list_in_scope
);
21924 /* The semantics of C++ state that "struct foo {
21925 ... }" also defines a typedef for "foo". */
21926 if (cu
->language
== language_cplus
21927 || cu
->language
== language_ada
21928 || cu
->language
== language_d
21929 || cu
->language
== language_rust
)
21931 /* The symbol's name is already allocated along
21932 with this objfile, so we don't need to
21933 duplicate it for the type. */
21934 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21935 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
21940 case DW_TAG_typedef
:
21941 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21942 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21943 list_to_add
= cu
->list_in_scope
;
21945 case DW_TAG_base_type
:
21946 case DW_TAG_subrange_type
:
21947 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21948 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21949 list_to_add
= cu
->list_in_scope
;
21951 case DW_TAG_enumerator
:
21952 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21953 if (attr
!= nullptr)
21955 dwarf2_const_value (attr
, sym
, cu
);
21958 /* NOTE: carlton/2003-11-10: See comment above in the
21959 DW_TAG_class_type, etc. block. */
21962 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21963 && cu
->language
== language_cplus
21964 ? cu
->get_builder ()->get_global_symbols ()
21965 : cu
->list_in_scope
);
21968 case DW_TAG_imported_declaration
:
21969 case DW_TAG_namespace
:
21970 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21971 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21973 case DW_TAG_module
:
21974 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21975 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21976 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21978 case DW_TAG_common_block
:
21979 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21980 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21981 add_symbol_to_list (sym
, cu
->list_in_scope
);
21984 /* Not a tag we recognize. Hopefully we aren't processing
21985 trash data, but since we must specifically ignore things
21986 we don't recognize, there is nothing else we should do at
21988 complaint (_("unsupported tag: '%s'"),
21989 dwarf_tag_name (die
->tag
));
21995 sym
->hash_next
= objfile
->template_symbols
;
21996 objfile
->template_symbols
= sym
;
21997 list_to_add
= NULL
;
22000 if (list_to_add
!= NULL
)
22001 add_symbol_to_list (sym
, list_to_add
);
22003 /* For the benefit of old versions of GCC, check for anonymous
22004 namespaces based on the demangled name. */
22005 if (!cu
->processing_has_namespace_info
22006 && cu
->language
== language_cplus
)
22007 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22012 /* Given an attr with a DW_FORM_dataN value in host byte order,
22013 zero-extend it as appropriate for the symbol's type. The DWARF
22014 standard (v4) is not entirely clear about the meaning of using
22015 DW_FORM_dataN for a constant with a signed type, where the type is
22016 wider than the data. The conclusion of a discussion on the DWARF
22017 list was that this is unspecified. We choose to always zero-extend
22018 because that is the interpretation long in use by GCC. */
22021 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22022 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22024 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22025 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22026 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22027 LONGEST l
= DW_UNSND (attr
);
22029 if (bits
< sizeof (*value
) * 8)
22031 l
&= ((LONGEST
) 1 << bits
) - 1;
22034 else if (bits
== sizeof (*value
) * 8)
22038 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22039 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22046 /* Read a constant value from an attribute. Either set *VALUE, or if
22047 the value does not fit in *VALUE, set *BYTES - either already
22048 allocated on the objfile obstack, or newly allocated on OBSTACK,
22049 or, set *BATON, if we translated the constant to a location
22053 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22054 const char *name
, struct obstack
*obstack
,
22055 struct dwarf2_cu
*cu
,
22056 LONGEST
*value
, const gdb_byte
**bytes
,
22057 struct dwarf2_locexpr_baton
**baton
)
22059 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22060 struct comp_unit_head
*cu_header
= &cu
->header
;
22061 struct dwarf_block
*blk
;
22062 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22063 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22069 switch (attr
->form
)
22072 case DW_FORM_addrx
:
22073 case DW_FORM_GNU_addr_index
:
22077 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22078 dwarf2_const_value_length_mismatch_complaint (name
,
22079 cu_header
->addr_size
,
22080 TYPE_LENGTH (type
));
22081 /* Symbols of this form are reasonably rare, so we just
22082 piggyback on the existing location code rather than writing
22083 a new implementation of symbol_computed_ops. */
22084 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22085 (*baton
)->per_cu
= cu
->per_cu
;
22086 gdb_assert ((*baton
)->per_cu
);
22088 (*baton
)->size
= 2 + cu_header
->addr_size
;
22089 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22090 (*baton
)->data
= data
;
22092 data
[0] = DW_OP_addr
;
22093 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22094 byte_order
, DW_ADDR (attr
));
22095 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22098 case DW_FORM_string
:
22101 case DW_FORM_GNU_str_index
:
22102 case DW_FORM_GNU_strp_alt
:
22103 /* DW_STRING is already allocated on the objfile obstack, point
22105 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22107 case DW_FORM_block1
:
22108 case DW_FORM_block2
:
22109 case DW_FORM_block4
:
22110 case DW_FORM_block
:
22111 case DW_FORM_exprloc
:
22112 case DW_FORM_data16
:
22113 blk
= DW_BLOCK (attr
);
22114 if (TYPE_LENGTH (type
) != blk
->size
)
22115 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22116 TYPE_LENGTH (type
));
22117 *bytes
= blk
->data
;
22120 /* The DW_AT_const_value attributes are supposed to carry the
22121 symbol's value "represented as it would be on the target
22122 architecture." By the time we get here, it's already been
22123 converted to host endianness, so we just need to sign- or
22124 zero-extend it as appropriate. */
22125 case DW_FORM_data1
:
22126 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22128 case DW_FORM_data2
:
22129 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22131 case DW_FORM_data4
:
22132 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22134 case DW_FORM_data8
:
22135 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22138 case DW_FORM_sdata
:
22139 case DW_FORM_implicit_const
:
22140 *value
= DW_SND (attr
);
22143 case DW_FORM_udata
:
22144 *value
= DW_UNSND (attr
);
22148 complaint (_("unsupported const value attribute form: '%s'"),
22149 dwarf_form_name (attr
->form
));
22156 /* Copy constant value from an attribute to a symbol. */
22159 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22160 struct dwarf2_cu
*cu
)
22162 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22164 const gdb_byte
*bytes
;
22165 struct dwarf2_locexpr_baton
*baton
;
22167 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22168 sym
->print_name (),
22169 &objfile
->objfile_obstack
, cu
,
22170 &value
, &bytes
, &baton
);
22174 SYMBOL_LOCATION_BATON (sym
) = baton
;
22175 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22177 else if (bytes
!= NULL
)
22179 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22180 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22184 SYMBOL_VALUE (sym
) = value
;
22185 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22189 /* Return the type of the die in question using its DW_AT_type attribute. */
22191 static struct type
*
22192 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22194 struct attribute
*type_attr
;
22196 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22199 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22200 /* A missing DW_AT_type represents a void type. */
22201 return objfile_type (objfile
)->builtin_void
;
22204 return lookup_die_type (die
, type_attr
, cu
);
22207 /* True iff CU's producer generates GNAT Ada auxiliary information
22208 that allows to find parallel types through that information instead
22209 of having to do expensive parallel lookups by type name. */
22212 need_gnat_info (struct dwarf2_cu
*cu
)
22214 /* Assume that the Ada compiler was GNAT, which always produces
22215 the auxiliary information. */
22216 return (cu
->language
== language_ada
);
22219 /* Return the auxiliary type of the die in question using its
22220 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22221 attribute is not present. */
22223 static struct type
*
22224 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22226 struct attribute
*type_attr
;
22228 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22232 return lookup_die_type (die
, type_attr
, cu
);
22235 /* If DIE has a descriptive_type attribute, then set the TYPE's
22236 descriptive type accordingly. */
22239 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22240 struct dwarf2_cu
*cu
)
22242 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22244 if (descriptive_type
)
22246 ALLOCATE_GNAT_AUX_TYPE (type
);
22247 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22251 /* Return the containing type of the die in question using its
22252 DW_AT_containing_type attribute. */
22254 static struct type
*
22255 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22257 struct attribute
*type_attr
;
22258 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22260 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22262 error (_("Dwarf Error: Problem turning containing type into gdb type "
22263 "[in module %s]"), objfile_name (objfile
));
22265 return lookup_die_type (die
, type_attr
, cu
);
22268 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22270 static struct type
*
22271 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22273 struct dwarf2_per_objfile
*dwarf2_per_objfile
22274 = cu
->per_cu
->dwarf2_per_objfile
;
22275 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22278 std::string message
22279 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22280 objfile_name (objfile
),
22281 sect_offset_str (cu
->header
.sect_off
),
22282 sect_offset_str (die
->sect_off
));
22283 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22285 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22288 /* Look up the type of DIE in CU using its type attribute ATTR.
22289 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22290 DW_AT_containing_type.
22291 If there is no type substitute an error marker. */
22293 static struct type
*
22294 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22295 struct dwarf2_cu
*cu
)
22297 struct dwarf2_per_objfile
*dwarf2_per_objfile
22298 = cu
->per_cu
->dwarf2_per_objfile
;
22299 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22300 struct type
*this_type
;
22302 gdb_assert (attr
->name
== DW_AT_type
22303 || attr
->name
== DW_AT_GNAT_descriptive_type
22304 || attr
->name
== DW_AT_containing_type
);
22306 /* First see if we have it cached. */
22308 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22310 struct dwarf2_per_cu_data
*per_cu
;
22311 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22313 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22314 dwarf2_per_objfile
);
22315 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22317 else if (attr_form_is_ref (attr
))
22319 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22321 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22323 else if (attr
->form
== DW_FORM_ref_sig8
)
22325 ULONGEST signature
= DW_SIGNATURE (attr
);
22327 return get_signatured_type (die
, signature
, cu
);
22331 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22332 " at %s [in module %s]"),
22333 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22334 objfile_name (objfile
));
22335 return build_error_marker_type (cu
, die
);
22338 /* If not cached we need to read it in. */
22340 if (this_type
== NULL
)
22342 struct die_info
*type_die
= NULL
;
22343 struct dwarf2_cu
*type_cu
= cu
;
22345 if (attr_form_is_ref (attr
))
22346 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22347 if (type_die
== NULL
)
22348 return build_error_marker_type (cu
, die
);
22349 /* If we find the type now, it's probably because the type came
22350 from an inter-CU reference and the type's CU got expanded before
22352 this_type
= read_type_die (type_die
, type_cu
);
22355 /* If we still don't have a type use an error marker. */
22357 if (this_type
== NULL
)
22358 return build_error_marker_type (cu
, die
);
22363 /* Return the type in DIE, CU.
22364 Returns NULL for invalid types.
22366 This first does a lookup in die_type_hash,
22367 and only reads the die in if necessary.
22369 NOTE: This can be called when reading in partial or full symbols. */
22371 static struct type
*
22372 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22374 struct type
*this_type
;
22376 this_type
= get_die_type (die
, cu
);
22380 return read_type_die_1 (die
, cu
);
22383 /* Read the type in DIE, CU.
22384 Returns NULL for invalid types. */
22386 static struct type
*
22387 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22389 struct type
*this_type
= NULL
;
22393 case DW_TAG_class_type
:
22394 case DW_TAG_interface_type
:
22395 case DW_TAG_structure_type
:
22396 case DW_TAG_union_type
:
22397 this_type
= read_structure_type (die
, cu
);
22399 case DW_TAG_enumeration_type
:
22400 this_type
= read_enumeration_type (die
, cu
);
22402 case DW_TAG_subprogram
:
22403 case DW_TAG_subroutine_type
:
22404 case DW_TAG_inlined_subroutine
:
22405 this_type
= read_subroutine_type (die
, cu
);
22407 case DW_TAG_array_type
:
22408 this_type
= read_array_type (die
, cu
);
22410 case DW_TAG_set_type
:
22411 this_type
= read_set_type (die
, cu
);
22413 case DW_TAG_pointer_type
:
22414 this_type
= read_tag_pointer_type (die
, cu
);
22416 case DW_TAG_ptr_to_member_type
:
22417 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22419 case DW_TAG_reference_type
:
22420 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22422 case DW_TAG_rvalue_reference_type
:
22423 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22425 case DW_TAG_const_type
:
22426 this_type
= read_tag_const_type (die
, cu
);
22428 case DW_TAG_volatile_type
:
22429 this_type
= read_tag_volatile_type (die
, cu
);
22431 case DW_TAG_restrict_type
:
22432 this_type
= read_tag_restrict_type (die
, cu
);
22434 case DW_TAG_string_type
:
22435 this_type
= read_tag_string_type (die
, cu
);
22437 case DW_TAG_typedef
:
22438 this_type
= read_typedef (die
, cu
);
22440 case DW_TAG_subrange_type
:
22441 this_type
= read_subrange_type (die
, cu
);
22443 case DW_TAG_base_type
:
22444 this_type
= read_base_type (die
, cu
);
22446 case DW_TAG_unspecified_type
:
22447 this_type
= read_unspecified_type (die
, cu
);
22449 case DW_TAG_namespace
:
22450 this_type
= read_namespace_type (die
, cu
);
22452 case DW_TAG_module
:
22453 this_type
= read_module_type (die
, cu
);
22455 case DW_TAG_atomic_type
:
22456 this_type
= read_tag_atomic_type (die
, cu
);
22459 complaint (_("unexpected tag in read_type_die: '%s'"),
22460 dwarf_tag_name (die
->tag
));
22467 /* See if we can figure out if the class lives in a namespace. We do
22468 this by looking for a member function; its demangled name will
22469 contain namespace info, if there is any.
22470 Return the computed name or NULL.
22471 Space for the result is allocated on the objfile's obstack.
22472 This is the full-die version of guess_partial_die_structure_name.
22473 In this case we know DIE has no useful parent. */
22476 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22478 struct die_info
*spec_die
;
22479 struct dwarf2_cu
*spec_cu
;
22480 struct die_info
*child
;
22481 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22484 spec_die
= die_specification (die
, &spec_cu
);
22485 if (spec_die
!= NULL
)
22491 for (child
= die
->child
;
22493 child
= child
->sibling
)
22495 if (child
->tag
== DW_TAG_subprogram
)
22497 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22499 if (linkage_name
!= NULL
)
22502 = language_class_name_from_physname (cu
->language_defn
,
22506 if (actual_name
!= NULL
)
22508 const char *die_name
= dwarf2_name (die
, cu
);
22510 if (die_name
!= NULL
22511 && strcmp (die_name
, actual_name
) != 0)
22513 /* Strip off the class name from the full name.
22514 We want the prefix. */
22515 int die_name_len
= strlen (die_name
);
22516 int actual_name_len
= strlen (actual_name
);
22518 /* Test for '::' as a sanity check. */
22519 if (actual_name_len
> die_name_len
+ 2
22520 && actual_name
[actual_name_len
22521 - die_name_len
- 1] == ':')
22522 name
= obstack_strndup (
22523 &objfile
->per_bfd
->storage_obstack
,
22524 actual_name
, actual_name_len
- die_name_len
- 2);
22527 xfree (actual_name
);
22536 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22537 prefix part in such case. See
22538 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22540 static const char *
22541 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22543 struct attribute
*attr
;
22546 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22547 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22550 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22553 attr
= dw2_linkage_name_attr (die
, cu
);
22554 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22557 /* dwarf2_name had to be already called. */
22558 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22560 /* Strip the base name, keep any leading namespaces/classes. */
22561 base
= strrchr (DW_STRING (attr
), ':');
22562 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22565 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22566 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22568 &base
[-1] - DW_STRING (attr
));
22571 /* Return the name of the namespace/class that DIE is defined within,
22572 or "" if we can't tell. The caller should not xfree the result.
22574 For example, if we're within the method foo() in the following
22584 then determine_prefix on foo's die will return "N::C". */
22586 static const char *
22587 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22589 struct dwarf2_per_objfile
*dwarf2_per_objfile
22590 = cu
->per_cu
->dwarf2_per_objfile
;
22591 struct die_info
*parent
, *spec_die
;
22592 struct dwarf2_cu
*spec_cu
;
22593 struct type
*parent_type
;
22594 const char *retval
;
22596 if (cu
->language
!= language_cplus
22597 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22598 && cu
->language
!= language_rust
)
22601 retval
= anonymous_struct_prefix (die
, cu
);
22605 /* We have to be careful in the presence of DW_AT_specification.
22606 For example, with GCC 3.4, given the code
22610 // Definition of N::foo.
22614 then we'll have a tree of DIEs like this:
22616 1: DW_TAG_compile_unit
22617 2: DW_TAG_namespace // N
22618 3: DW_TAG_subprogram // declaration of N::foo
22619 4: DW_TAG_subprogram // definition of N::foo
22620 DW_AT_specification // refers to die #3
22622 Thus, when processing die #4, we have to pretend that we're in
22623 the context of its DW_AT_specification, namely the contex of die
22626 spec_die
= die_specification (die
, &spec_cu
);
22627 if (spec_die
== NULL
)
22628 parent
= die
->parent
;
22631 parent
= spec_die
->parent
;
22635 if (parent
== NULL
)
22637 else if (parent
->building_fullname
)
22640 const char *parent_name
;
22642 /* It has been seen on RealView 2.2 built binaries,
22643 DW_TAG_template_type_param types actually _defined_ as
22644 children of the parent class:
22647 template class <class Enum> Class{};
22648 Class<enum E> class_e;
22650 1: DW_TAG_class_type (Class)
22651 2: DW_TAG_enumeration_type (E)
22652 3: DW_TAG_enumerator (enum1:0)
22653 3: DW_TAG_enumerator (enum2:1)
22655 2: DW_TAG_template_type_param
22656 DW_AT_type DW_FORM_ref_udata (E)
22658 Besides being broken debug info, it can put GDB into an
22659 infinite loop. Consider:
22661 When we're building the full name for Class<E>, we'll start
22662 at Class, and go look over its template type parameters,
22663 finding E. We'll then try to build the full name of E, and
22664 reach here. We're now trying to build the full name of E,
22665 and look over the parent DIE for containing scope. In the
22666 broken case, if we followed the parent DIE of E, we'd again
22667 find Class, and once again go look at its template type
22668 arguments, etc., etc. Simply don't consider such parent die
22669 as source-level parent of this die (it can't be, the language
22670 doesn't allow it), and break the loop here. */
22671 name
= dwarf2_name (die
, cu
);
22672 parent_name
= dwarf2_name (parent
, cu
);
22673 complaint (_("template param type '%s' defined within parent '%s'"),
22674 name
? name
: "<unknown>",
22675 parent_name
? parent_name
: "<unknown>");
22679 switch (parent
->tag
)
22681 case DW_TAG_namespace
:
22682 parent_type
= read_type_die (parent
, cu
);
22683 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22684 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22685 Work around this problem here. */
22686 if (cu
->language
== language_cplus
22687 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22689 /* We give a name to even anonymous namespaces. */
22690 return TYPE_NAME (parent_type
);
22691 case DW_TAG_class_type
:
22692 case DW_TAG_interface_type
:
22693 case DW_TAG_structure_type
:
22694 case DW_TAG_union_type
:
22695 case DW_TAG_module
:
22696 parent_type
= read_type_die (parent
, cu
);
22697 if (TYPE_NAME (parent_type
) != NULL
)
22698 return TYPE_NAME (parent_type
);
22700 /* An anonymous structure is only allowed non-static data
22701 members; no typedefs, no member functions, et cetera.
22702 So it does not need a prefix. */
22704 case DW_TAG_compile_unit
:
22705 case DW_TAG_partial_unit
:
22706 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22707 if (cu
->language
== language_cplus
22708 && !dwarf2_per_objfile
->types
.empty ()
22709 && die
->child
!= NULL
22710 && (die
->tag
== DW_TAG_class_type
22711 || die
->tag
== DW_TAG_structure_type
22712 || die
->tag
== DW_TAG_union_type
))
22714 char *name
= guess_full_die_structure_name (die
, cu
);
22719 case DW_TAG_subprogram
:
22720 /* Nested subroutines in Fortran get a prefix with the name
22721 of the parent's subroutine. */
22722 if (cu
->language
== language_fortran
)
22724 if ((die
->tag
== DW_TAG_subprogram
)
22725 && (dwarf2_name (parent
, cu
) != NULL
))
22726 return dwarf2_name (parent
, cu
);
22728 return determine_prefix (parent
, cu
);
22729 case DW_TAG_enumeration_type
:
22730 parent_type
= read_type_die (parent
, cu
);
22731 if (TYPE_DECLARED_CLASS (parent_type
))
22733 if (TYPE_NAME (parent_type
) != NULL
)
22734 return TYPE_NAME (parent_type
);
22737 /* Fall through. */
22739 return determine_prefix (parent
, cu
);
22743 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22744 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22745 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22746 an obconcat, otherwise allocate storage for the result. The CU argument is
22747 used to determine the language and hence, the appropriate separator. */
22749 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22752 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22753 int physname
, struct dwarf2_cu
*cu
)
22755 const char *lead
= "";
22758 if (suffix
== NULL
|| suffix
[0] == '\0'
22759 || prefix
== NULL
|| prefix
[0] == '\0')
22761 else if (cu
->language
== language_d
)
22763 /* For D, the 'main' function could be defined in any module, but it
22764 should never be prefixed. */
22765 if (strcmp (suffix
, "D main") == 0)
22773 else if (cu
->language
== language_fortran
&& physname
)
22775 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22776 DW_AT_MIPS_linkage_name is preferred and used instead. */
22784 if (prefix
== NULL
)
22786 if (suffix
== NULL
)
22793 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22795 strcpy (retval
, lead
);
22796 strcat (retval
, prefix
);
22797 strcat (retval
, sep
);
22798 strcat (retval
, suffix
);
22803 /* We have an obstack. */
22804 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22808 /* Return sibling of die, NULL if no sibling. */
22810 static struct die_info
*
22811 sibling_die (struct die_info
*die
)
22813 return die
->sibling
;
22816 /* Get name of a die, return NULL if not found. */
22818 static const char *
22819 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22820 struct obstack
*obstack
)
22822 if (name
&& cu
->language
== language_cplus
)
22824 std::string canon_name
= cp_canonicalize_string (name
);
22826 if (!canon_name
.empty ())
22828 if (canon_name
!= name
)
22829 name
= obstack_strdup (obstack
, canon_name
);
22836 /* Get name of a die, return NULL if not found.
22837 Anonymous namespaces are converted to their magic string. */
22839 static const char *
22840 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22842 struct attribute
*attr
;
22843 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22845 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22846 if ((!attr
|| !DW_STRING (attr
))
22847 && die
->tag
!= DW_TAG_namespace
22848 && die
->tag
!= DW_TAG_class_type
22849 && die
->tag
!= DW_TAG_interface_type
22850 && die
->tag
!= DW_TAG_structure_type
22851 && die
->tag
!= DW_TAG_union_type
)
22856 case DW_TAG_compile_unit
:
22857 case DW_TAG_partial_unit
:
22858 /* Compilation units have a DW_AT_name that is a filename, not
22859 a source language identifier. */
22860 case DW_TAG_enumeration_type
:
22861 case DW_TAG_enumerator
:
22862 /* These tags always have simple identifiers already; no need
22863 to canonicalize them. */
22864 return DW_STRING (attr
);
22866 case DW_TAG_namespace
:
22867 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22868 return DW_STRING (attr
);
22869 return CP_ANONYMOUS_NAMESPACE_STR
;
22871 case DW_TAG_class_type
:
22872 case DW_TAG_interface_type
:
22873 case DW_TAG_structure_type
:
22874 case DW_TAG_union_type
:
22875 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22876 structures or unions. These were of the form "._%d" in GCC 4.1,
22877 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22878 and GCC 4.4. We work around this problem by ignoring these. */
22879 if (attr
&& DW_STRING (attr
)
22880 && (startswith (DW_STRING (attr
), "._")
22881 || startswith (DW_STRING (attr
), "<anonymous")))
22884 /* GCC might emit a nameless typedef that has a linkage name. See
22885 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22886 if (!attr
|| DW_STRING (attr
) == NULL
)
22888 char *demangled
= NULL
;
22890 attr
= dw2_linkage_name_attr (die
, cu
);
22891 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22894 /* Avoid demangling DW_STRING (attr) the second time on a second
22895 call for the same DIE. */
22896 if (!DW_STRING_IS_CANONICAL (attr
))
22897 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22903 /* FIXME: we already did this for the partial symbol... */
22905 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
22907 DW_STRING_IS_CANONICAL (attr
) = 1;
22910 /* Strip any leading namespaces/classes, keep only the base name.
22911 DW_AT_name for named DIEs does not contain the prefixes. */
22912 base
= strrchr (DW_STRING (attr
), ':');
22913 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22916 return DW_STRING (attr
);
22925 if (!DW_STRING_IS_CANONICAL (attr
))
22928 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22929 &objfile
->per_bfd
->storage_obstack
);
22930 DW_STRING_IS_CANONICAL (attr
) = 1;
22932 return DW_STRING (attr
);
22935 /* Return the die that this die in an extension of, or NULL if there
22936 is none. *EXT_CU is the CU containing DIE on input, and the CU
22937 containing the return value on output. */
22939 static struct die_info
*
22940 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22942 struct attribute
*attr
;
22944 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22948 return follow_die_ref (die
, attr
, ext_cu
);
22951 /* A convenience function that returns an "unknown" DWARF name,
22952 including the value of V. STR is the name of the entity being
22953 printed, e.g., "TAG". */
22955 static const char *
22956 dwarf_unknown (const char *str
, unsigned v
)
22958 char *cell
= get_print_cell ();
22959 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
22963 /* Convert a DIE tag into its string name. */
22965 static const char *
22966 dwarf_tag_name (unsigned tag
)
22968 const char *name
= get_DW_TAG_name (tag
);
22971 return dwarf_unknown ("TAG", tag
);
22976 /* Convert a DWARF attribute code into its string name. */
22978 static const char *
22979 dwarf_attr_name (unsigned attr
)
22983 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22984 if (attr
== DW_AT_MIPS_fde
)
22985 return "DW_AT_MIPS_fde";
22987 if (attr
== DW_AT_HP_block_index
)
22988 return "DW_AT_HP_block_index";
22991 name
= get_DW_AT_name (attr
);
22994 return dwarf_unknown ("AT", attr
);
22999 /* Convert a unit type to corresponding DW_UT name. */
23001 static const char *
23002 dwarf_unit_type_name (int unit_type
) {
23006 return "DW_UT_compile (0x01)";
23008 return "DW_UT_type (0x02)";
23010 return "DW_UT_partial (0x03)";
23012 return "DW_UT_skeleton (0x04)";
23014 return "DW_UT_split_compile (0x05)";
23016 return "DW_UT_split_type (0x06)";
23018 return "DW_UT_lo_user (0x80)";
23020 return "DW_UT_hi_user (0xff)";
23026 /* Convert a DWARF value form code into its string name. */
23028 static const char *
23029 dwarf_form_name (unsigned form
)
23031 const char *name
= get_DW_FORM_name (form
);
23034 return dwarf_unknown ("FORM", form
);
23039 static const char *
23040 dwarf_bool_name (unsigned mybool
)
23048 /* Convert a DWARF type code into its string name. */
23050 static const char *
23051 dwarf_type_encoding_name (unsigned enc
)
23053 const char *name
= get_DW_ATE_name (enc
);
23056 return dwarf_unknown ("ATE", enc
);
23062 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23066 print_spaces (indent
, f
);
23067 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23068 dwarf_tag_name (die
->tag
), die
->abbrev
,
23069 sect_offset_str (die
->sect_off
));
23071 if (die
->parent
!= NULL
)
23073 print_spaces (indent
, f
);
23074 fprintf_unfiltered (f
, " parent at offset: %s\n",
23075 sect_offset_str (die
->parent
->sect_off
));
23078 print_spaces (indent
, f
);
23079 fprintf_unfiltered (f
, " has children: %s\n",
23080 dwarf_bool_name (die
->child
!= NULL
));
23082 print_spaces (indent
, f
);
23083 fprintf_unfiltered (f
, " attributes:\n");
23085 for (i
= 0; i
< die
->num_attrs
; ++i
)
23087 print_spaces (indent
, f
);
23088 fprintf_unfiltered (f
, " %s (%s) ",
23089 dwarf_attr_name (die
->attrs
[i
].name
),
23090 dwarf_form_name (die
->attrs
[i
].form
));
23092 switch (die
->attrs
[i
].form
)
23095 case DW_FORM_addrx
:
23096 case DW_FORM_GNU_addr_index
:
23097 fprintf_unfiltered (f
, "address: ");
23098 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23100 case DW_FORM_block2
:
23101 case DW_FORM_block4
:
23102 case DW_FORM_block
:
23103 case DW_FORM_block1
:
23104 fprintf_unfiltered (f
, "block: size %s",
23105 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23107 case DW_FORM_exprloc
:
23108 fprintf_unfiltered (f
, "expression: size %s",
23109 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23111 case DW_FORM_data16
:
23112 fprintf_unfiltered (f
, "constant of 16 bytes");
23114 case DW_FORM_ref_addr
:
23115 fprintf_unfiltered (f
, "ref address: ");
23116 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23118 case DW_FORM_GNU_ref_alt
:
23119 fprintf_unfiltered (f
, "alt ref address: ");
23120 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23126 case DW_FORM_ref_udata
:
23127 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23128 (long) (DW_UNSND (&die
->attrs
[i
])));
23130 case DW_FORM_data1
:
23131 case DW_FORM_data2
:
23132 case DW_FORM_data4
:
23133 case DW_FORM_data8
:
23134 case DW_FORM_udata
:
23135 case DW_FORM_sdata
:
23136 fprintf_unfiltered (f
, "constant: %s",
23137 pulongest (DW_UNSND (&die
->attrs
[i
])));
23139 case DW_FORM_sec_offset
:
23140 fprintf_unfiltered (f
, "section offset: %s",
23141 pulongest (DW_UNSND (&die
->attrs
[i
])));
23143 case DW_FORM_ref_sig8
:
23144 fprintf_unfiltered (f
, "signature: %s",
23145 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23147 case DW_FORM_string
:
23149 case DW_FORM_line_strp
:
23151 case DW_FORM_GNU_str_index
:
23152 case DW_FORM_GNU_strp_alt
:
23153 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23154 DW_STRING (&die
->attrs
[i
])
23155 ? DW_STRING (&die
->attrs
[i
]) : "",
23156 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23159 if (DW_UNSND (&die
->attrs
[i
]))
23160 fprintf_unfiltered (f
, "flag: TRUE");
23162 fprintf_unfiltered (f
, "flag: FALSE");
23164 case DW_FORM_flag_present
:
23165 fprintf_unfiltered (f
, "flag: TRUE");
23167 case DW_FORM_indirect
:
23168 /* The reader will have reduced the indirect form to
23169 the "base form" so this form should not occur. */
23170 fprintf_unfiltered (f
,
23171 "unexpected attribute form: DW_FORM_indirect");
23173 case DW_FORM_implicit_const
:
23174 fprintf_unfiltered (f
, "constant: %s",
23175 plongest (DW_SND (&die
->attrs
[i
])));
23178 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23179 die
->attrs
[i
].form
);
23182 fprintf_unfiltered (f
, "\n");
23187 dump_die_for_error (struct die_info
*die
)
23189 dump_die_shallow (gdb_stderr
, 0, die
);
23193 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23195 int indent
= level
* 4;
23197 gdb_assert (die
!= NULL
);
23199 if (level
>= max_level
)
23202 dump_die_shallow (f
, indent
, die
);
23204 if (die
->child
!= NULL
)
23206 print_spaces (indent
, f
);
23207 fprintf_unfiltered (f
, " Children:");
23208 if (level
+ 1 < max_level
)
23210 fprintf_unfiltered (f
, "\n");
23211 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23215 fprintf_unfiltered (f
,
23216 " [not printed, max nesting level reached]\n");
23220 if (die
->sibling
!= NULL
&& level
> 0)
23222 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23226 /* This is called from the pdie macro in gdbinit.in.
23227 It's not static so gcc will keep a copy callable from gdb. */
23230 dump_die (struct die_info
*die
, int max_level
)
23232 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23236 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23240 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23241 to_underlying (die
->sect_off
),
23247 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23251 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23253 if (attr_form_is_ref (attr
))
23254 return (sect_offset
) DW_UNSND (attr
);
23256 complaint (_("unsupported die ref attribute form: '%s'"),
23257 dwarf_form_name (attr
->form
));
23261 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23262 * the value held by the attribute is not constant. */
23265 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23267 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23268 return DW_SND (attr
);
23269 else if (attr
->form
== DW_FORM_udata
23270 || attr
->form
== DW_FORM_data1
23271 || attr
->form
== DW_FORM_data2
23272 || attr
->form
== DW_FORM_data4
23273 || attr
->form
== DW_FORM_data8
)
23274 return DW_UNSND (attr
);
23277 /* For DW_FORM_data16 see attr_form_is_constant. */
23278 complaint (_("Attribute value is not a constant (%s)"),
23279 dwarf_form_name (attr
->form
));
23280 return default_value
;
23284 /* Follow reference or signature attribute ATTR of SRC_DIE.
23285 On entry *REF_CU is the CU of SRC_DIE.
23286 On exit *REF_CU is the CU of the result. */
23288 static struct die_info
*
23289 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23290 struct dwarf2_cu
**ref_cu
)
23292 struct die_info
*die
;
23294 if (attr_form_is_ref (attr
))
23295 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23296 else if (attr
->form
== DW_FORM_ref_sig8
)
23297 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23300 dump_die_for_error (src_die
);
23301 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23302 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23308 /* Follow reference OFFSET.
23309 On entry *REF_CU is the CU of the source die referencing OFFSET.
23310 On exit *REF_CU is the CU of the result.
23311 Returns NULL if OFFSET is invalid. */
23313 static struct die_info
*
23314 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23315 struct dwarf2_cu
**ref_cu
)
23317 struct die_info temp_die
;
23318 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23319 struct dwarf2_per_objfile
*dwarf2_per_objfile
23320 = cu
->per_cu
->dwarf2_per_objfile
;
23322 gdb_assert (cu
->per_cu
!= NULL
);
23326 if (cu
->per_cu
->is_debug_types
)
23328 /* .debug_types CUs cannot reference anything outside their CU.
23329 If they need to, they have to reference a signatured type via
23330 DW_FORM_ref_sig8. */
23331 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23334 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23335 || !offset_in_cu_p (&cu
->header
, sect_off
))
23337 struct dwarf2_per_cu_data
*per_cu
;
23339 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23340 dwarf2_per_objfile
);
23342 /* If necessary, add it to the queue and load its DIEs. */
23343 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23344 load_full_comp_unit (per_cu
, false, cu
->language
);
23346 target_cu
= per_cu
->cu
;
23348 else if (cu
->dies
== NULL
)
23350 /* We're loading full DIEs during partial symbol reading. */
23351 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23352 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23355 *ref_cu
= target_cu
;
23356 temp_die
.sect_off
= sect_off
;
23358 if (target_cu
!= cu
)
23359 target_cu
->ancestor
= cu
;
23361 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23363 to_underlying (sect_off
));
23366 /* Follow reference attribute ATTR of SRC_DIE.
23367 On entry *REF_CU is the CU of SRC_DIE.
23368 On exit *REF_CU is the CU of the result. */
23370 static struct die_info
*
23371 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23372 struct dwarf2_cu
**ref_cu
)
23374 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23375 struct dwarf2_cu
*cu
= *ref_cu
;
23376 struct die_info
*die
;
23378 die
= follow_die_offset (sect_off
,
23379 (attr
->form
== DW_FORM_GNU_ref_alt
23380 || cu
->per_cu
->is_dwz
),
23383 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23384 "at %s [in module %s]"),
23385 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23386 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23391 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23392 Returned value is intended for DW_OP_call*. Returned
23393 dwarf2_locexpr_baton->data has lifetime of
23394 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23396 struct dwarf2_locexpr_baton
23397 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23398 struct dwarf2_per_cu_data
*per_cu
,
23399 CORE_ADDR (*get_frame_pc
) (void *baton
),
23400 void *baton
, bool resolve_abstract_p
)
23402 struct dwarf2_cu
*cu
;
23403 struct die_info
*die
;
23404 struct attribute
*attr
;
23405 struct dwarf2_locexpr_baton retval
;
23406 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23407 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23409 if (per_cu
->cu
== NULL
)
23410 load_cu (per_cu
, false);
23414 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23415 Instead just throw an error, not much else we can do. */
23416 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23417 sect_offset_str (sect_off
), objfile_name (objfile
));
23420 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23422 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23423 sect_offset_str (sect_off
), objfile_name (objfile
));
23425 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23426 if (!attr
&& resolve_abstract_p
23427 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23428 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23430 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23432 = ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23433 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23435 for (const auto &cand_off
23436 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23438 struct dwarf2_cu
*cand_cu
= cu
;
23439 struct die_info
*cand
23440 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23443 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23446 CORE_ADDR pc_low
, pc_high
;
23447 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23448 if (pc_low
== ((CORE_ADDR
) -1))
23450 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23451 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23452 if (!(pc_low
<= pc
&& pc
< pc_high
))
23456 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23463 /* DWARF: "If there is no such attribute, then there is no effect.".
23464 DATA is ignored if SIZE is 0. */
23466 retval
.data
= NULL
;
23469 else if (attr_form_is_section_offset (attr
))
23471 struct dwarf2_loclist_baton loclist_baton
;
23472 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23475 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23477 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23479 retval
.size
= size
;
23483 if (!attr_form_is_block (attr
))
23484 error (_("Dwarf Error: DIE at %s referenced in module %s "
23485 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23486 sect_offset_str (sect_off
), objfile_name (objfile
));
23488 retval
.data
= DW_BLOCK (attr
)->data
;
23489 retval
.size
= DW_BLOCK (attr
)->size
;
23491 retval
.per_cu
= cu
->per_cu
;
23493 age_cached_comp_units (dwarf2_per_objfile
);
23498 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23501 struct dwarf2_locexpr_baton
23502 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23503 struct dwarf2_per_cu_data
*per_cu
,
23504 CORE_ADDR (*get_frame_pc
) (void *baton
),
23507 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23509 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23512 /* Write a constant of a given type as target-ordered bytes into
23515 static const gdb_byte
*
23516 write_constant_as_bytes (struct obstack
*obstack
,
23517 enum bfd_endian byte_order
,
23524 *len
= TYPE_LENGTH (type
);
23525 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23526 store_unsigned_integer (result
, *len
, byte_order
, value
);
23531 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23532 pointer to the constant bytes and set LEN to the length of the
23533 data. If memory is needed, allocate it on OBSTACK. If the DIE
23534 does not have a DW_AT_const_value, return NULL. */
23537 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23538 struct dwarf2_per_cu_data
*per_cu
,
23539 struct obstack
*obstack
,
23542 struct dwarf2_cu
*cu
;
23543 struct die_info
*die
;
23544 struct attribute
*attr
;
23545 const gdb_byte
*result
= NULL
;
23548 enum bfd_endian byte_order
;
23549 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23551 if (per_cu
->cu
== NULL
)
23552 load_cu (per_cu
, false);
23556 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23557 Instead just throw an error, not much else we can do. */
23558 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23559 sect_offset_str (sect_off
), objfile_name (objfile
));
23562 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23564 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23565 sect_offset_str (sect_off
), objfile_name (objfile
));
23567 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23571 byte_order
= (bfd_big_endian (objfile
->obfd
)
23572 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23574 switch (attr
->form
)
23577 case DW_FORM_addrx
:
23578 case DW_FORM_GNU_addr_index
:
23582 *len
= cu
->header
.addr_size
;
23583 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23584 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23588 case DW_FORM_string
:
23591 case DW_FORM_GNU_str_index
:
23592 case DW_FORM_GNU_strp_alt
:
23593 /* DW_STRING is already allocated on the objfile obstack, point
23595 result
= (const gdb_byte
*) DW_STRING (attr
);
23596 *len
= strlen (DW_STRING (attr
));
23598 case DW_FORM_block1
:
23599 case DW_FORM_block2
:
23600 case DW_FORM_block4
:
23601 case DW_FORM_block
:
23602 case DW_FORM_exprloc
:
23603 case DW_FORM_data16
:
23604 result
= DW_BLOCK (attr
)->data
;
23605 *len
= DW_BLOCK (attr
)->size
;
23608 /* The DW_AT_const_value attributes are supposed to carry the
23609 symbol's value "represented as it would be on the target
23610 architecture." By the time we get here, it's already been
23611 converted to host endianness, so we just need to sign- or
23612 zero-extend it as appropriate. */
23613 case DW_FORM_data1
:
23614 type
= die_type (die
, cu
);
23615 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23616 if (result
== NULL
)
23617 result
= write_constant_as_bytes (obstack
, byte_order
,
23620 case DW_FORM_data2
:
23621 type
= die_type (die
, cu
);
23622 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23623 if (result
== NULL
)
23624 result
= write_constant_as_bytes (obstack
, byte_order
,
23627 case DW_FORM_data4
:
23628 type
= die_type (die
, cu
);
23629 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23630 if (result
== NULL
)
23631 result
= write_constant_as_bytes (obstack
, byte_order
,
23634 case DW_FORM_data8
:
23635 type
= die_type (die
, cu
);
23636 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23637 if (result
== NULL
)
23638 result
= write_constant_as_bytes (obstack
, byte_order
,
23642 case DW_FORM_sdata
:
23643 case DW_FORM_implicit_const
:
23644 type
= die_type (die
, cu
);
23645 result
= write_constant_as_bytes (obstack
, byte_order
,
23646 type
, DW_SND (attr
), len
);
23649 case DW_FORM_udata
:
23650 type
= die_type (die
, cu
);
23651 result
= write_constant_as_bytes (obstack
, byte_order
,
23652 type
, DW_UNSND (attr
), len
);
23656 complaint (_("unsupported const value attribute form: '%s'"),
23657 dwarf_form_name (attr
->form
));
23664 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23665 valid type for this die is found. */
23668 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23669 struct dwarf2_per_cu_data
*per_cu
)
23671 struct dwarf2_cu
*cu
;
23672 struct die_info
*die
;
23674 if (per_cu
->cu
== NULL
)
23675 load_cu (per_cu
, false);
23680 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23684 return die_type (die
, cu
);
23687 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23691 dwarf2_get_die_type (cu_offset die_offset
,
23692 struct dwarf2_per_cu_data
*per_cu
)
23694 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23695 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23698 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23699 On entry *REF_CU is the CU of SRC_DIE.
23700 On exit *REF_CU is the CU of the result.
23701 Returns NULL if the referenced DIE isn't found. */
23703 static struct die_info
*
23704 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23705 struct dwarf2_cu
**ref_cu
)
23707 struct die_info temp_die
;
23708 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23709 struct die_info
*die
;
23711 /* While it might be nice to assert sig_type->type == NULL here,
23712 we can get here for DW_AT_imported_declaration where we need
23713 the DIE not the type. */
23715 /* If necessary, add it to the queue and load its DIEs. */
23717 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23718 read_signatured_type (sig_type
);
23720 sig_cu
= sig_type
->per_cu
.cu
;
23721 gdb_assert (sig_cu
!= NULL
);
23722 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23723 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23724 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23725 to_underlying (temp_die
.sect_off
));
23728 struct dwarf2_per_objfile
*dwarf2_per_objfile
23729 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23731 /* For .gdb_index version 7 keep track of included TUs.
23732 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23733 if (dwarf2_per_objfile
->index_table
!= NULL
23734 && dwarf2_per_objfile
->index_table
->version
<= 7)
23736 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23741 sig_cu
->ancestor
= cu
;
23749 /* Follow signatured type referenced by ATTR in SRC_DIE.
23750 On entry *REF_CU is the CU of SRC_DIE.
23751 On exit *REF_CU is the CU of the result.
23752 The result is the DIE of the type.
23753 If the referenced type cannot be found an error is thrown. */
23755 static struct die_info
*
23756 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23757 struct dwarf2_cu
**ref_cu
)
23759 ULONGEST signature
= DW_SIGNATURE (attr
);
23760 struct signatured_type
*sig_type
;
23761 struct die_info
*die
;
23763 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23765 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23766 /* sig_type will be NULL if the signatured type is missing from
23768 if (sig_type
== NULL
)
23770 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23771 " from DIE at %s [in module %s]"),
23772 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23773 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23776 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23779 dump_die_for_error (src_die
);
23780 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23781 " from DIE at %s [in module %s]"),
23782 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23783 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23789 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23790 reading in and processing the type unit if necessary. */
23792 static struct type
*
23793 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23794 struct dwarf2_cu
*cu
)
23796 struct dwarf2_per_objfile
*dwarf2_per_objfile
23797 = cu
->per_cu
->dwarf2_per_objfile
;
23798 struct signatured_type
*sig_type
;
23799 struct dwarf2_cu
*type_cu
;
23800 struct die_info
*type_die
;
23803 sig_type
= lookup_signatured_type (cu
, signature
);
23804 /* sig_type will be NULL if the signatured type is missing from
23806 if (sig_type
== NULL
)
23808 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23809 " from DIE at %s [in module %s]"),
23810 hex_string (signature
), sect_offset_str (die
->sect_off
),
23811 objfile_name (dwarf2_per_objfile
->objfile
));
23812 return build_error_marker_type (cu
, die
);
23815 /* If we already know the type we're done. */
23816 if (sig_type
->type
!= NULL
)
23817 return sig_type
->type
;
23820 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23821 if (type_die
!= NULL
)
23823 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23824 is created. This is important, for example, because for c++ classes
23825 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23826 type
= read_type_die (type_die
, type_cu
);
23829 complaint (_("Dwarf Error: Cannot build signatured type %s"
23830 " referenced from DIE at %s [in module %s]"),
23831 hex_string (signature
), sect_offset_str (die
->sect_off
),
23832 objfile_name (dwarf2_per_objfile
->objfile
));
23833 type
= build_error_marker_type (cu
, die
);
23838 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23839 " from DIE at %s [in module %s]"),
23840 hex_string (signature
), sect_offset_str (die
->sect_off
),
23841 objfile_name (dwarf2_per_objfile
->objfile
));
23842 type
= build_error_marker_type (cu
, die
);
23844 sig_type
->type
= type
;
23849 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23850 reading in and processing the type unit if necessary. */
23852 static struct type
*
23853 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23854 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23856 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23857 if (attr_form_is_ref (attr
))
23859 struct dwarf2_cu
*type_cu
= cu
;
23860 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23862 return read_type_die (type_die
, type_cu
);
23864 else if (attr
->form
== DW_FORM_ref_sig8
)
23866 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23870 struct dwarf2_per_objfile
*dwarf2_per_objfile
23871 = cu
->per_cu
->dwarf2_per_objfile
;
23873 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23874 " at %s [in module %s]"),
23875 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23876 objfile_name (dwarf2_per_objfile
->objfile
));
23877 return build_error_marker_type (cu
, die
);
23881 /* Load the DIEs associated with type unit PER_CU into memory. */
23884 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23886 struct signatured_type
*sig_type
;
23888 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23889 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23891 /* We have the per_cu, but we need the signatured_type.
23892 Fortunately this is an easy translation. */
23893 gdb_assert (per_cu
->is_debug_types
);
23894 sig_type
= (struct signatured_type
*) per_cu
;
23896 gdb_assert (per_cu
->cu
== NULL
);
23898 read_signatured_type (sig_type
);
23900 gdb_assert (per_cu
->cu
!= NULL
);
23903 /* die_reader_func for read_signatured_type.
23904 This is identical to load_full_comp_unit_reader,
23905 but is kept separate for now. */
23908 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23909 const gdb_byte
*info_ptr
,
23910 struct die_info
*comp_unit_die
,
23914 struct dwarf2_cu
*cu
= reader
->cu
;
23916 gdb_assert (cu
->die_hash
== NULL
);
23918 htab_create_alloc_ex (cu
->header
.length
/ 12,
23922 &cu
->comp_unit_obstack
,
23923 hashtab_obstack_allocate
,
23924 dummy_obstack_deallocate
);
23927 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23928 &info_ptr
, comp_unit_die
);
23929 cu
->dies
= comp_unit_die
;
23930 /* comp_unit_die is not stored in die_hash, no need. */
23932 /* We try not to read any attributes in this function, because not
23933 all CUs needed for references have been loaded yet, and symbol
23934 table processing isn't initialized. But we have to set the CU language,
23935 or we won't be able to build types correctly.
23936 Similarly, if we do not read the producer, we can not apply
23937 producer-specific interpretation. */
23938 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23941 /* Read in a signatured type and build its CU and DIEs.
23942 If the type is a stub for the real type in a DWO file,
23943 read in the real type from the DWO file as well. */
23946 read_signatured_type (struct signatured_type
*sig_type
)
23948 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23950 gdb_assert (per_cu
->is_debug_types
);
23951 gdb_assert (per_cu
->cu
== NULL
);
23953 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1, false,
23954 read_signatured_type_reader
, NULL
);
23955 sig_type
->per_cu
.tu_read
= 1;
23958 /* Decode simple location descriptions.
23959 Given a pointer to a dwarf block that defines a location, compute
23960 the location and return the value.
23962 NOTE drow/2003-11-18: This function is called in two situations
23963 now: for the address of static or global variables (partial symbols
23964 only) and for offsets into structures which are expected to be
23965 (more or less) constant. The partial symbol case should go away,
23966 and only the constant case should remain. That will let this
23967 function complain more accurately. A few special modes are allowed
23968 without complaint for global variables (for instance, global
23969 register values and thread-local values).
23971 A location description containing no operations indicates that the
23972 object is optimized out. The return value is 0 for that case.
23973 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23974 callers will only want a very basic result and this can become a
23977 Note that stack[0] is unused except as a default error return. */
23980 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23982 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23984 size_t size
= blk
->size
;
23985 const gdb_byte
*data
= blk
->data
;
23986 CORE_ADDR stack
[64];
23988 unsigned int bytes_read
, unsnd
;
23994 stack
[++stacki
] = 0;
24033 stack
[++stacki
] = op
- DW_OP_lit0
;
24068 stack
[++stacki
] = op
- DW_OP_reg0
;
24070 dwarf2_complex_location_expr_complaint ();
24074 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24076 stack
[++stacki
] = unsnd
;
24078 dwarf2_complex_location_expr_complaint ();
24082 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24087 case DW_OP_const1u
:
24088 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24092 case DW_OP_const1s
:
24093 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24097 case DW_OP_const2u
:
24098 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24102 case DW_OP_const2s
:
24103 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24107 case DW_OP_const4u
:
24108 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24112 case DW_OP_const4s
:
24113 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24117 case DW_OP_const8u
:
24118 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24123 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24129 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24134 stack
[stacki
+ 1] = stack
[stacki
];
24139 stack
[stacki
- 1] += stack
[stacki
];
24143 case DW_OP_plus_uconst
:
24144 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24150 stack
[stacki
- 1] -= stack
[stacki
];
24155 /* If we're not the last op, then we definitely can't encode
24156 this using GDB's address_class enum. This is valid for partial
24157 global symbols, although the variable's address will be bogus
24160 dwarf2_complex_location_expr_complaint ();
24163 case DW_OP_GNU_push_tls_address
:
24164 case DW_OP_form_tls_address
:
24165 /* The top of the stack has the offset from the beginning
24166 of the thread control block at which the variable is located. */
24167 /* Nothing should follow this operator, so the top of stack would
24169 /* This is valid for partial global symbols, but the variable's
24170 address will be bogus in the psymtab. Make it always at least
24171 non-zero to not look as a variable garbage collected by linker
24172 which have DW_OP_addr 0. */
24174 dwarf2_complex_location_expr_complaint ();
24178 case DW_OP_GNU_uninit
:
24182 case DW_OP_GNU_addr_index
:
24183 case DW_OP_GNU_const_index
:
24184 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24191 const char *name
= get_DW_OP_name (op
);
24194 complaint (_("unsupported stack op: '%s'"),
24197 complaint (_("unsupported stack op: '%02x'"),
24201 return (stack
[stacki
]);
24204 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24205 outside of the allocated space. Also enforce minimum>0. */
24206 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24208 complaint (_("location description stack overflow"));
24214 complaint (_("location description stack underflow"));
24218 return (stack
[stacki
]);
24221 /* memory allocation interface */
24223 static struct dwarf_block
*
24224 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24226 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24229 static struct die_info
*
24230 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24232 struct die_info
*die
;
24233 size_t size
= sizeof (struct die_info
);
24236 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24238 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24239 memset (die
, 0, sizeof (struct die_info
));
24244 /* Macro support. */
24246 /* Return file name relative to the compilation directory of file number I in
24247 *LH's file name table. The result is allocated using xmalloc; the caller is
24248 responsible for freeing it. */
24251 file_file_name (int file
, struct line_header
*lh
)
24253 /* Is the file number a valid index into the line header's file name
24254 table? Remember that file numbers start with one, not zero. */
24255 if (lh
->is_valid_file_index (file
))
24257 const file_entry
*fe
= lh
->file_name_at (file
);
24259 if (!IS_ABSOLUTE_PATH (fe
->name
))
24261 const char *dir
= fe
->include_dir (lh
);
24263 return concat (dir
, SLASH_STRING
, fe
->name
, (char *) NULL
);
24265 return xstrdup (fe
->name
);
24269 /* The compiler produced a bogus file number. We can at least
24270 record the macro definitions made in the file, even if we
24271 won't be able to find the file by name. */
24272 char fake_name
[80];
24274 xsnprintf (fake_name
, sizeof (fake_name
),
24275 "<bad macro file number %d>", file
);
24277 complaint (_("bad file number in macro information (%d)"),
24280 return xstrdup (fake_name
);
24284 /* Return the full name of file number I in *LH's file name table.
24285 Use COMP_DIR as the name of the current directory of the
24286 compilation. The result is allocated using xmalloc; the caller is
24287 responsible for freeing it. */
24289 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24291 /* Is the file number a valid index into the line header's file name
24292 table? Remember that file numbers start with one, not zero. */
24293 if (lh
->is_valid_file_index (file
))
24295 char *relative
= file_file_name (file
, lh
);
24297 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24299 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24300 relative
, (char *) NULL
);
24303 return file_file_name (file
, lh
);
24307 static struct macro_source_file
*
24308 macro_start_file (struct dwarf2_cu
*cu
,
24309 int file
, int line
,
24310 struct macro_source_file
*current_file
,
24311 struct line_header
*lh
)
24313 /* File name relative to the compilation directory of this source file. */
24314 char *file_name
= file_file_name (file
, lh
);
24316 if (! current_file
)
24318 /* Note: We don't create a macro table for this compilation unit
24319 at all until we actually get a filename. */
24320 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24322 /* If we have no current file, then this must be the start_file
24323 directive for the compilation unit's main source file. */
24324 current_file
= macro_set_main (macro_table
, file_name
);
24325 macro_define_special (macro_table
);
24328 current_file
= macro_include (current_file
, line
, file_name
);
24332 return current_file
;
24335 static const char *
24336 consume_improper_spaces (const char *p
, const char *body
)
24340 complaint (_("macro definition contains spaces "
24341 "in formal argument list:\n`%s'"),
24353 parse_macro_definition (struct macro_source_file
*file
, int line
,
24358 /* The body string takes one of two forms. For object-like macro
24359 definitions, it should be:
24361 <macro name> " " <definition>
24363 For function-like macro definitions, it should be:
24365 <macro name> "() " <definition>
24367 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24369 Spaces may appear only where explicitly indicated, and in the
24372 The Dwarf 2 spec says that an object-like macro's name is always
24373 followed by a space, but versions of GCC around March 2002 omit
24374 the space when the macro's definition is the empty string.
24376 The Dwarf 2 spec says that there should be no spaces between the
24377 formal arguments in a function-like macro's formal argument list,
24378 but versions of GCC around March 2002 include spaces after the
24382 /* Find the extent of the macro name. The macro name is terminated
24383 by either a space or null character (for an object-like macro) or
24384 an opening paren (for a function-like macro). */
24385 for (p
= body
; *p
; p
++)
24386 if (*p
== ' ' || *p
== '(')
24389 if (*p
== ' ' || *p
== '\0')
24391 /* It's an object-like macro. */
24392 int name_len
= p
- body
;
24393 char *name
= savestring (body
, name_len
);
24394 const char *replacement
;
24397 replacement
= body
+ name_len
+ 1;
24400 dwarf2_macro_malformed_definition_complaint (body
);
24401 replacement
= body
+ name_len
;
24404 macro_define_object (file
, line
, name
, replacement
);
24408 else if (*p
== '(')
24410 /* It's a function-like macro. */
24411 char *name
= savestring (body
, p
- body
);
24414 char **argv
= XNEWVEC (char *, argv_size
);
24418 p
= consume_improper_spaces (p
, body
);
24420 /* Parse the formal argument list. */
24421 while (*p
&& *p
!= ')')
24423 /* Find the extent of the current argument name. */
24424 const char *arg_start
= p
;
24426 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24429 if (! *p
|| p
== arg_start
)
24430 dwarf2_macro_malformed_definition_complaint (body
);
24433 /* Make sure argv has room for the new argument. */
24434 if (argc
>= argv_size
)
24437 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24440 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24443 p
= consume_improper_spaces (p
, body
);
24445 /* Consume the comma, if present. */
24450 p
= consume_improper_spaces (p
, body
);
24459 /* Perfectly formed definition, no complaints. */
24460 macro_define_function (file
, line
, name
,
24461 argc
, (const char **) argv
,
24463 else if (*p
== '\0')
24465 /* Complain, but do define it. */
24466 dwarf2_macro_malformed_definition_complaint (body
);
24467 macro_define_function (file
, line
, name
,
24468 argc
, (const char **) argv
,
24472 /* Just complain. */
24473 dwarf2_macro_malformed_definition_complaint (body
);
24476 /* Just complain. */
24477 dwarf2_macro_malformed_definition_complaint (body
);
24483 for (i
= 0; i
< argc
; i
++)
24489 dwarf2_macro_malformed_definition_complaint (body
);
24492 /* Skip some bytes from BYTES according to the form given in FORM.
24493 Returns the new pointer. */
24495 static const gdb_byte
*
24496 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24497 enum dwarf_form form
,
24498 unsigned int offset_size
,
24499 struct dwarf2_section_info
*section
)
24501 unsigned int bytes_read
;
24505 case DW_FORM_data1
:
24510 case DW_FORM_data2
:
24514 case DW_FORM_data4
:
24518 case DW_FORM_data8
:
24522 case DW_FORM_data16
:
24526 case DW_FORM_string
:
24527 read_direct_string (abfd
, bytes
, &bytes_read
);
24528 bytes
+= bytes_read
;
24531 case DW_FORM_sec_offset
:
24533 case DW_FORM_GNU_strp_alt
:
24534 bytes
+= offset_size
;
24537 case DW_FORM_block
:
24538 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24539 bytes
+= bytes_read
;
24542 case DW_FORM_block1
:
24543 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24545 case DW_FORM_block2
:
24546 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24548 case DW_FORM_block4
:
24549 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24552 case DW_FORM_addrx
:
24553 case DW_FORM_sdata
:
24555 case DW_FORM_udata
:
24556 case DW_FORM_GNU_addr_index
:
24557 case DW_FORM_GNU_str_index
:
24558 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24561 dwarf2_section_buffer_overflow_complaint (section
);
24566 case DW_FORM_implicit_const
:
24571 complaint (_("invalid form 0x%x in `%s'"),
24572 form
, get_section_name (section
));
24580 /* A helper for dwarf_decode_macros that handles skipping an unknown
24581 opcode. Returns an updated pointer to the macro data buffer; or,
24582 on error, issues a complaint and returns NULL. */
24584 static const gdb_byte
*
24585 skip_unknown_opcode (unsigned int opcode
,
24586 const gdb_byte
**opcode_definitions
,
24587 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24589 unsigned int offset_size
,
24590 struct dwarf2_section_info
*section
)
24592 unsigned int bytes_read
, i
;
24594 const gdb_byte
*defn
;
24596 if (opcode_definitions
[opcode
] == NULL
)
24598 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24603 defn
= opcode_definitions
[opcode
];
24604 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24605 defn
+= bytes_read
;
24607 for (i
= 0; i
< arg
; ++i
)
24609 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24610 (enum dwarf_form
) defn
[i
], offset_size
,
24612 if (mac_ptr
== NULL
)
24614 /* skip_form_bytes already issued the complaint. */
24622 /* A helper function which parses the header of a macro section.
24623 If the macro section is the extended (for now called "GNU") type,
24624 then this updates *OFFSET_SIZE. Returns a pointer to just after
24625 the header, or issues a complaint and returns NULL on error. */
24627 static const gdb_byte
*
24628 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24630 const gdb_byte
*mac_ptr
,
24631 unsigned int *offset_size
,
24632 int section_is_gnu
)
24634 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24636 if (section_is_gnu
)
24638 unsigned int version
, flags
;
24640 version
= read_2_bytes (abfd
, mac_ptr
);
24641 if (version
!= 4 && version
!= 5)
24643 complaint (_("unrecognized version `%d' in .debug_macro section"),
24649 flags
= read_1_byte (abfd
, mac_ptr
);
24651 *offset_size
= (flags
& 1) ? 8 : 4;
24653 if ((flags
& 2) != 0)
24654 /* We don't need the line table offset. */
24655 mac_ptr
+= *offset_size
;
24657 /* Vendor opcode descriptions. */
24658 if ((flags
& 4) != 0)
24660 unsigned int i
, count
;
24662 count
= read_1_byte (abfd
, mac_ptr
);
24664 for (i
= 0; i
< count
; ++i
)
24666 unsigned int opcode
, bytes_read
;
24669 opcode
= read_1_byte (abfd
, mac_ptr
);
24671 opcode_definitions
[opcode
] = mac_ptr
;
24672 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24673 mac_ptr
+= bytes_read
;
24682 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24683 including DW_MACRO_import. */
24686 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24688 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24689 struct macro_source_file
*current_file
,
24690 struct line_header
*lh
,
24691 struct dwarf2_section_info
*section
,
24692 int section_is_gnu
, int section_is_dwz
,
24693 unsigned int offset_size
,
24694 htab_t include_hash
)
24696 struct dwarf2_per_objfile
*dwarf2_per_objfile
24697 = cu
->per_cu
->dwarf2_per_objfile
;
24698 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24699 enum dwarf_macro_record_type macinfo_type
;
24700 int at_commandline
;
24701 const gdb_byte
*opcode_definitions
[256];
24703 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24704 &offset_size
, section_is_gnu
);
24705 if (mac_ptr
== NULL
)
24707 /* We already issued a complaint. */
24711 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24712 GDB is still reading the definitions from command line. First
24713 DW_MACINFO_start_file will need to be ignored as it was already executed
24714 to create CURRENT_FILE for the main source holding also the command line
24715 definitions. On first met DW_MACINFO_start_file this flag is reset to
24716 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24718 at_commandline
= 1;
24722 /* Do we at least have room for a macinfo type byte? */
24723 if (mac_ptr
>= mac_end
)
24725 dwarf2_section_buffer_overflow_complaint (section
);
24729 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24732 /* Note that we rely on the fact that the corresponding GNU and
24733 DWARF constants are the same. */
24735 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24736 switch (macinfo_type
)
24738 /* A zero macinfo type indicates the end of the macro
24743 case DW_MACRO_define
:
24744 case DW_MACRO_undef
:
24745 case DW_MACRO_define_strp
:
24746 case DW_MACRO_undef_strp
:
24747 case DW_MACRO_define_sup
:
24748 case DW_MACRO_undef_sup
:
24750 unsigned int bytes_read
;
24755 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24756 mac_ptr
+= bytes_read
;
24758 if (macinfo_type
== DW_MACRO_define
24759 || macinfo_type
== DW_MACRO_undef
)
24761 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24762 mac_ptr
+= bytes_read
;
24766 LONGEST str_offset
;
24768 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24769 mac_ptr
+= offset_size
;
24771 if (macinfo_type
== DW_MACRO_define_sup
24772 || macinfo_type
== DW_MACRO_undef_sup
24775 struct dwz_file
*dwz
24776 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24778 body
= read_indirect_string_from_dwz (objfile
,
24782 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24786 is_define
= (macinfo_type
== DW_MACRO_define
24787 || macinfo_type
== DW_MACRO_define_strp
24788 || macinfo_type
== DW_MACRO_define_sup
);
24789 if (! current_file
)
24791 /* DWARF violation as no main source is present. */
24792 complaint (_("debug info with no main source gives macro %s "
24794 is_define
? _("definition") : _("undefinition"),
24798 if ((line
== 0 && !at_commandline
)
24799 || (line
!= 0 && at_commandline
))
24800 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
24801 at_commandline
? _("command-line") : _("in-file"),
24802 is_define
? _("definition") : _("undefinition"),
24803 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24807 /* Fedora's rpm-build's "debugedit" binary
24808 corrupted .debug_macro sections.
24811 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
24812 complaint (_("debug info gives %s invalid macro %s "
24813 "without body (corrupted?) at line %d "
24815 at_commandline
? _("command-line") : _("in-file"),
24816 is_define
? _("definition") : _("undefinition"),
24817 line
, current_file
->filename
);
24819 else if (is_define
)
24820 parse_macro_definition (current_file
, line
, body
);
24823 gdb_assert (macinfo_type
== DW_MACRO_undef
24824 || macinfo_type
== DW_MACRO_undef_strp
24825 || macinfo_type
== DW_MACRO_undef_sup
);
24826 macro_undef (current_file
, line
, body
);
24831 case DW_MACRO_start_file
:
24833 unsigned int bytes_read
;
24836 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24837 mac_ptr
+= bytes_read
;
24838 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24839 mac_ptr
+= bytes_read
;
24841 if ((line
== 0 && !at_commandline
)
24842 || (line
!= 0 && at_commandline
))
24843 complaint (_("debug info gives source %d included "
24844 "from %s at %s line %d"),
24845 file
, at_commandline
? _("command-line") : _("file"),
24846 line
== 0 ? _("zero") : _("non-zero"), line
);
24848 if (at_commandline
)
24850 /* This DW_MACRO_start_file was executed in the
24852 at_commandline
= 0;
24855 current_file
= macro_start_file (cu
, file
, line
, current_file
,
24860 case DW_MACRO_end_file
:
24861 if (! current_file
)
24862 complaint (_("macro debug info has an unmatched "
24863 "`close_file' directive"));
24866 current_file
= current_file
->included_by
;
24867 if (! current_file
)
24869 enum dwarf_macro_record_type next_type
;
24871 /* GCC circa March 2002 doesn't produce the zero
24872 type byte marking the end of the compilation
24873 unit. Complain if it's not there, but exit no
24876 /* Do we at least have room for a macinfo type byte? */
24877 if (mac_ptr
>= mac_end
)
24879 dwarf2_section_buffer_overflow_complaint (section
);
24883 /* We don't increment mac_ptr here, so this is just
24886 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24888 if (next_type
!= 0)
24889 complaint (_("no terminating 0-type entry for "
24890 "macros in `.debug_macinfo' section"));
24897 case DW_MACRO_import
:
24898 case DW_MACRO_import_sup
:
24902 bfd
*include_bfd
= abfd
;
24903 struct dwarf2_section_info
*include_section
= section
;
24904 const gdb_byte
*include_mac_end
= mac_end
;
24905 int is_dwz
= section_is_dwz
;
24906 const gdb_byte
*new_mac_ptr
;
24908 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24909 mac_ptr
+= offset_size
;
24911 if (macinfo_type
== DW_MACRO_import_sup
)
24913 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24915 dwarf2_read_section (objfile
, &dwz
->macro
);
24917 include_section
= &dwz
->macro
;
24918 include_bfd
= get_section_bfd_owner (include_section
);
24919 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24923 new_mac_ptr
= include_section
->buffer
+ offset
;
24924 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24928 /* This has actually happened; see
24929 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24930 complaint (_("recursive DW_MACRO_import in "
24931 ".debug_macro section"));
24935 *slot
= (void *) new_mac_ptr
;
24937 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
24938 include_mac_end
, current_file
, lh
,
24939 section
, section_is_gnu
, is_dwz
,
24940 offset_size
, include_hash
);
24942 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24947 case DW_MACINFO_vendor_ext
:
24948 if (!section_is_gnu
)
24950 unsigned int bytes_read
;
24952 /* This reads the constant, but since we don't recognize
24953 any vendor extensions, we ignore it. */
24954 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24955 mac_ptr
+= bytes_read
;
24956 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24957 mac_ptr
+= bytes_read
;
24959 /* We don't recognize any vendor extensions. */
24965 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24966 mac_ptr
, mac_end
, abfd
, offset_size
,
24968 if (mac_ptr
== NULL
)
24973 } while (macinfo_type
!= 0);
24977 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24978 int section_is_gnu
)
24980 struct dwarf2_per_objfile
*dwarf2_per_objfile
24981 = cu
->per_cu
->dwarf2_per_objfile
;
24982 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24983 struct line_header
*lh
= cu
->line_header
;
24985 const gdb_byte
*mac_ptr
, *mac_end
;
24986 struct macro_source_file
*current_file
= 0;
24987 enum dwarf_macro_record_type macinfo_type
;
24988 unsigned int offset_size
= cu
->header
.offset_size
;
24989 const gdb_byte
*opcode_definitions
[256];
24991 struct dwarf2_section_info
*section
;
24992 const char *section_name
;
24994 if (cu
->dwo_unit
!= NULL
)
24996 if (section_is_gnu
)
24998 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24999 section_name
= ".debug_macro.dwo";
25003 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
25004 section_name
= ".debug_macinfo.dwo";
25009 if (section_is_gnu
)
25011 section
= &dwarf2_per_objfile
->macro
;
25012 section_name
= ".debug_macro";
25016 section
= &dwarf2_per_objfile
->macinfo
;
25017 section_name
= ".debug_macinfo";
25021 dwarf2_read_section (objfile
, section
);
25022 if (section
->buffer
== NULL
)
25024 complaint (_("missing %s section"), section_name
);
25027 abfd
= get_section_bfd_owner (section
);
25029 /* First pass: Find the name of the base filename.
25030 This filename is needed in order to process all macros whose definition
25031 (or undefinition) comes from the command line. These macros are defined
25032 before the first DW_MACINFO_start_file entry, and yet still need to be
25033 associated to the base file.
25035 To determine the base file name, we scan the macro definitions until we
25036 reach the first DW_MACINFO_start_file entry. We then initialize
25037 CURRENT_FILE accordingly so that any macro definition found before the
25038 first DW_MACINFO_start_file can still be associated to the base file. */
25040 mac_ptr
= section
->buffer
+ offset
;
25041 mac_end
= section
->buffer
+ section
->size
;
25043 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
25044 &offset_size
, section_is_gnu
);
25045 if (mac_ptr
== NULL
)
25047 /* We already issued a complaint. */
25053 /* Do we at least have room for a macinfo type byte? */
25054 if (mac_ptr
>= mac_end
)
25056 /* Complaint is printed during the second pass as GDB will probably
25057 stop the first pass earlier upon finding
25058 DW_MACINFO_start_file. */
25062 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25065 /* Note that we rely on the fact that the corresponding GNU and
25066 DWARF constants are the same. */
25068 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25069 switch (macinfo_type
)
25071 /* A zero macinfo type indicates the end of the macro
25076 case DW_MACRO_define
:
25077 case DW_MACRO_undef
:
25078 /* Only skip the data by MAC_PTR. */
25080 unsigned int bytes_read
;
25082 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25083 mac_ptr
+= bytes_read
;
25084 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25085 mac_ptr
+= bytes_read
;
25089 case DW_MACRO_start_file
:
25091 unsigned int bytes_read
;
25094 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25095 mac_ptr
+= bytes_read
;
25096 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25097 mac_ptr
+= bytes_read
;
25099 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
25103 case DW_MACRO_end_file
:
25104 /* No data to skip by MAC_PTR. */
25107 case DW_MACRO_define_strp
:
25108 case DW_MACRO_undef_strp
:
25109 case DW_MACRO_define_sup
:
25110 case DW_MACRO_undef_sup
:
25112 unsigned int bytes_read
;
25114 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25115 mac_ptr
+= bytes_read
;
25116 mac_ptr
+= offset_size
;
25120 case DW_MACRO_import
:
25121 case DW_MACRO_import_sup
:
25122 /* Note that, according to the spec, a transparent include
25123 chain cannot call DW_MACRO_start_file. So, we can just
25124 skip this opcode. */
25125 mac_ptr
+= offset_size
;
25128 case DW_MACINFO_vendor_ext
:
25129 /* Only skip the data by MAC_PTR. */
25130 if (!section_is_gnu
)
25132 unsigned int bytes_read
;
25134 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25135 mac_ptr
+= bytes_read
;
25136 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25137 mac_ptr
+= bytes_read
;
25142 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25143 mac_ptr
, mac_end
, abfd
, offset_size
,
25145 if (mac_ptr
== NULL
)
25150 } while (macinfo_type
!= 0 && current_file
== NULL
);
25152 /* Second pass: Process all entries.
25154 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25155 command-line macro definitions/undefinitions. This flag is unset when we
25156 reach the first DW_MACINFO_start_file entry. */
25158 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25160 NULL
, xcalloc
, xfree
));
25161 mac_ptr
= section
->buffer
+ offset
;
25162 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25163 *slot
= (void *) mac_ptr
;
25164 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
25165 current_file
, lh
, section
,
25166 section_is_gnu
, 0, offset_size
,
25167 include_hash
.get ());
25170 /* Check if the attribute's form is a DW_FORM_block*
25171 if so return true else false. */
25174 attr_form_is_block (const struct attribute
*attr
)
25176 return (attr
== NULL
? 0 :
25177 attr
->form
== DW_FORM_block1
25178 || attr
->form
== DW_FORM_block2
25179 || attr
->form
== DW_FORM_block4
25180 || attr
->form
== DW_FORM_block
25181 || attr
->form
== DW_FORM_exprloc
);
25184 /* Return non-zero if ATTR's value is a section offset --- classes
25185 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25186 You may use DW_UNSND (attr) to retrieve such offsets.
25188 Section 7.5.4, "Attribute Encodings", explains that no attribute
25189 may have a value that belongs to more than one of these classes; it
25190 would be ambiguous if we did, because we use the same forms for all
25194 attr_form_is_section_offset (const struct attribute
*attr
)
25196 return (attr
->form
== DW_FORM_data4
25197 || attr
->form
== DW_FORM_data8
25198 || attr
->form
== DW_FORM_sec_offset
);
25201 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25202 zero otherwise. When this function returns true, you can apply
25203 dwarf2_get_attr_constant_value to it.
25205 However, note that for some attributes you must check
25206 attr_form_is_section_offset before using this test. DW_FORM_data4
25207 and DW_FORM_data8 are members of both the constant class, and of
25208 the classes that contain offsets into other debug sections
25209 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25210 that, if an attribute's can be either a constant or one of the
25211 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25212 taken as section offsets, not constants.
25214 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25215 cannot handle that. */
25218 attr_form_is_constant (const struct attribute
*attr
)
25220 switch (attr
->form
)
25222 case DW_FORM_sdata
:
25223 case DW_FORM_udata
:
25224 case DW_FORM_data1
:
25225 case DW_FORM_data2
:
25226 case DW_FORM_data4
:
25227 case DW_FORM_data8
:
25228 case DW_FORM_implicit_const
:
25236 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25237 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25240 attr_form_is_ref (const struct attribute
*attr
)
25242 switch (attr
->form
)
25244 case DW_FORM_ref_addr
:
25249 case DW_FORM_ref_udata
:
25250 case DW_FORM_GNU_ref_alt
:
25257 /* Return the .debug_loc section to use for CU.
25258 For DWO files use .debug_loc.dwo. */
25260 static struct dwarf2_section_info
*
25261 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25263 struct dwarf2_per_objfile
*dwarf2_per_objfile
25264 = cu
->per_cu
->dwarf2_per_objfile
;
25268 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25270 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25272 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25273 : &dwarf2_per_objfile
->loc
);
25276 /* A helper function that fills in a dwarf2_loclist_baton. */
25279 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25280 struct dwarf2_loclist_baton
*baton
,
25281 const struct attribute
*attr
)
25283 struct dwarf2_per_objfile
*dwarf2_per_objfile
25284 = cu
->per_cu
->dwarf2_per_objfile
;
25285 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25287 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25289 baton
->per_cu
= cu
->per_cu
;
25290 gdb_assert (baton
->per_cu
);
25291 /* We don't know how long the location list is, but make sure we
25292 don't run off the edge of the section. */
25293 baton
->size
= section
->size
- DW_UNSND (attr
);
25294 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25295 baton
->base_address
= cu
->base_address
;
25296 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25300 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25301 struct dwarf2_cu
*cu
, int is_block
)
25303 struct dwarf2_per_objfile
*dwarf2_per_objfile
25304 = cu
->per_cu
->dwarf2_per_objfile
;
25305 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25306 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25308 if (attr_form_is_section_offset (attr
)
25309 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25310 the section. If so, fall through to the complaint in the
25312 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25314 struct dwarf2_loclist_baton
*baton
;
25316 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25318 fill_in_loclist_baton (cu
, baton
, attr
);
25320 if (cu
->base_known
== 0)
25321 complaint (_("Location list used without "
25322 "specifying the CU base address."));
25324 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25325 ? dwarf2_loclist_block_index
25326 : dwarf2_loclist_index
);
25327 SYMBOL_LOCATION_BATON (sym
) = baton
;
25331 struct dwarf2_locexpr_baton
*baton
;
25333 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25334 baton
->per_cu
= cu
->per_cu
;
25335 gdb_assert (baton
->per_cu
);
25337 if (attr_form_is_block (attr
))
25339 /* Note that we're just copying the block's data pointer
25340 here, not the actual data. We're still pointing into the
25341 info_buffer for SYM's objfile; right now we never release
25342 that buffer, but when we do clean up properly this may
25344 baton
->size
= DW_BLOCK (attr
)->size
;
25345 baton
->data
= DW_BLOCK (attr
)->data
;
25349 dwarf2_invalid_attrib_class_complaint ("location description",
25350 sym
->natural_name ());
25354 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25355 ? dwarf2_locexpr_block_index
25356 : dwarf2_locexpr_index
);
25357 SYMBOL_LOCATION_BATON (sym
) = baton
;
25361 /* Return the OBJFILE associated with the compilation unit CU. If CU
25362 came from a separate debuginfo file, then the master objfile is
25366 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25368 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25370 /* Return the master objfile, so that we can report and look up the
25371 correct file containing this variable. */
25372 if (objfile
->separate_debug_objfile_backlink
)
25373 objfile
= objfile
->separate_debug_objfile_backlink
;
25378 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25379 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25380 CU_HEADERP first. */
25382 static const struct comp_unit_head
*
25383 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25384 struct dwarf2_per_cu_data
*per_cu
)
25386 const gdb_byte
*info_ptr
;
25389 return &per_cu
->cu
->header
;
25391 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25393 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25394 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25395 rcuh_kind::COMPILE
);
25400 /* Return the address size given in the compilation unit header for CU. */
25403 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25405 struct comp_unit_head cu_header_local
;
25406 const struct comp_unit_head
*cu_headerp
;
25408 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25410 return cu_headerp
->addr_size
;
25413 /* Return the offset size given in the compilation unit header for CU. */
25416 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25418 struct comp_unit_head cu_header_local
;
25419 const struct comp_unit_head
*cu_headerp
;
25421 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25423 return cu_headerp
->offset_size
;
25426 /* See its dwarf2loc.h declaration. */
25429 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25431 struct comp_unit_head cu_header_local
;
25432 const struct comp_unit_head
*cu_headerp
;
25434 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25436 if (cu_headerp
->version
== 2)
25437 return cu_headerp
->addr_size
;
25439 return cu_headerp
->offset_size
;
25442 /* Return the text offset of the CU. The returned offset comes from
25443 this CU's objfile. If this objfile came from a separate debuginfo
25444 file, then the offset may be different from the corresponding
25445 offset in the parent objfile. */
25448 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25450 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25452 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25455 /* Return a type that is a generic pointer type, the size of which matches
25456 the address size given in the compilation unit header for PER_CU. */
25457 static struct type
*
25458 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25460 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25461 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25462 struct type
*addr_type
= lookup_pointer_type (void_type
);
25463 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25465 if (TYPE_LENGTH (addr_type
) == addr_size
)
25469 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25473 /* Return DWARF version number of PER_CU. */
25476 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25478 return per_cu
->dwarf_version
;
25481 /* Locate the .debug_info compilation unit from CU's objfile which contains
25482 the DIE at OFFSET. Raises an error on failure. */
25484 static struct dwarf2_per_cu_data
*
25485 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25486 unsigned int offset_in_dwz
,
25487 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25489 struct dwarf2_per_cu_data
*this_cu
;
25493 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25496 struct dwarf2_per_cu_data
*mid_cu
;
25497 int mid
= low
+ (high
- low
) / 2;
25499 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25500 if (mid_cu
->is_dwz
> offset_in_dwz
25501 || (mid_cu
->is_dwz
== offset_in_dwz
25502 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25507 gdb_assert (low
== high
);
25508 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25509 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25511 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25512 error (_("Dwarf Error: could not find partial DIE containing "
25513 "offset %s [in module %s]"),
25514 sect_offset_str (sect_off
),
25515 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25517 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25519 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25523 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25524 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25525 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25526 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25531 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25533 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25534 : per_cu (per_cu_
),
25536 has_loclist (false),
25537 checked_producer (false),
25538 producer_is_gxx_lt_4_6 (false),
25539 producer_is_gcc_lt_4_3 (false),
25540 producer_is_icc (false),
25541 producer_is_icc_lt_14 (false),
25542 producer_is_codewarrior (false),
25543 processing_has_namespace_info (false)
25548 /* Destroy a dwarf2_cu. */
25550 dwarf2_cu::~dwarf2_cu ()
25555 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25558 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25559 enum language pretend_language
)
25561 struct attribute
*attr
;
25563 /* Set the language we're debugging. */
25564 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25565 if (attr
!= nullptr)
25566 set_cu_language (DW_UNSND (attr
), cu
);
25569 cu
->language
= pretend_language
;
25570 cu
->language_defn
= language_def (cu
->language
);
25573 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25576 /* Increase the age counter on each cached compilation unit, and free
25577 any that are too old. */
25580 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25582 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25584 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25585 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25586 while (per_cu
!= NULL
)
25588 per_cu
->cu
->last_used
++;
25589 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25590 dwarf2_mark (per_cu
->cu
);
25591 per_cu
= per_cu
->cu
->read_in_chain
;
25594 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25595 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25596 while (per_cu
!= NULL
)
25598 struct dwarf2_per_cu_data
*next_cu
;
25600 next_cu
= per_cu
->cu
->read_in_chain
;
25602 if (!per_cu
->cu
->mark
)
25605 *last_chain
= next_cu
;
25608 last_chain
= &per_cu
->cu
->read_in_chain
;
25614 /* Remove a single compilation unit from the cache. */
25617 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25619 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25620 struct dwarf2_per_objfile
*dwarf2_per_objfile
25621 = target_per_cu
->dwarf2_per_objfile
;
25623 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25624 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25625 while (per_cu
!= NULL
)
25627 struct dwarf2_per_cu_data
*next_cu
;
25629 next_cu
= per_cu
->cu
->read_in_chain
;
25631 if (per_cu
== target_per_cu
)
25635 *last_chain
= next_cu
;
25639 last_chain
= &per_cu
->cu
->read_in_chain
;
25645 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25646 We store these in a hash table separate from the DIEs, and preserve them
25647 when the DIEs are flushed out of cache.
25649 The CU "per_cu" pointer is needed because offset alone is not enough to
25650 uniquely identify the type. A file may have multiple .debug_types sections,
25651 or the type may come from a DWO file. Furthermore, while it's more logical
25652 to use per_cu->section+offset, with Fission the section with the data is in
25653 the DWO file but we don't know that section at the point we need it.
25654 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25655 because we can enter the lookup routine, get_die_type_at_offset, from
25656 outside this file, and thus won't necessarily have PER_CU->cu.
25657 Fortunately, PER_CU is stable for the life of the objfile. */
25659 struct dwarf2_per_cu_offset_and_type
25661 const struct dwarf2_per_cu_data
*per_cu
;
25662 sect_offset sect_off
;
25666 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25669 per_cu_offset_and_type_hash (const void *item
)
25671 const struct dwarf2_per_cu_offset_and_type
*ofs
25672 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25674 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25677 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25680 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25682 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25683 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25684 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25685 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25687 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25688 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25691 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25692 table if necessary. For convenience, return TYPE.
25694 The DIEs reading must have careful ordering to:
25695 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25696 reading current DIE.
25697 * Not trying to dereference contents of still incompletely read in types
25698 while reading in other DIEs.
25699 * Enable referencing still incompletely read in types just by a pointer to
25700 the type without accessing its fields.
25702 Therefore caller should follow these rules:
25703 * Try to fetch any prerequisite types we may need to build this DIE type
25704 before building the type and calling set_die_type.
25705 * After building type call set_die_type for current DIE as soon as
25706 possible before fetching more types to complete the current type.
25707 * Make the type as complete as possible before fetching more types. */
25709 static struct type
*
25710 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25712 struct dwarf2_per_objfile
*dwarf2_per_objfile
25713 = cu
->per_cu
->dwarf2_per_objfile
;
25714 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25715 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25716 struct attribute
*attr
;
25717 struct dynamic_prop prop
;
25719 /* For Ada types, make sure that the gnat-specific data is always
25720 initialized (if not already set). There are a few types where
25721 we should not be doing so, because the type-specific area is
25722 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25723 where the type-specific area is used to store the floatformat).
25724 But this is not a problem, because the gnat-specific information
25725 is actually not needed for these types. */
25726 if (need_gnat_info (cu
)
25727 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25728 && TYPE_CODE (type
) != TYPE_CODE_FLT
25729 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25730 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25731 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25732 && !HAVE_GNAT_AUX_INFO (type
))
25733 INIT_GNAT_SPECIFIC (type
);
25735 /* Read DW_AT_allocated and set in type. */
25736 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25737 if (attr_form_is_block (attr
))
25739 struct type
*prop_type
25740 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25741 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25742 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25744 else if (attr
!= NULL
)
25746 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25747 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25748 sect_offset_str (die
->sect_off
));
25751 /* Read DW_AT_associated and set in type. */
25752 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25753 if (attr_form_is_block (attr
))
25755 struct type
*prop_type
25756 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25757 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25758 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25760 else if (attr
!= NULL
)
25762 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25763 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25764 sect_offset_str (die
->sect_off
));
25767 /* Read DW_AT_data_location and set in type. */
25768 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25769 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25770 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25771 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25773 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25775 dwarf2_per_objfile
->die_type_hash
=
25776 htab_create_alloc_ex (127,
25777 per_cu_offset_and_type_hash
,
25778 per_cu_offset_and_type_eq
,
25780 &objfile
->objfile_obstack
,
25781 hashtab_obstack_allocate
,
25782 dummy_obstack_deallocate
);
25785 ofs
.per_cu
= cu
->per_cu
;
25786 ofs
.sect_off
= die
->sect_off
;
25788 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25789 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25791 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25792 sect_offset_str (die
->sect_off
));
25793 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25794 struct dwarf2_per_cu_offset_and_type
);
25799 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25800 or return NULL if the die does not have a saved type. */
25802 static struct type
*
25803 get_die_type_at_offset (sect_offset sect_off
,
25804 struct dwarf2_per_cu_data
*per_cu
)
25806 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25807 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25809 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25812 ofs
.per_cu
= per_cu
;
25813 ofs
.sect_off
= sect_off
;
25814 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25815 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25822 /* Look up the type for DIE in CU in die_type_hash,
25823 or return NULL if DIE does not have a saved type. */
25825 static struct type
*
25826 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25828 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25831 /* Add a dependence relationship from CU to REF_PER_CU. */
25834 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25835 struct dwarf2_per_cu_data
*ref_per_cu
)
25839 if (cu
->dependencies
== NULL
)
25841 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25842 NULL
, &cu
->comp_unit_obstack
,
25843 hashtab_obstack_allocate
,
25844 dummy_obstack_deallocate
);
25846 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25848 *slot
= ref_per_cu
;
25851 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25852 Set the mark field in every compilation unit in the
25853 cache that we must keep because we are keeping CU. */
25856 dwarf2_mark_helper (void **slot
, void *data
)
25858 struct dwarf2_per_cu_data
*per_cu
;
25860 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25862 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25863 reading of the chain. As such dependencies remain valid it is not much
25864 useful to track and undo them during QUIT cleanups. */
25865 if (per_cu
->cu
== NULL
)
25868 if (per_cu
->cu
->mark
)
25870 per_cu
->cu
->mark
= true;
25872 if (per_cu
->cu
->dependencies
!= NULL
)
25873 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25878 /* Set the mark field in CU and in every other compilation unit in the
25879 cache that we must keep because we are keeping CU. */
25882 dwarf2_mark (struct dwarf2_cu
*cu
)
25887 if (cu
->dependencies
!= NULL
)
25888 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25892 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25896 per_cu
->cu
->mark
= false;
25897 per_cu
= per_cu
->cu
->read_in_chain
;
25901 /* Trivial hash function for partial_die_info: the hash value of a DIE
25902 is its offset in .debug_info for this objfile. */
25905 partial_die_hash (const void *item
)
25907 const struct partial_die_info
*part_die
25908 = (const struct partial_die_info
*) item
;
25910 return to_underlying (part_die
->sect_off
);
25913 /* Trivial comparison function for partial_die_info structures: two DIEs
25914 are equal if they have the same offset. */
25917 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25919 const struct partial_die_info
*part_die_lhs
25920 = (const struct partial_die_info
*) item_lhs
;
25921 const struct partial_die_info
*part_die_rhs
25922 = (const struct partial_die_info
*) item_rhs
;
25924 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25927 struct cmd_list_element
*set_dwarf_cmdlist
;
25928 struct cmd_list_element
*show_dwarf_cmdlist
;
25931 set_dwarf_cmd (const char *args
, int from_tty
)
25933 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25938 show_dwarf_cmd (const char *args
, int from_tty
)
25940 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25943 bool dwarf_always_disassemble
;
25946 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
25947 struct cmd_list_element
*c
, const char *value
)
25949 fprintf_filtered (file
,
25950 _("Whether to always disassemble "
25951 "DWARF expressions is %s.\n"),
25956 show_check_physname (struct ui_file
*file
, int from_tty
,
25957 struct cmd_list_element
*c
, const char *value
)
25959 fprintf_filtered (file
,
25960 _("Whether to check \"physname\" is %s.\n"),
25965 _initialize_dwarf2_read (void)
25967 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
25968 Set DWARF specific variables.\n\
25969 Configure DWARF variables such as the cache size."),
25970 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25971 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25973 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
25974 Show DWARF specific variables.\n\
25975 Show DWARF variables such as the cache size."),
25976 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25977 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25979 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25980 &dwarf_max_cache_age
, _("\
25981 Set the upper bound on the age of cached DWARF compilation units."), _("\
25982 Show the upper bound on the age of cached DWARF compilation units."), _("\
25983 A higher limit means that cached compilation units will be stored\n\
25984 in memory longer, and more total memory will be used. Zero disables\n\
25985 caching, which can slow down startup."),
25987 show_dwarf_max_cache_age
,
25988 &set_dwarf_cmdlist
,
25989 &show_dwarf_cmdlist
);
25991 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
25992 &dwarf_always_disassemble
, _("\
25993 Set whether `info address' always disassembles DWARF expressions."), _("\
25994 Show whether `info address' always disassembles DWARF expressions."), _("\
25995 When enabled, DWARF expressions are always printed in an assembly-like\n\
25996 syntax. When disabled, expressions will be printed in a more\n\
25997 conversational style, when possible."),
25999 show_dwarf_always_disassemble
,
26000 &set_dwarf_cmdlist
,
26001 &show_dwarf_cmdlist
);
26003 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
26004 Set debugging of the DWARF reader."), _("\
26005 Show debugging of the DWARF reader."), _("\
26006 When enabled (non-zero), debugging messages are printed during DWARF\n\
26007 reading and symtab expansion. A value of 1 (one) provides basic\n\
26008 information. A value greater than 1 provides more verbose information."),
26011 &setdebuglist
, &showdebuglist
);
26013 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
26014 Set debugging of the DWARF DIE reader."), _("\
26015 Show debugging of the DWARF DIE reader."), _("\
26016 When enabled (non-zero), DIEs are dumped after they are read in.\n\
26017 The value is the maximum depth to print."),
26020 &setdebuglist
, &showdebuglist
);
26022 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
26023 Set debugging of the dwarf line reader."), _("\
26024 Show debugging of the dwarf line reader."), _("\
26025 When enabled (non-zero), line number entries are dumped as they are read in.\n\
26026 A value of 1 (one) provides basic information.\n\
26027 A value greater than 1 provides more verbose information."),
26030 &setdebuglist
, &showdebuglist
);
26032 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
26033 Set cross-checking of \"physname\" code against demangler."), _("\
26034 Show cross-checking of \"physname\" code against demangler."), _("\
26035 When enabled, GDB's internal \"physname\" code is checked against\n\
26037 NULL
, show_check_physname
,
26038 &setdebuglist
, &showdebuglist
);
26040 add_setshow_boolean_cmd ("use-deprecated-index-sections",
26041 no_class
, &use_deprecated_index_sections
, _("\
26042 Set whether to use deprecated gdb_index sections."), _("\
26043 Show whether to use deprecated gdb_index sections."), _("\
26044 When enabled, deprecated .gdb_index sections are used anyway.\n\
26045 Normally they are ignored either because of a missing feature or\n\
26046 performance issue.\n\
26047 Warning: This option must be enabled before gdb reads the file."),
26050 &setlist
, &showlist
);
26052 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26053 &dwarf2_locexpr_funcs
);
26054 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26055 &dwarf2_loclist_funcs
);
26057 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26058 &dwarf2_block_frame_base_locexpr_funcs
);
26059 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26060 &dwarf2_block_frame_base_loclist_funcs
);
26063 selftests::register_test ("dw2_expand_symtabs_matching",
26064 selftests::dw2_expand_symtabs_matching::run_test
);