1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit.h"
36 #include "dwarf2/index-cache.h"
37 #include "dwarf2/index-common.h"
38 #include "dwarf2/leb.h"
39 #include "dwarf2/line-header.h"
48 #include "gdb-demangle.h"
49 #include "filenames.h" /* for DOSish file names */
52 #include "complaints.h"
53 #include "dwarf2/expr.h"
54 #include "dwarf2/loc.h"
55 #include "cp-support.h"
61 #include "typeprint.h"
66 #include "gdbcore.h" /* for gnutarget */
67 #include "gdb/gdb-index.h"
72 #include "namespace.h"
73 #include "gdbsupport/function-view.h"
74 #include "gdbsupport/gdb_optional.h"
75 #include "gdbsupport/underlying.h"
76 #include "gdbsupport/hash_enum.h"
77 #include "filename-seen-cache.h"
81 #include <unordered_map>
82 #include "gdbsupport/selftest.h"
83 #include "rust-lang.h"
84 #include "gdbsupport/pathstuff.h"
86 /* When == 1, print basic high level tracing messages.
87 When > 1, be more verbose.
88 This is in contrast to the low level DIE reading of dwarf_die_debug. */
89 static unsigned int dwarf_read_debug
= 0;
91 /* When non-zero, dump DIEs after they are read in. */
92 static unsigned int dwarf_die_debug
= 0;
94 /* When non-zero, dump line number entries as they are read in. */
95 unsigned int dwarf_line_debug
= 0;
97 /* When true, cross-check physname against demangler. */
98 static bool check_physname
= false;
100 /* When true, do not reject deprecated .gdb_index sections. */
101 static bool use_deprecated_index_sections
= false;
103 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
105 /* The "aclass" indices for various kinds of computed DWARF symbols. */
107 static int dwarf2_locexpr_index
;
108 static int dwarf2_loclist_index
;
109 static int dwarf2_locexpr_block_index
;
110 static int dwarf2_loclist_block_index
;
112 /* An index into a (C++) symbol name component in a symbol name as
113 recorded in the mapped_index's symbol table. For each C++ symbol
114 in the symbol table, we record one entry for the start of each
115 component in the symbol in a table of name components, and then
116 sort the table, in order to be able to binary search symbol names,
117 ignoring leading namespaces, both completion and regular look up.
118 For example, for symbol "A::B::C", we'll have an entry that points
119 to "A::B::C", another that points to "B::C", and another for "C".
120 Note that function symbols in GDB index have no parameter
121 information, just the function/method names. You can convert a
122 name_component to a "const char *" using the
123 'mapped_index::symbol_name_at(offset_type)' method. */
125 struct name_component
127 /* Offset in the symbol name where the component starts. Stored as
128 a (32-bit) offset instead of a pointer to save memory and improve
129 locality on 64-bit architectures. */
130 offset_type name_offset
;
132 /* The symbol's index in the symbol and constant pool tables of a
137 /* Base class containing bits shared by both .gdb_index and
138 .debug_name indexes. */
140 struct mapped_index_base
142 mapped_index_base () = default;
143 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
145 /* The name_component table (a sorted vector). See name_component's
146 description above. */
147 std::vector
<name_component
> name_components
;
149 /* How NAME_COMPONENTS is sorted. */
150 enum case_sensitivity name_components_casing
;
152 /* Return the number of names in the symbol table. */
153 virtual size_t symbol_name_count () const = 0;
155 /* Get the name of the symbol at IDX in the symbol table. */
156 virtual const char *symbol_name_at (offset_type idx
) const = 0;
158 /* Return whether the name at IDX in the symbol table should be
160 virtual bool symbol_name_slot_invalid (offset_type idx
) const
165 /* Build the symbol name component sorted vector, if we haven't
167 void build_name_components ();
169 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
170 possible matches for LN_NO_PARAMS in the name component
172 std::pair
<std::vector
<name_component
>::const_iterator
,
173 std::vector
<name_component
>::const_iterator
>
174 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
175 enum language lang
) const;
177 /* Prevent deleting/destroying via a base class pointer. */
179 ~mapped_index_base() = default;
182 /* A description of the mapped index. The file format is described in
183 a comment by the code that writes the index. */
184 struct mapped_index final
: public mapped_index_base
186 /* A slot/bucket in the symbol table hash. */
187 struct symbol_table_slot
189 const offset_type name
;
190 const offset_type vec
;
193 /* Index data format version. */
196 /* The address table data. */
197 gdb::array_view
<const gdb_byte
> address_table
;
199 /* The symbol table, implemented as a hash table. */
200 gdb::array_view
<symbol_table_slot
> symbol_table
;
202 /* A pointer to the constant pool. */
203 const char *constant_pool
= nullptr;
205 bool symbol_name_slot_invalid (offset_type idx
) const override
207 const auto &bucket
= this->symbol_table
[idx
];
208 return bucket
.name
== 0 && bucket
.vec
== 0;
211 /* Convenience method to get at the name of the symbol at IDX in the
213 const char *symbol_name_at (offset_type idx
) const override
214 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
216 size_t symbol_name_count () const override
217 { return this->symbol_table
.size (); }
220 /* A description of the mapped .debug_names.
221 Uninitialized map has CU_COUNT 0. */
222 struct mapped_debug_names final
: public mapped_index_base
224 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
225 : dwarf2_per_objfile (dwarf2_per_objfile_
)
228 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
229 bfd_endian dwarf5_byte_order
;
230 bool dwarf5_is_dwarf64
;
231 bool augmentation_is_gdb
;
233 uint32_t cu_count
= 0;
234 uint32_t tu_count
, bucket_count
, name_count
;
235 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
236 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
237 const gdb_byte
*name_table_string_offs_reordered
;
238 const gdb_byte
*name_table_entry_offs_reordered
;
239 const gdb_byte
*entry_pool
;
246 /* Attribute name DW_IDX_*. */
249 /* Attribute form DW_FORM_*. */
252 /* Value if FORM is DW_FORM_implicit_const. */
253 LONGEST implicit_const
;
255 std::vector
<attr
> attr_vec
;
258 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
260 const char *namei_to_name (uint32_t namei
) const;
262 /* Implementation of the mapped_index_base virtual interface, for
263 the name_components cache. */
265 const char *symbol_name_at (offset_type idx
) const override
266 { return namei_to_name (idx
); }
268 size_t symbol_name_count () const override
269 { return this->name_count
; }
272 /* See dwarf2read.h. */
275 get_dwarf2_per_objfile (struct objfile
*objfile
)
277 return dwarf2_objfile_data_key
.get (objfile
);
280 /* Default names of the debugging sections. */
282 /* Note that if the debugging section has been compressed, it might
283 have a name like .zdebug_info. */
285 static const struct dwarf2_debug_sections dwarf2_elf_names
=
287 { ".debug_info", ".zdebug_info" },
288 { ".debug_abbrev", ".zdebug_abbrev" },
289 { ".debug_line", ".zdebug_line" },
290 { ".debug_loc", ".zdebug_loc" },
291 { ".debug_loclists", ".zdebug_loclists" },
292 { ".debug_macinfo", ".zdebug_macinfo" },
293 { ".debug_macro", ".zdebug_macro" },
294 { ".debug_str", ".zdebug_str" },
295 { ".debug_str_offsets", ".zdebug_str_offsets" },
296 { ".debug_line_str", ".zdebug_line_str" },
297 { ".debug_ranges", ".zdebug_ranges" },
298 { ".debug_rnglists", ".zdebug_rnglists" },
299 { ".debug_types", ".zdebug_types" },
300 { ".debug_addr", ".zdebug_addr" },
301 { ".debug_frame", ".zdebug_frame" },
302 { ".eh_frame", NULL
},
303 { ".gdb_index", ".zgdb_index" },
304 { ".debug_names", ".zdebug_names" },
305 { ".debug_aranges", ".zdebug_aranges" },
309 /* List of DWO/DWP sections. */
311 static const struct dwop_section_names
313 struct dwarf2_section_names abbrev_dwo
;
314 struct dwarf2_section_names info_dwo
;
315 struct dwarf2_section_names line_dwo
;
316 struct dwarf2_section_names loc_dwo
;
317 struct dwarf2_section_names loclists_dwo
;
318 struct dwarf2_section_names macinfo_dwo
;
319 struct dwarf2_section_names macro_dwo
;
320 struct dwarf2_section_names str_dwo
;
321 struct dwarf2_section_names str_offsets_dwo
;
322 struct dwarf2_section_names types_dwo
;
323 struct dwarf2_section_names cu_index
;
324 struct dwarf2_section_names tu_index
;
328 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
329 { ".debug_info.dwo", ".zdebug_info.dwo" },
330 { ".debug_line.dwo", ".zdebug_line.dwo" },
331 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
332 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
333 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
334 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
335 { ".debug_str.dwo", ".zdebug_str.dwo" },
336 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
337 { ".debug_types.dwo", ".zdebug_types.dwo" },
338 { ".debug_cu_index", ".zdebug_cu_index" },
339 { ".debug_tu_index", ".zdebug_tu_index" },
342 /* local data types */
344 /* Type used for delaying computation of method physnames.
345 See comments for compute_delayed_physnames. */
346 struct delayed_method_info
348 /* The type to which the method is attached, i.e., its parent class. */
351 /* The index of the method in the type's function fieldlists. */
354 /* The index of the method in the fieldlist. */
357 /* The name of the DIE. */
360 /* The DIE associated with this method. */
361 struct die_info
*die
;
364 /* Internal state when decoding a particular compilation unit. */
367 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
370 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
372 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
373 Create the set of symtabs used by this TU, or if this TU is sharing
374 symtabs with another TU and the symtabs have already been created
375 then restore those symtabs in the line header.
376 We don't need the pc/line-number mapping for type units. */
377 void setup_type_unit_groups (struct die_info
*die
);
379 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
380 buildsym_compunit constructor. */
381 struct compunit_symtab
*start_symtab (const char *name
,
382 const char *comp_dir
,
385 /* Reset the builder. */
386 void reset_builder () { m_builder
.reset (); }
388 /* The header of the compilation unit. */
389 struct comp_unit_head header
{};
391 /* Base address of this compilation unit. */
392 CORE_ADDR base_address
= 0;
394 /* Non-zero if base_address has been set. */
397 /* The language we are debugging. */
398 enum language language
= language_unknown
;
399 const struct language_defn
*language_defn
= nullptr;
401 const char *producer
= nullptr;
404 /* The symtab builder for this CU. This is only non-NULL when full
405 symbols are being read. */
406 std::unique_ptr
<buildsym_compunit
> m_builder
;
409 /* The generic symbol table building routines have separate lists for
410 file scope symbols and all all other scopes (local scopes). So
411 we need to select the right one to pass to add_symbol_to_list().
412 We do it by keeping a pointer to the correct list in list_in_scope.
414 FIXME: The original dwarf code just treated the file scope as the
415 first local scope, and all other local scopes as nested local
416 scopes, and worked fine. Check to see if we really need to
417 distinguish these in buildsym.c. */
418 struct pending
**list_in_scope
= nullptr;
420 /* Hash table holding all the loaded partial DIEs
421 with partial_die->offset.SECT_OFF as hash. */
422 htab_t partial_dies
= nullptr;
424 /* Storage for things with the same lifetime as this read-in compilation
425 unit, including partial DIEs. */
426 auto_obstack comp_unit_obstack
;
428 /* When multiple dwarf2_cu structures are living in memory, this field
429 chains them all together, so that they can be released efficiently.
430 We will probably also want a generation counter so that most-recently-used
431 compilation units are cached... */
432 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
434 /* Backlink to our per_cu entry. */
435 struct dwarf2_per_cu_data
*per_cu
;
437 /* How many compilation units ago was this CU last referenced? */
440 /* A hash table of DIE cu_offset for following references with
441 die_info->offset.sect_off as hash. */
442 htab_t die_hash
= nullptr;
444 /* Full DIEs if read in. */
445 struct die_info
*dies
= nullptr;
447 /* A set of pointers to dwarf2_per_cu_data objects for compilation
448 units referenced by this one. Only set during full symbol processing;
449 partial symbol tables do not have dependencies. */
450 htab_t dependencies
= nullptr;
452 /* Header data from the line table, during full symbol processing. */
453 struct line_header
*line_header
= nullptr;
454 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
455 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
456 this is the DW_TAG_compile_unit die for this CU. We'll hold on
457 to the line header as long as this DIE is being processed. See
458 process_die_scope. */
459 die_info
*line_header_die_owner
= nullptr;
461 /* A list of methods which need to have physnames computed
462 after all type information has been read. */
463 std::vector
<delayed_method_info
> method_list
;
465 /* To be copied to symtab->call_site_htab. */
466 htab_t call_site_htab
= nullptr;
468 /* Non-NULL if this CU came from a DWO file.
469 There is an invariant here that is important to remember:
470 Except for attributes copied from the top level DIE in the "main"
471 (or "stub") file in preparation for reading the DWO file
472 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
473 Either there isn't a DWO file (in which case this is NULL and the point
474 is moot), or there is and either we're not going to read it (in which
475 case this is NULL) or there is and we are reading it (in which case this
477 struct dwo_unit
*dwo_unit
= nullptr;
479 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
480 Note this value comes from the Fission stub CU/TU's DIE. */
481 gdb::optional
<ULONGEST
> addr_base
;
483 /* The DW_AT_rnglists_base attribute if present.
484 Note this value comes from the Fission stub CU/TU's DIE.
485 Also note that the value is zero in the non-DWO case so this value can
486 be used without needing to know whether DWO files are in use or not.
487 N.B. This does not apply to DW_AT_ranges appearing in
488 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
489 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
490 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
491 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
492 ULONGEST ranges_base
= 0;
494 /* When reading debug info generated by older versions of rustc, we
495 have to rewrite some union types to be struct types with a
496 variant part. This rewriting must be done after the CU is fully
497 read in, because otherwise at the point of rewriting some struct
498 type might not have been fully processed. So, we keep a list of
499 all such types here and process them after expansion. */
500 std::vector
<struct type
*> rust_unions
;
502 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
503 files, the value is implicitly zero. For DWARF 5 version DWO files, the
504 value is often implicit and is the size of the header of
505 .debug_str_offsets section (8 or 4, depending on the address size). */
506 gdb::optional
<ULONGEST
> str_offsets_base
;
508 /* Mark used when releasing cached dies. */
511 /* This CU references .debug_loc. See the symtab->locations_valid field.
512 This test is imperfect as there may exist optimized debug code not using
513 any location list and still facing inlining issues if handled as
514 unoptimized code. For a future better test see GCC PR other/32998. */
515 bool has_loclist
: 1;
517 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
518 if all the producer_is_* fields are valid. This information is cached
519 because profiling CU expansion showed excessive time spent in
520 producer_is_gxx_lt_4_6. */
521 bool checked_producer
: 1;
522 bool producer_is_gxx_lt_4_6
: 1;
523 bool producer_is_gcc_lt_4_3
: 1;
524 bool producer_is_icc
: 1;
525 bool producer_is_icc_lt_14
: 1;
526 bool producer_is_codewarrior
: 1;
528 /* When true, the file that we're processing is known to have
529 debugging info for C++ namespaces. GCC 3.3.x did not produce
530 this information, but later versions do. */
532 bool processing_has_namespace_info
: 1;
534 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
536 /* If this CU was inherited by another CU (via specification,
537 abstract_origin, etc), this is the ancestor CU. */
540 /* Get the buildsym_compunit for this CU. */
541 buildsym_compunit
*get_builder ()
543 /* If this CU has a builder associated with it, use that. */
544 if (m_builder
!= nullptr)
545 return m_builder
.get ();
547 /* Otherwise, search ancestors for a valid builder. */
548 if (ancestor
!= nullptr)
549 return ancestor
->get_builder ();
555 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
556 This includes type_unit_group and quick_file_names. */
558 struct stmt_list_hash
560 /* The DWO unit this table is from or NULL if there is none. */
561 struct dwo_unit
*dwo_unit
;
563 /* Offset in .debug_line or .debug_line.dwo. */
564 sect_offset line_sect_off
;
567 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
568 an object of this type. */
570 struct type_unit_group
572 /* dwarf2read.c's main "handle" on a TU symtab.
573 To simplify things we create an artificial CU that "includes" all the
574 type units using this stmt_list so that the rest of the code still has
575 a "per_cu" handle on the symtab.
576 This PER_CU is recognized by having no section. */
577 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
578 struct dwarf2_per_cu_data per_cu
;
580 /* The TUs that share this DW_AT_stmt_list entry.
581 This is added to while parsing type units to build partial symtabs,
582 and is deleted afterwards and not used again. */
583 std::vector
<signatured_type
*> *tus
;
585 /* The compunit symtab.
586 Type units in a group needn't all be defined in the same source file,
587 so we create an essentially anonymous symtab as the compunit symtab. */
588 struct compunit_symtab
*compunit_symtab
;
590 /* The data used to construct the hash key. */
591 struct stmt_list_hash hash
;
593 /* The number of symtabs from the line header.
594 The value here must match line_header.num_file_names. */
595 unsigned int num_symtabs
;
597 /* The symbol tables for this TU (obtained from the files listed in
599 WARNING: The order of entries here must match the order of entries
600 in the line header. After the first TU using this type_unit_group, the
601 line header for the subsequent TUs is recreated from this. This is done
602 because we need to use the same symtabs for each TU using the same
603 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
604 there's no guarantee the line header doesn't have duplicate entries. */
605 struct symtab
**symtabs
;
608 /* These sections are what may appear in a (real or virtual) DWO file. */
612 struct dwarf2_section_info abbrev
;
613 struct dwarf2_section_info line
;
614 struct dwarf2_section_info loc
;
615 struct dwarf2_section_info loclists
;
616 struct dwarf2_section_info macinfo
;
617 struct dwarf2_section_info macro
;
618 struct dwarf2_section_info str
;
619 struct dwarf2_section_info str_offsets
;
620 /* In the case of a virtual DWO file, these two are unused. */
621 struct dwarf2_section_info info
;
622 std::vector
<dwarf2_section_info
> types
;
625 /* CUs/TUs in DWP/DWO files. */
629 /* Backlink to the containing struct dwo_file. */
630 struct dwo_file
*dwo_file
;
632 /* The "id" that distinguishes this CU/TU.
633 .debug_info calls this "dwo_id", .debug_types calls this "signature".
634 Since signatures came first, we stick with it for consistency. */
637 /* The section this CU/TU lives in, in the DWO file. */
638 struct dwarf2_section_info
*section
;
640 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
641 sect_offset sect_off
;
644 /* For types, offset in the type's DIE of the type defined by this TU. */
645 cu_offset type_offset_in_tu
;
648 /* include/dwarf2.h defines the DWP section codes.
649 It defines a max value but it doesn't define a min value, which we
650 use for error checking, so provide one. */
652 enum dwp_v2_section_ids
657 /* Data for one DWO file.
659 This includes virtual DWO files (a virtual DWO file is a DWO file as it
660 appears in a DWP file). DWP files don't really have DWO files per se -
661 comdat folding of types "loses" the DWO file they came from, and from
662 a high level view DWP files appear to contain a mass of random types.
663 However, to maintain consistency with the non-DWP case we pretend DWP
664 files contain virtual DWO files, and we assign each TU with one virtual
665 DWO file (generally based on the line and abbrev section offsets -
666 a heuristic that seems to work in practice). */
670 dwo_file () = default;
671 DISABLE_COPY_AND_ASSIGN (dwo_file
);
673 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
674 For virtual DWO files the name is constructed from the section offsets
675 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
676 from related CU+TUs. */
677 const char *dwo_name
= nullptr;
679 /* The DW_AT_comp_dir attribute. */
680 const char *comp_dir
= nullptr;
682 /* The bfd, when the file is open. Otherwise this is NULL.
683 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
684 gdb_bfd_ref_ptr dbfd
;
686 /* The sections that make up this DWO file.
687 Remember that for virtual DWO files in DWP V2, these are virtual
688 sections (for lack of a better name). */
689 struct dwo_sections sections
{};
691 /* The CUs in the file.
692 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
693 an extension to handle LLVM's Link Time Optimization output (where
694 multiple source files may be compiled into a single object/dwo pair). */
697 /* Table of TUs in the file.
698 Each element is a struct dwo_unit. */
702 /* These sections are what may appear in a DWP file. */
706 /* These are used by both DWP version 1 and 2. */
707 struct dwarf2_section_info str
;
708 struct dwarf2_section_info cu_index
;
709 struct dwarf2_section_info tu_index
;
711 /* These are only used by DWP version 2 files.
712 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
713 sections are referenced by section number, and are not recorded here.
714 In DWP version 2 there is at most one copy of all these sections, each
715 section being (effectively) comprised of the concatenation of all of the
716 individual sections that exist in the version 1 format.
717 To keep the code simple we treat each of these concatenated pieces as a
718 section itself (a virtual section?). */
719 struct dwarf2_section_info abbrev
;
720 struct dwarf2_section_info info
;
721 struct dwarf2_section_info line
;
722 struct dwarf2_section_info loc
;
723 struct dwarf2_section_info macinfo
;
724 struct dwarf2_section_info macro
;
725 struct dwarf2_section_info str_offsets
;
726 struct dwarf2_section_info types
;
729 /* These sections are what may appear in a virtual DWO file in DWP version 1.
730 A virtual DWO file is a DWO file as it appears in a DWP file. */
732 struct virtual_v1_dwo_sections
734 struct dwarf2_section_info abbrev
;
735 struct dwarf2_section_info line
;
736 struct dwarf2_section_info loc
;
737 struct dwarf2_section_info macinfo
;
738 struct dwarf2_section_info macro
;
739 struct dwarf2_section_info str_offsets
;
740 /* Each DWP hash table entry records one CU or one TU.
741 That is recorded here, and copied to dwo_unit.section. */
742 struct dwarf2_section_info info_or_types
;
745 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
746 In version 2, the sections of the DWO files are concatenated together
747 and stored in one section of that name. Thus each ELF section contains
748 several "virtual" sections. */
750 struct virtual_v2_dwo_sections
752 bfd_size_type abbrev_offset
;
753 bfd_size_type abbrev_size
;
755 bfd_size_type line_offset
;
756 bfd_size_type line_size
;
758 bfd_size_type loc_offset
;
759 bfd_size_type loc_size
;
761 bfd_size_type macinfo_offset
;
762 bfd_size_type macinfo_size
;
764 bfd_size_type macro_offset
;
765 bfd_size_type macro_size
;
767 bfd_size_type str_offsets_offset
;
768 bfd_size_type str_offsets_size
;
770 /* Each DWP hash table entry records one CU or one TU.
771 That is recorded here, and copied to dwo_unit.section. */
772 bfd_size_type info_or_types_offset
;
773 bfd_size_type info_or_types_size
;
776 /* Contents of DWP hash tables. */
778 struct dwp_hash_table
780 uint32_t version
, nr_columns
;
781 uint32_t nr_units
, nr_slots
;
782 const gdb_byte
*hash_table
, *unit_table
;
787 const gdb_byte
*indices
;
791 /* This is indexed by column number and gives the id of the section
793 #define MAX_NR_V2_DWO_SECTIONS \
794 (1 /* .debug_info or .debug_types */ \
795 + 1 /* .debug_abbrev */ \
796 + 1 /* .debug_line */ \
797 + 1 /* .debug_loc */ \
798 + 1 /* .debug_str_offsets */ \
799 + 1 /* .debug_macro or .debug_macinfo */)
800 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
801 const gdb_byte
*offsets
;
802 const gdb_byte
*sizes
;
807 /* Data for one DWP file. */
811 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
813 dbfd (std::move (abfd
))
817 /* Name of the file. */
820 /* File format version. */
824 gdb_bfd_ref_ptr dbfd
;
826 /* Section info for this file. */
827 struct dwp_sections sections
{};
829 /* Table of CUs in the file. */
830 const struct dwp_hash_table
*cus
= nullptr;
832 /* Table of TUs in the file. */
833 const struct dwp_hash_table
*tus
= nullptr;
835 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
839 /* Table to map ELF section numbers to their sections.
840 This is only needed for the DWP V1 file format. */
841 unsigned int num_sections
= 0;
842 asection
**elf_sections
= nullptr;
845 /* Struct used to pass misc. parameters to read_die_and_children, et
846 al. which are used for both .debug_info and .debug_types dies.
847 All parameters here are unchanging for the life of the call. This
848 struct exists to abstract away the constant parameters of die reading. */
850 struct die_reader_specs
852 /* The bfd of die_section. */
855 /* The CU of the DIE we are parsing. */
856 struct dwarf2_cu
*cu
;
858 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
859 struct dwo_file
*dwo_file
;
861 /* The section the die comes from.
862 This is either .debug_info or .debug_types, or the .dwo variants. */
863 struct dwarf2_section_info
*die_section
;
865 /* die_section->buffer. */
866 const gdb_byte
*buffer
;
868 /* The end of the buffer. */
869 const gdb_byte
*buffer_end
;
871 /* The abbreviation table to use when reading the DIEs. */
872 struct abbrev_table
*abbrev_table
;
875 /* A subclass of die_reader_specs that holds storage and has complex
876 constructor and destructor behavior. */
878 class cutu_reader
: public die_reader_specs
882 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
883 struct abbrev_table
*abbrev_table
,
884 int use_existing_cu
, int keep
,
887 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
888 struct dwarf2_cu
*parent_cu
= nullptr,
889 struct dwo_file
*dwo_file
= nullptr);
893 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
895 const gdb_byte
*info_ptr
= nullptr;
896 struct die_info
*comp_unit_die
= nullptr;
897 bool dummy_p
= false;
900 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
901 int use_existing_cu
, int keep
);
903 struct dwarf2_per_cu_data
*m_this_cu
;
905 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
907 /* The ordinary abbreviation table. */
908 abbrev_table_up m_abbrev_table_holder
;
910 /* The DWO abbreviation table. */
911 abbrev_table_up m_dwo_abbrev_table
;
914 /* When we construct a partial symbol table entry we only
915 need this much information. */
916 struct partial_die_info
: public allocate_on_obstack
918 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
920 /* Disable assign but still keep copy ctor, which is needed
921 load_partial_dies. */
922 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
924 /* Adjust the partial die before generating a symbol for it. This
925 function may set the is_external flag or change the DIE's
927 void fixup (struct dwarf2_cu
*cu
);
929 /* Read a minimal amount of information into the minimal die
931 const gdb_byte
*read (const struct die_reader_specs
*reader
,
932 const struct abbrev_info
&abbrev
,
933 const gdb_byte
*info_ptr
);
935 /* Offset of this DIE. */
936 const sect_offset sect_off
;
938 /* DWARF-2 tag for this DIE. */
939 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
941 /* Assorted flags describing the data found in this DIE. */
942 const unsigned int has_children
: 1;
944 unsigned int is_external
: 1;
945 unsigned int is_declaration
: 1;
946 unsigned int has_type
: 1;
947 unsigned int has_specification
: 1;
948 unsigned int has_pc_info
: 1;
949 unsigned int may_be_inlined
: 1;
951 /* This DIE has been marked DW_AT_main_subprogram. */
952 unsigned int main_subprogram
: 1;
954 /* Flag set if the SCOPE field of this structure has been
956 unsigned int scope_set
: 1;
958 /* Flag set if the DIE has a byte_size attribute. */
959 unsigned int has_byte_size
: 1;
961 /* Flag set if the DIE has a DW_AT_const_value attribute. */
962 unsigned int has_const_value
: 1;
964 /* Flag set if any of the DIE's children are template arguments. */
965 unsigned int has_template_arguments
: 1;
967 /* Flag set if fixup has been called on this die. */
968 unsigned int fixup_called
: 1;
970 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
971 unsigned int is_dwz
: 1;
973 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
974 unsigned int spec_is_dwz
: 1;
976 /* The name of this DIE. Normally the value of DW_AT_name, but
977 sometimes a default name for unnamed DIEs. */
978 const char *name
= nullptr;
980 /* The linkage name, if present. */
981 const char *linkage_name
= nullptr;
983 /* The scope to prepend to our children. This is generally
984 allocated on the comp_unit_obstack, so will disappear
985 when this compilation unit leaves the cache. */
986 const char *scope
= nullptr;
988 /* Some data associated with the partial DIE. The tag determines
989 which field is live. */
992 /* The location description associated with this DIE, if any. */
993 struct dwarf_block
*locdesc
;
994 /* The offset of an import, for DW_TAG_imported_unit. */
995 sect_offset sect_off
;
998 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1000 CORE_ADDR highpc
= 0;
1002 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1003 DW_AT_sibling, if any. */
1004 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1005 could return DW_AT_sibling values to its caller load_partial_dies. */
1006 const gdb_byte
*sibling
= nullptr;
1008 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1009 DW_AT_specification (or DW_AT_abstract_origin or
1010 DW_AT_extension). */
1011 sect_offset spec_offset
{};
1013 /* Pointers to this DIE's parent, first child, and next sibling,
1015 struct partial_die_info
*die_parent
= nullptr;
1016 struct partial_die_info
*die_child
= nullptr;
1017 struct partial_die_info
*die_sibling
= nullptr;
1019 friend struct partial_die_info
*
1020 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1023 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1024 partial_die_info (sect_offset sect_off
)
1025 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1029 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1031 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1036 has_specification
= 0;
1039 main_subprogram
= 0;
1042 has_const_value
= 0;
1043 has_template_arguments
= 0;
1050 /* This data structure holds a complete die structure. */
1053 /* DWARF-2 tag for this DIE. */
1054 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1056 /* Number of attributes */
1057 unsigned char num_attrs
;
1059 /* True if we're presently building the full type name for the
1060 type derived from this DIE. */
1061 unsigned char building_fullname
: 1;
1063 /* True if this die is in process. PR 16581. */
1064 unsigned char in_process
: 1;
1066 /* True if this DIE has children. */
1067 unsigned char has_children
: 1;
1070 unsigned int abbrev
;
1072 /* Offset in .debug_info or .debug_types section. */
1073 sect_offset sect_off
;
1075 /* The dies in a compilation unit form an n-ary tree. PARENT
1076 points to this die's parent; CHILD points to the first child of
1077 this node; and all the children of a given node are chained
1078 together via their SIBLING fields. */
1079 struct die_info
*child
; /* Its first child, if any. */
1080 struct die_info
*sibling
; /* Its next sibling, if any. */
1081 struct die_info
*parent
; /* Its parent, if any. */
1083 /* An array of attributes, with NUM_ATTRS elements. There may be
1084 zero, but it's not common and zero-sized arrays are not
1085 sufficiently portable C. */
1086 struct attribute attrs
[1];
1089 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1090 but this would require a corresponding change in unpack_field_as_long
1092 static int bits_per_byte
= 8;
1094 /* When reading a variant or variant part, we track a bit more
1095 information about the field, and store it in an object of this
1098 struct variant_field
1100 /* If we see a DW_TAG_variant, then this will be the discriminant
1102 ULONGEST discriminant_value
;
1103 /* If we see a DW_TAG_variant, then this will be set if this is the
1105 bool default_branch
;
1106 /* While reading a DW_TAG_variant_part, this will be set if this
1107 field is the discriminant. */
1108 bool is_discriminant
;
1113 int accessibility
= 0;
1115 /* Extra information to describe a variant or variant part. */
1116 struct variant_field variant
{};
1117 struct field field
{};
1122 const char *name
= nullptr;
1123 std::vector
<struct fn_field
> fnfields
;
1126 /* The routines that read and process dies for a C struct or C++ class
1127 pass lists of data member fields and lists of member function fields
1128 in an instance of a field_info structure, as defined below. */
1131 /* List of data member and baseclasses fields. */
1132 std::vector
<struct nextfield
> fields
;
1133 std::vector
<struct nextfield
> baseclasses
;
1135 /* Number of fields (including baseclasses). */
1138 /* Set if the accessibility of one of the fields is not public. */
1139 int non_public_fields
= 0;
1141 /* Member function fieldlist array, contains name of possibly overloaded
1142 member function, number of overloaded member functions and a pointer
1143 to the head of the member function field chain. */
1144 std::vector
<struct fnfieldlist
> fnfieldlists
;
1146 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1147 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1148 std::vector
<struct decl_field
> typedef_field_list
;
1150 /* Nested types defined by this class and the number of elements in this
1152 std::vector
<struct decl_field
> nested_types_list
;
1155 /* Loaded secondary compilation units are kept in memory until they
1156 have not been referenced for the processing of this many
1157 compilation units. Set this to zero to disable caching. Cache
1158 sizes of up to at least twenty will improve startup time for
1159 typical inter-CU-reference binaries, at an obvious memory cost. */
1160 static int dwarf_max_cache_age
= 5;
1162 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1163 struct cmd_list_element
*c
, const char *value
)
1165 fprintf_filtered (file
, _("The upper bound on the age of cached "
1166 "DWARF compilation units is %s.\n"),
1170 /* local function prototypes */
1172 static void dwarf2_find_base_address (struct die_info
*die
,
1173 struct dwarf2_cu
*cu
);
1175 static dwarf2_psymtab
*create_partial_symtab
1176 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1178 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1179 const gdb_byte
*info_ptr
,
1180 struct die_info
*type_unit_die
);
1182 static void dwarf2_build_psymtabs_hard
1183 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1185 static void scan_partial_symbols (struct partial_die_info
*,
1186 CORE_ADDR
*, CORE_ADDR
*,
1187 int, struct dwarf2_cu
*);
1189 static void add_partial_symbol (struct partial_die_info
*,
1190 struct dwarf2_cu
*);
1192 static void add_partial_namespace (struct partial_die_info
*pdi
,
1193 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1194 int set_addrmap
, struct dwarf2_cu
*cu
);
1196 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1197 CORE_ADDR
*highpc
, int set_addrmap
,
1198 struct dwarf2_cu
*cu
);
1200 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1201 struct dwarf2_cu
*cu
);
1203 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1204 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1205 int need_pc
, struct dwarf2_cu
*cu
);
1207 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1209 static struct partial_die_info
*load_partial_dies
1210 (const struct die_reader_specs
*, const gdb_byte
*, int);
1212 /* A pair of partial_die_info and compilation unit. */
1213 struct cu_partial_die_info
1215 /* The compilation unit of the partial_die_info. */
1216 struct dwarf2_cu
*cu
;
1217 /* A partial_die_info. */
1218 struct partial_die_info
*pdi
;
1220 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1226 cu_partial_die_info () = delete;
1229 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1230 struct dwarf2_cu
*);
1232 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1233 struct attribute
*, struct attr_abbrev
*,
1234 const gdb_byte
*, bool *need_reprocess
);
1236 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1237 struct attribute
*attr
);
1239 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1241 static LONGEST read_checked_initial_length_and_offset
1242 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1243 unsigned int *, unsigned int *);
1245 static sect_offset read_abbrev_offset
1246 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1247 struct dwarf2_section_info
*, sect_offset
);
1249 static const char *read_indirect_string
1250 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1251 const struct comp_unit_head
*, unsigned int *);
1253 static const char *read_indirect_line_string
1254 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1255 const struct comp_unit_head
*, unsigned int *);
1257 static const char *read_indirect_string_at_offset
1258 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1259 LONGEST str_offset
);
1261 static const char *read_indirect_string_from_dwz
1262 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1264 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1268 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1269 ULONGEST str_index
);
1271 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1272 ULONGEST str_index
);
1274 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1276 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1277 struct dwarf2_cu
*);
1279 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1282 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1283 struct dwarf2_cu
*cu
);
1285 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1287 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1288 struct dwarf2_cu
*cu
);
1290 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1292 static struct die_info
*die_specification (struct die_info
*die
,
1293 struct dwarf2_cu
**);
1295 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1296 struct dwarf2_cu
*cu
);
1298 static void dwarf_decode_lines (struct line_header
*, const char *,
1299 struct dwarf2_cu
*, dwarf2_psymtab
*,
1300 CORE_ADDR
, int decode_mapping
);
1302 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1305 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1306 struct dwarf2_cu
*, struct symbol
* = NULL
);
1308 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1309 struct dwarf2_cu
*);
1311 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1314 struct obstack
*obstack
,
1315 struct dwarf2_cu
*cu
, LONGEST
*value
,
1316 const gdb_byte
**bytes
,
1317 struct dwarf2_locexpr_baton
**baton
);
1319 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1321 static int need_gnat_info (struct dwarf2_cu
*);
1323 static struct type
*die_descriptive_type (struct die_info
*,
1324 struct dwarf2_cu
*);
1326 static void set_descriptive_type (struct type
*, struct die_info
*,
1327 struct dwarf2_cu
*);
1329 static struct type
*die_containing_type (struct die_info
*,
1330 struct dwarf2_cu
*);
1332 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1333 struct dwarf2_cu
*);
1335 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1337 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1339 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1341 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1342 const char *suffix
, int physname
,
1343 struct dwarf2_cu
*cu
);
1345 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1347 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1349 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1351 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1353 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1355 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1357 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1358 struct dwarf2_cu
*, dwarf2_psymtab
*);
1360 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1361 values. Keep the items ordered with increasing constraints compliance. */
1364 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1365 PC_BOUNDS_NOT_PRESENT
,
1367 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1368 were present but they do not form a valid range of PC addresses. */
1371 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1374 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1378 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1379 CORE_ADDR
*, CORE_ADDR
*,
1383 static void get_scope_pc_bounds (struct die_info
*,
1384 CORE_ADDR
*, CORE_ADDR
*,
1385 struct dwarf2_cu
*);
1387 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1388 CORE_ADDR
, struct dwarf2_cu
*);
1390 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1391 struct dwarf2_cu
*);
1393 static void dwarf2_attach_fields_to_type (struct field_info
*,
1394 struct type
*, struct dwarf2_cu
*);
1396 static void dwarf2_add_member_fn (struct field_info
*,
1397 struct die_info
*, struct type
*,
1398 struct dwarf2_cu
*);
1400 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1402 struct dwarf2_cu
*);
1404 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1406 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1408 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1410 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1412 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1414 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1416 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1418 static struct type
*read_module_type (struct die_info
*die
,
1419 struct dwarf2_cu
*cu
);
1421 static const char *namespace_name (struct die_info
*die
,
1422 int *is_anonymous
, struct dwarf2_cu
*);
1424 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1426 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1428 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1429 struct dwarf2_cu
*);
1431 static struct die_info
*read_die_and_siblings_1
1432 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1435 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1436 const gdb_byte
*info_ptr
,
1437 const gdb_byte
**new_info_ptr
,
1438 struct die_info
*parent
);
1440 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1441 struct die_info
**, const gdb_byte
*,
1444 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1445 struct die_info
**, const gdb_byte
*);
1447 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1449 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1452 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1454 static const char *dwarf2_full_name (const char *name
,
1455 struct die_info
*die
,
1456 struct dwarf2_cu
*cu
);
1458 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1459 struct dwarf2_cu
*cu
);
1461 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1462 struct dwarf2_cu
**);
1464 static const char *dwarf_tag_name (unsigned int);
1466 static const char *dwarf_attr_name (unsigned int);
1468 static const char *dwarf_form_name (unsigned int);
1470 static const char *dwarf_bool_name (unsigned int);
1472 static const char *dwarf_type_encoding_name (unsigned int);
1474 static struct die_info
*sibling_die (struct die_info
*);
1476 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1478 static void dump_die_for_error (struct die_info
*);
1480 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1483 /*static*/ void dump_die (struct die_info
*, int max_level
);
1485 static void store_in_ref_table (struct die_info
*,
1486 struct dwarf2_cu
*);
1488 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1490 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1492 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1493 const struct attribute
*,
1494 struct dwarf2_cu
**);
1496 static struct die_info
*follow_die_ref (struct die_info
*,
1497 const struct attribute
*,
1498 struct dwarf2_cu
**);
1500 static struct die_info
*follow_die_sig (struct die_info
*,
1501 const struct attribute
*,
1502 struct dwarf2_cu
**);
1504 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1505 struct dwarf2_cu
*);
1507 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1508 const struct attribute
*,
1509 struct dwarf2_cu
*);
1511 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1513 static void read_signatured_type (struct signatured_type
*);
1515 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1516 struct die_info
*die
, struct dwarf2_cu
*cu
,
1517 struct dynamic_prop
*prop
, struct type
*type
);
1519 /* memory allocation interface */
1521 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1523 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1525 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1527 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1528 struct dwarf2_loclist_baton
*baton
,
1529 const struct attribute
*attr
);
1531 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1533 struct dwarf2_cu
*cu
,
1536 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1537 const gdb_byte
*info_ptr
,
1538 struct abbrev_info
*abbrev
);
1540 static hashval_t
partial_die_hash (const void *item
);
1542 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1544 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1545 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1546 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1548 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1549 struct die_info
*comp_unit_die
,
1550 enum language pretend_language
);
1552 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1554 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1556 static struct type
*set_die_type (struct die_info
*, struct type
*,
1557 struct dwarf2_cu
*);
1559 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1561 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1563 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1566 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1569 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1572 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1573 struct dwarf2_per_cu_data
*);
1575 static void dwarf2_mark (struct dwarf2_cu
*);
1577 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1579 static struct type
*get_die_type_at_offset (sect_offset
,
1580 struct dwarf2_per_cu_data
*);
1582 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1584 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1585 enum language pretend_language
);
1587 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1589 /* Class, the destructor of which frees all allocated queue entries. This
1590 will only have work to do if an error was thrown while processing the
1591 dwarf. If no error was thrown then the queue entries should have all
1592 been processed, and freed, as we went along. */
1594 class dwarf2_queue_guard
1597 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1598 : m_per_objfile (per_objfile
)
1602 /* Free any entries remaining on the queue. There should only be
1603 entries left if we hit an error while processing the dwarf. */
1604 ~dwarf2_queue_guard ()
1606 /* Ensure that no memory is allocated by the queue. */
1607 std::queue
<dwarf2_queue_item
> empty
;
1608 std::swap (m_per_objfile
->queue
, empty
);
1611 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1614 dwarf2_per_objfile
*m_per_objfile
;
1617 dwarf2_queue_item::~dwarf2_queue_item ()
1619 /* Anything still marked queued is likely to be in an
1620 inconsistent state, so discard it. */
1623 if (per_cu
->cu
!= NULL
)
1624 free_one_cached_comp_unit (per_cu
);
1629 /* The return type of find_file_and_directory. Note, the enclosed
1630 string pointers are only valid while this object is valid. */
1632 struct file_and_directory
1634 /* The filename. This is never NULL. */
1637 /* The compilation directory. NULL if not known. If we needed to
1638 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1639 points directly to the DW_AT_comp_dir string attribute owned by
1640 the obstack that owns the DIE. */
1641 const char *comp_dir
;
1643 /* If we needed to build a new string for comp_dir, this is what
1644 owns the storage. */
1645 std::string comp_dir_storage
;
1648 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1649 struct dwarf2_cu
*cu
);
1651 static htab_up
allocate_signatured_type_table (struct objfile
*objfile
);
1653 static htab_up
allocate_dwo_unit_table (struct objfile
*objfile
);
1655 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1656 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1657 struct dwp_file
*dwp_file
, const char *comp_dir
,
1658 ULONGEST signature
, int is_debug_types
);
1660 static struct dwp_file
*get_dwp_file
1661 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1663 static struct dwo_unit
*lookup_dwo_comp_unit
1664 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1666 static struct dwo_unit
*lookup_dwo_type_unit
1667 (struct signatured_type
*, const char *, const char *);
1669 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1671 /* A unique pointer to a dwo_file. */
1673 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1675 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1677 static void check_producer (struct dwarf2_cu
*cu
);
1679 static void free_line_header_voidp (void *arg
);
1681 /* Various complaints about symbol reading that don't abort the process. */
1684 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1686 complaint (_("statement list doesn't fit in .debug_line section"));
1690 dwarf2_debug_line_missing_file_complaint (void)
1692 complaint (_(".debug_line section has line data without a file"));
1696 dwarf2_debug_line_missing_end_sequence_complaint (void)
1698 complaint (_(".debug_line section has line "
1699 "program sequence without an end"));
1703 dwarf2_complex_location_expr_complaint (void)
1705 complaint (_("location expression too complex"));
1709 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1712 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1717 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1719 complaint (_("debug info runs off end of %s section"
1721 section
->get_name (),
1722 section
->get_file_name ());
1726 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1728 complaint (_("macro debug info contains a "
1729 "malformed macro definition:\n`%s'"),
1734 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1736 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1740 /* Hash function for line_header_hash. */
1743 line_header_hash (const struct line_header
*ofs
)
1745 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1748 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1751 line_header_hash_voidp (const void *item
)
1753 const struct line_header
*ofs
= (const struct line_header
*) item
;
1755 return line_header_hash (ofs
);
1758 /* Equality function for line_header_hash. */
1761 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1763 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1764 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1766 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1767 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1772 /* See declaration. */
1774 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1775 const dwarf2_debug_sections
*names
,
1777 : objfile (objfile_
),
1778 can_copy (can_copy_
)
1781 names
= &dwarf2_elf_names
;
1783 bfd
*obfd
= objfile
->obfd
;
1785 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1786 locate_sections (obfd
, sec
, *names
);
1789 dwarf2_per_objfile::~dwarf2_per_objfile ()
1791 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1792 free_cached_comp_units ();
1794 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1795 per_cu
->imported_symtabs_free ();
1797 for (signatured_type
*sig_type
: all_type_units
)
1798 sig_type
->per_cu
.imported_symtabs_free ();
1800 /* Everything else should be on the objfile obstack. */
1803 /* See declaration. */
1806 dwarf2_per_objfile::free_cached_comp_units ()
1808 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1809 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1810 while (per_cu
!= NULL
)
1812 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1815 *last_chain
= next_cu
;
1820 /* A helper class that calls free_cached_comp_units on
1823 class free_cached_comp_units
1827 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1828 : m_per_objfile (per_objfile
)
1832 ~free_cached_comp_units ()
1834 m_per_objfile
->free_cached_comp_units ();
1837 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1841 dwarf2_per_objfile
*m_per_objfile
;
1844 /* Try to locate the sections we need for DWARF 2 debugging
1845 information and return true if we have enough to do something.
1846 NAMES points to the dwarf2 section names, or is NULL if the standard
1847 ELF names are used. CAN_COPY is true for formats where symbol
1848 interposition is possible and so symbol values must follow copy
1849 relocation rules. */
1852 dwarf2_has_info (struct objfile
*objfile
,
1853 const struct dwarf2_debug_sections
*names
,
1856 if (objfile
->flags
& OBJF_READNEVER
)
1859 struct dwarf2_per_objfile
*dwarf2_per_objfile
1860 = get_dwarf2_per_objfile (objfile
);
1862 if (dwarf2_per_objfile
== NULL
)
1863 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1867 return (!dwarf2_per_objfile
->info
.is_virtual
1868 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1869 && !dwarf2_per_objfile
->abbrev
.is_virtual
1870 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1873 /* When loading sections, we look either for uncompressed section or for
1874 compressed section names. */
1877 section_is_p (const char *section_name
,
1878 const struct dwarf2_section_names
*names
)
1880 if (names
->normal
!= NULL
1881 && strcmp (section_name
, names
->normal
) == 0)
1883 if (names
->compressed
!= NULL
1884 && strcmp (section_name
, names
->compressed
) == 0)
1889 /* See declaration. */
1892 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1893 const dwarf2_debug_sections
&names
)
1895 flagword aflag
= bfd_section_flags (sectp
);
1897 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1900 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1901 > bfd_get_file_size (abfd
))
1903 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1904 warning (_("Discarding section %s which has a section size (%s"
1905 ") larger than the file size [in module %s]"),
1906 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1907 bfd_get_filename (abfd
));
1909 else if (section_is_p (sectp
->name
, &names
.info
))
1911 this->info
.s
.section
= sectp
;
1912 this->info
.size
= bfd_section_size (sectp
);
1914 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1916 this->abbrev
.s
.section
= sectp
;
1917 this->abbrev
.size
= bfd_section_size (sectp
);
1919 else if (section_is_p (sectp
->name
, &names
.line
))
1921 this->line
.s
.section
= sectp
;
1922 this->line
.size
= bfd_section_size (sectp
);
1924 else if (section_is_p (sectp
->name
, &names
.loc
))
1926 this->loc
.s
.section
= sectp
;
1927 this->loc
.size
= bfd_section_size (sectp
);
1929 else if (section_is_p (sectp
->name
, &names
.loclists
))
1931 this->loclists
.s
.section
= sectp
;
1932 this->loclists
.size
= bfd_section_size (sectp
);
1934 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1936 this->macinfo
.s
.section
= sectp
;
1937 this->macinfo
.size
= bfd_section_size (sectp
);
1939 else if (section_is_p (sectp
->name
, &names
.macro
))
1941 this->macro
.s
.section
= sectp
;
1942 this->macro
.size
= bfd_section_size (sectp
);
1944 else if (section_is_p (sectp
->name
, &names
.str
))
1946 this->str
.s
.section
= sectp
;
1947 this->str
.size
= bfd_section_size (sectp
);
1949 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1951 this->str_offsets
.s
.section
= sectp
;
1952 this->str_offsets
.size
= bfd_section_size (sectp
);
1954 else if (section_is_p (sectp
->name
, &names
.line_str
))
1956 this->line_str
.s
.section
= sectp
;
1957 this->line_str
.size
= bfd_section_size (sectp
);
1959 else if (section_is_p (sectp
->name
, &names
.addr
))
1961 this->addr
.s
.section
= sectp
;
1962 this->addr
.size
= bfd_section_size (sectp
);
1964 else if (section_is_p (sectp
->name
, &names
.frame
))
1966 this->frame
.s
.section
= sectp
;
1967 this->frame
.size
= bfd_section_size (sectp
);
1969 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1971 this->eh_frame
.s
.section
= sectp
;
1972 this->eh_frame
.size
= bfd_section_size (sectp
);
1974 else if (section_is_p (sectp
->name
, &names
.ranges
))
1976 this->ranges
.s
.section
= sectp
;
1977 this->ranges
.size
= bfd_section_size (sectp
);
1979 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1981 this->rnglists
.s
.section
= sectp
;
1982 this->rnglists
.size
= bfd_section_size (sectp
);
1984 else if (section_is_p (sectp
->name
, &names
.types
))
1986 struct dwarf2_section_info type_section
;
1988 memset (&type_section
, 0, sizeof (type_section
));
1989 type_section
.s
.section
= sectp
;
1990 type_section
.size
= bfd_section_size (sectp
);
1992 this->types
.push_back (type_section
);
1994 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1996 this->gdb_index
.s
.section
= sectp
;
1997 this->gdb_index
.size
= bfd_section_size (sectp
);
1999 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2001 this->debug_names
.s
.section
= sectp
;
2002 this->debug_names
.size
= bfd_section_size (sectp
);
2004 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2006 this->debug_aranges
.s
.section
= sectp
;
2007 this->debug_aranges
.size
= bfd_section_size (sectp
);
2010 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2011 && bfd_section_vma (sectp
) == 0)
2012 this->has_section_at_zero
= true;
2015 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2019 dwarf2_get_section_info (struct objfile
*objfile
,
2020 enum dwarf2_section_enum sect
,
2021 asection
**sectp
, const gdb_byte
**bufp
,
2022 bfd_size_type
*sizep
)
2024 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2025 struct dwarf2_section_info
*info
;
2027 /* We may see an objfile without any DWARF, in which case we just
2038 case DWARF2_DEBUG_FRAME
:
2039 info
= &data
->frame
;
2041 case DWARF2_EH_FRAME
:
2042 info
= &data
->eh_frame
;
2045 gdb_assert_not_reached ("unexpected section");
2048 info
->read (objfile
);
2050 *sectp
= info
->get_bfd_section ();
2051 *bufp
= info
->buffer
;
2052 *sizep
= info
->size
;
2055 /* A helper function to find the sections for a .dwz file. */
2058 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2060 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2062 /* Note that we only support the standard ELF names, because .dwz
2063 is ELF-only (at the time of writing). */
2064 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2066 dwz_file
->abbrev
.s
.section
= sectp
;
2067 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2069 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2071 dwz_file
->info
.s
.section
= sectp
;
2072 dwz_file
->info
.size
= bfd_section_size (sectp
);
2074 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2076 dwz_file
->str
.s
.section
= sectp
;
2077 dwz_file
->str
.size
= bfd_section_size (sectp
);
2079 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2081 dwz_file
->line
.s
.section
= sectp
;
2082 dwz_file
->line
.size
= bfd_section_size (sectp
);
2084 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2086 dwz_file
->macro
.s
.section
= sectp
;
2087 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2089 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2091 dwz_file
->gdb_index
.s
.section
= sectp
;
2092 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2094 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2096 dwz_file
->debug_names
.s
.section
= sectp
;
2097 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2101 /* See dwarf2read.h. */
2104 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2106 const char *filename
;
2107 bfd_size_type buildid_len_arg
;
2111 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2112 return dwarf2_per_objfile
->dwz_file
.get ();
2114 bfd_set_error (bfd_error_no_error
);
2115 gdb::unique_xmalloc_ptr
<char> data
2116 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2117 &buildid_len_arg
, &buildid
));
2120 if (bfd_get_error () == bfd_error_no_error
)
2122 error (_("could not read '.gnu_debugaltlink' section: %s"),
2123 bfd_errmsg (bfd_get_error ()));
2126 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2128 buildid_len
= (size_t) buildid_len_arg
;
2130 filename
= data
.get ();
2132 std::string abs_storage
;
2133 if (!IS_ABSOLUTE_PATH (filename
))
2135 gdb::unique_xmalloc_ptr
<char> abs
2136 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2138 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2139 filename
= abs_storage
.c_str ();
2142 /* First try the file name given in the section. If that doesn't
2143 work, try to use the build-id instead. */
2144 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2145 if (dwz_bfd
!= NULL
)
2147 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2148 dwz_bfd
.reset (nullptr);
2151 if (dwz_bfd
== NULL
)
2152 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2154 if (dwz_bfd
== NULL
)
2155 error (_("could not find '.gnu_debugaltlink' file for %s"),
2156 objfile_name (dwarf2_per_objfile
->objfile
));
2158 std::unique_ptr
<struct dwz_file
> result
2159 (new struct dwz_file (std::move (dwz_bfd
)));
2161 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2164 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2165 result
->dwz_bfd
.get ());
2166 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2167 return dwarf2_per_objfile
->dwz_file
.get ();
2170 /* DWARF quick_symbols_functions support. */
2172 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2173 unique line tables, so we maintain a separate table of all .debug_line
2174 derived entries to support the sharing.
2175 All the quick functions need is the list of file names. We discard the
2176 line_header when we're done and don't need to record it here. */
2177 struct quick_file_names
2179 /* The data used to construct the hash key. */
2180 struct stmt_list_hash hash
;
2182 /* The number of entries in file_names, real_names. */
2183 unsigned int num_file_names
;
2185 /* The file names from the line table, after being run through
2187 const char **file_names
;
2189 /* The file names from the line table after being run through
2190 gdb_realpath. These are computed lazily. */
2191 const char **real_names
;
2194 /* When using the index (and thus not using psymtabs), each CU has an
2195 object of this type. This is used to hold information needed by
2196 the various "quick" methods. */
2197 struct dwarf2_per_cu_quick_data
2199 /* The file table. This can be NULL if there was no file table
2200 or it's currently not read in.
2201 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2202 struct quick_file_names
*file_names
;
2204 /* The corresponding symbol table. This is NULL if symbols for this
2205 CU have not yet been read. */
2206 struct compunit_symtab
*compunit_symtab
;
2208 /* A temporary mark bit used when iterating over all CUs in
2209 expand_symtabs_matching. */
2210 unsigned int mark
: 1;
2212 /* True if we've tried to read the file table and found there isn't one.
2213 There will be no point in trying to read it again next time. */
2214 unsigned int no_file_data
: 1;
2217 /* Utility hash function for a stmt_list_hash. */
2220 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2224 if (stmt_list_hash
->dwo_unit
!= NULL
)
2225 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2226 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2230 /* Utility equality function for a stmt_list_hash. */
2233 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2234 const struct stmt_list_hash
*rhs
)
2236 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2238 if (lhs
->dwo_unit
!= NULL
2239 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2242 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2245 /* Hash function for a quick_file_names. */
2248 hash_file_name_entry (const void *e
)
2250 const struct quick_file_names
*file_data
2251 = (const struct quick_file_names
*) e
;
2253 return hash_stmt_list_entry (&file_data
->hash
);
2256 /* Equality function for a quick_file_names. */
2259 eq_file_name_entry (const void *a
, const void *b
)
2261 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2262 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2264 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2267 /* Delete function for a quick_file_names. */
2270 delete_file_name_entry (void *e
)
2272 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2275 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2277 xfree ((void*) file_data
->file_names
[i
]);
2278 if (file_data
->real_names
)
2279 xfree ((void*) file_data
->real_names
[i
]);
2282 /* The space for the struct itself lives on objfile_obstack,
2283 so we don't free it here. */
2286 /* Create a quick_file_names hash table. */
2289 create_quick_file_names_table (unsigned int nr_initial_entries
)
2291 return htab_up (htab_create_alloc (nr_initial_entries
,
2292 hash_file_name_entry
, eq_file_name_entry
,
2293 delete_file_name_entry
, xcalloc
, xfree
));
2296 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2297 have to be created afterwards. You should call age_cached_comp_units after
2298 processing PER_CU->CU. dw2_setup must have been already called. */
2301 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2303 if (per_cu
->is_debug_types
)
2304 load_full_type_unit (per_cu
);
2306 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2308 if (per_cu
->cu
== NULL
)
2309 return; /* Dummy CU. */
2311 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2314 /* Read in the symbols for PER_CU. */
2317 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2319 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2321 /* Skip type_unit_groups, reading the type units they contain
2322 is handled elsewhere. */
2323 if (IS_TYPE_UNIT_GROUP (per_cu
))
2326 /* The destructor of dwarf2_queue_guard frees any entries left on
2327 the queue. After this point we're guaranteed to leave this function
2328 with the dwarf queue empty. */
2329 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2331 if (dwarf2_per_objfile
->using_index
2332 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2333 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2335 queue_comp_unit (per_cu
, language_minimal
);
2336 load_cu (per_cu
, skip_partial
);
2338 /* If we just loaded a CU from a DWO, and we're working with an index
2339 that may badly handle TUs, load all the TUs in that DWO as well.
2340 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2341 if (!per_cu
->is_debug_types
2342 && per_cu
->cu
!= NULL
2343 && per_cu
->cu
->dwo_unit
!= NULL
2344 && dwarf2_per_objfile
->index_table
!= NULL
2345 && dwarf2_per_objfile
->index_table
->version
<= 7
2346 /* DWP files aren't supported yet. */
2347 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2348 queue_and_load_all_dwo_tus (per_cu
);
2351 process_queue (dwarf2_per_objfile
);
2353 /* Age the cache, releasing compilation units that have not
2354 been used recently. */
2355 age_cached_comp_units (dwarf2_per_objfile
);
2358 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2359 the objfile from which this CU came. Returns the resulting symbol
2362 static struct compunit_symtab
*
2363 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2365 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2367 gdb_assert (dwarf2_per_objfile
->using_index
);
2368 if (!per_cu
->v
.quick
->compunit_symtab
)
2370 free_cached_comp_units
freer (dwarf2_per_objfile
);
2371 scoped_restore decrementer
= increment_reading_symtab ();
2372 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2373 process_cu_includes (dwarf2_per_objfile
);
2376 return per_cu
->v
.quick
->compunit_symtab
;
2379 /* See declaration. */
2381 dwarf2_per_cu_data
*
2382 dwarf2_per_objfile::get_cutu (int index
)
2384 if (index
>= this->all_comp_units
.size ())
2386 index
-= this->all_comp_units
.size ();
2387 gdb_assert (index
< this->all_type_units
.size ());
2388 return &this->all_type_units
[index
]->per_cu
;
2391 return this->all_comp_units
[index
];
2394 /* See declaration. */
2396 dwarf2_per_cu_data
*
2397 dwarf2_per_objfile::get_cu (int index
)
2399 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2401 return this->all_comp_units
[index
];
2404 /* See declaration. */
2407 dwarf2_per_objfile::get_tu (int index
)
2409 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2411 return this->all_type_units
[index
];
2414 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2415 objfile_obstack, and constructed with the specified field
2418 static dwarf2_per_cu_data
*
2419 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2420 struct dwarf2_section_info
*section
,
2422 sect_offset sect_off
, ULONGEST length
)
2424 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2425 dwarf2_per_cu_data
*the_cu
2426 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2427 struct dwarf2_per_cu_data
);
2428 the_cu
->sect_off
= sect_off
;
2429 the_cu
->length
= length
;
2430 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2431 the_cu
->section
= section
;
2432 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2433 struct dwarf2_per_cu_quick_data
);
2434 the_cu
->is_dwz
= is_dwz
;
2438 /* A helper for create_cus_from_index that handles a given list of
2442 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2443 const gdb_byte
*cu_list
, offset_type n_elements
,
2444 struct dwarf2_section_info
*section
,
2447 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2449 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2451 sect_offset sect_off
2452 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2453 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2456 dwarf2_per_cu_data
*per_cu
2457 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2459 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2463 /* Read the CU list from the mapped index, and use it to create all
2464 the CU objects for this objfile. */
2467 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2468 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2469 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2471 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2472 dwarf2_per_objfile
->all_comp_units
.reserve
2473 ((cu_list_elements
+ dwz_elements
) / 2);
2475 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2476 &dwarf2_per_objfile
->info
, 0);
2478 if (dwz_elements
== 0)
2481 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2482 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2486 /* Create the signatured type hash table from the index. */
2489 create_signatured_type_table_from_index
2490 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2491 struct dwarf2_section_info
*section
,
2492 const gdb_byte
*bytes
,
2493 offset_type elements
)
2495 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2497 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2498 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2500 htab_up sig_types_hash
= allocate_signatured_type_table (objfile
);
2502 for (offset_type i
= 0; i
< elements
; i
+= 3)
2504 struct signatured_type
*sig_type
;
2507 cu_offset type_offset_in_tu
;
2509 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2510 sect_offset sect_off
2511 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2513 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2515 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2518 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2519 struct signatured_type
);
2520 sig_type
->signature
= signature
;
2521 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2522 sig_type
->per_cu
.is_debug_types
= 1;
2523 sig_type
->per_cu
.section
= section
;
2524 sig_type
->per_cu
.sect_off
= sect_off
;
2525 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2526 sig_type
->per_cu
.v
.quick
2527 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2528 struct dwarf2_per_cu_quick_data
);
2530 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2533 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2536 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2539 /* Create the signatured type hash table from .debug_names. */
2542 create_signatured_type_table_from_debug_names
2543 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2544 const mapped_debug_names
&map
,
2545 struct dwarf2_section_info
*section
,
2546 struct dwarf2_section_info
*abbrev_section
)
2548 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2550 section
->read (objfile
);
2551 abbrev_section
->read (objfile
);
2553 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2554 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2556 htab_up sig_types_hash
= allocate_signatured_type_table (objfile
);
2558 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2560 struct signatured_type
*sig_type
;
2563 sect_offset sect_off
2564 = (sect_offset
) (extract_unsigned_integer
2565 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2567 map
.dwarf5_byte_order
));
2569 comp_unit_head cu_header
;
2570 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2572 section
->buffer
+ to_underlying (sect_off
),
2575 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2576 struct signatured_type
);
2577 sig_type
->signature
= cu_header
.signature
;
2578 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2579 sig_type
->per_cu
.is_debug_types
= 1;
2580 sig_type
->per_cu
.section
= section
;
2581 sig_type
->per_cu
.sect_off
= sect_off
;
2582 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2583 sig_type
->per_cu
.v
.quick
2584 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2585 struct dwarf2_per_cu_quick_data
);
2587 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2590 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2593 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2596 /* Read the address map data from the mapped index, and use it to
2597 populate the objfile's psymtabs_addrmap. */
2600 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2601 struct mapped_index
*index
)
2603 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2604 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2605 const gdb_byte
*iter
, *end
;
2606 struct addrmap
*mutable_map
;
2609 auto_obstack temp_obstack
;
2611 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2613 iter
= index
->address_table
.data ();
2614 end
= iter
+ index
->address_table
.size ();
2616 baseaddr
= objfile
->text_section_offset ();
2620 ULONGEST hi
, lo
, cu_index
;
2621 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2623 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2625 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2630 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2631 hex_string (lo
), hex_string (hi
));
2635 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2637 complaint (_(".gdb_index address table has invalid CU number %u"),
2638 (unsigned) cu_index
);
2642 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2643 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2644 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2645 dwarf2_per_objfile
->get_cu (cu_index
));
2648 objfile
->partial_symtabs
->psymtabs_addrmap
2649 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2652 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2653 populate the objfile's psymtabs_addrmap. */
2656 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2657 struct dwarf2_section_info
*section
)
2659 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2660 bfd
*abfd
= objfile
->obfd
;
2661 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2662 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2664 auto_obstack temp_obstack
;
2665 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2667 std::unordered_map
<sect_offset
,
2668 dwarf2_per_cu_data
*,
2669 gdb::hash_enum
<sect_offset
>>
2670 debug_info_offset_to_per_cu
;
2671 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2673 const auto insertpair
2674 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2675 if (!insertpair
.second
)
2677 warning (_("Section .debug_aranges in %s has duplicate "
2678 "debug_info_offset %s, ignoring .debug_aranges."),
2679 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2684 section
->read (objfile
);
2686 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2688 const gdb_byte
*addr
= section
->buffer
;
2690 while (addr
< section
->buffer
+ section
->size
)
2692 const gdb_byte
*const entry_addr
= addr
;
2693 unsigned int bytes_read
;
2695 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2699 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2700 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2701 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2702 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2704 warning (_("Section .debug_aranges in %s entry at offset %s "
2705 "length %s exceeds section length %s, "
2706 "ignoring .debug_aranges."),
2707 objfile_name (objfile
),
2708 plongest (entry_addr
- section
->buffer
),
2709 plongest (bytes_read
+ entry_length
),
2710 pulongest (section
->size
));
2714 /* The version number. */
2715 const uint16_t version
= read_2_bytes (abfd
, addr
);
2719 warning (_("Section .debug_aranges in %s entry at offset %s "
2720 "has unsupported version %d, ignoring .debug_aranges."),
2721 objfile_name (objfile
),
2722 plongest (entry_addr
- section
->buffer
), version
);
2726 const uint64_t debug_info_offset
2727 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2728 addr
+= offset_size
;
2729 const auto per_cu_it
2730 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2731 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2733 warning (_("Section .debug_aranges in %s entry at offset %s "
2734 "debug_info_offset %s does not exists, "
2735 "ignoring .debug_aranges."),
2736 objfile_name (objfile
),
2737 plongest (entry_addr
- section
->buffer
),
2738 pulongest (debug_info_offset
));
2741 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2743 const uint8_t address_size
= *addr
++;
2744 if (address_size
< 1 || address_size
> 8)
2746 warning (_("Section .debug_aranges in %s entry at offset %s "
2747 "address_size %u is invalid, ignoring .debug_aranges."),
2748 objfile_name (objfile
),
2749 plongest (entry_addr
- section
->buffer
), address_size
);
2753 const uint8_t segment_selector_size
= *addr
++;
2754 if (segment_selector_size
!= 0)
2756 warning (_("Section .debug_aranges in %s entry at offset %s "
2757 "segment_selector_size %u is not supported, "
2758 "ignoring .debug_aranges."),
2759 objfile_name (objfile
),
2760 plongest (entry_addr
- section
->buffer
),
2761 segment_selector_size
);
2765 /* Must pad to an alignment boundary that is twice the address
2766 size. It is undocumented by the DWARF standard but GCC does
2768 for (size_t padding
= ((-(addr
- section
->buffer
))
2769 & (2 * address_size
- 1));
2770 padding
> 0; padding
--)
2773 warning (_("Section .debug_aranges in %s entry at offset %s "
2774 "padding is not zero, ignoring .debug_aranges."),
2775 objfile_name (objfile
),
2776 plongest (entry_addr
- section
->buffer
));
2782 if (addr
+ 2 * address_size
> entry_end
)
2784 warning (_("Section .debug_aranges in %s entry at offset %s "
2785 "address list is not properly terminated, "
2786 "ignoring .debug_aranges."),
2787 objfile_name (objfile
),
2788 plongest (entry_addr
- section
->buffer
));
2791 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2793 addr
+= address_size
;
2794 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2796 addr
+= address_size
;
2797 if (start
== 0 && length
== 0)
2799 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2801 /* Symbol was eliminated due to a COMDAT group. */
2804 ULONGEST end
= start
+ length
;
2805 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2807 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2809 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2813 objfile
->partial_symtabs
->psymtabs_addrmap
2814 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2817 /* Find a slot in the mapped index INDEX for the object named NAME.
2818 If NAME is found, set *VEC_OUT to point to the CU vector in the
2819 constant pool and return true. If NAME cannot be found, return
2823 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2824 offset_type
**vec_out
)
2827 offset_type slot
, step
;
2828 int (*cmp
) (const char *, const char *);
2830 gdb::unique_xmalloc_ptr
<char> without_params
;
2831 if (current_language
->la_language
== language_cplus
2832 || current_language
->la_language
== language_fortran
2833 || current_language
->la_language
== language_d
)
2835 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2838 if (strchr (name
, '(') != NULL
)
2840 without_params
= cp_remove_params (name
);
2842 if (without_params
!= NULL
)
2843 name
= without_params
.get ();
2847 /* Index version 4 did not support case insensitive searches. But the
2848 indices for case insensitive languages are built in lowercase, therefore
2849 simulate our NAME being searched is also lowercased. */
2850 hash
= mapped_index_string_hash ((index
->version
== 4
2851 && case_sensitivity
== case_sensitive_off
2852 ? 5 : index
->version
),
2855 slot
= hash
& (index
->symbol_table
.size () - 1);
2856 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2857 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2863 const auto &bucket
= index
->symbol_table
[slot
];
2864 if (bucket
.name
== 0 && bucket
.vec
== 0)
2867 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2868 if (!cmp (name
, str
))
2870 *vec_out
= (offset_type
*) (index
->constant_pool
2871 + MAYBE_SWAP (bucket
.vec
));
2875 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2879 /* A helper function that reads the .gdb_index from BUFFER and fills
2880 in MAP. FILENAME is the name of the file containing the data;
2881 it is used for error reporting. DEPRECATED_OK is true if it is
2882 ok to use deprecated sections.
2884 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2885 out parameters that are filled in with information about the CU and
2886 TU lists in the section.
2888 Returns true if all went well, false otherwise. */
2891 read_gdb_index_from_buffer (struct objfile
*objfile
,
2892 const char *filename
,
2894 gdb::array_view
<const gdb_byte
> buffer
,
2895 struct mapped_index
*map
,
2896 const gdb_byte
**cu_list
,
2897 offset_type
*cu_list_elements
,
2898 const gdb_byte
**types_list
,
2899 offset_type
*types_list_elements
)
2901 const gdb_byte
*addr
= &buffer
[0];
2903 /* Version check. */
2904 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2905 /* Versions earlier than 3 emitted every copy of a psymbol. This
2906 causes the index to behave very poorly for certain requests. Version 3
2907 contained incomplete addrmap. So, it seems better to just ignore such
2911 static int warning_printed
= 0;
2912 if (!warning_printed
)
2914 warning (_("Skipping obsolete .gdb_index section in %s."),
2916 warning_printed
= 1;
2920 /* Index version 4 uses a different hash function than index version
2923 Versions earlier than 6 did not emit psymbols for inlined
2924 functions. Using these files will cause GDB not to be able to
2925 set breakpoints on inlined functions by name, so we ignore these
2926 indices unless the user has done
2927 "set use-deprecated-index-sections on". */
2928 if (version
< 6 && !deprecated_ok
)
2930 static int warning_printed
= 0;
2931 if (!warning_printed
)
2934 Skipping deprecated .gdb_index section in %s.\n\
2935 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2936 to use the section anyway."),
2938 warning_printed
= 1;
2942 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2943 of the TU (for symbols coming from TUs),
2944 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2945 Plus gold-generated indices can have duplicate entries for global symbols,
2946 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2947 These are just performance bugs, and we can't distinguish gdb-generated
2948 indices from gold-generated ones, so issue no warning here. */
2950 /* Indexes with higher version than the one supported by GDB may be no
2951 longer backward compatible. */
2955 map
->version
= version
;
2957 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2960 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2961 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2965 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2966 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2967 - MAYBE_SWAP (metadata
[i
]))
2971 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2972 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2974 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2977 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2978 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2980 = gdb::array_view
<mapped_index::symbol_table_slot
>
2981 ((mapped_index::symbol_table_slot
*) symbol_table
,
2982 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2985 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2990 /* Callback types for dwarf2_read_gdb_index. */
2992 typedef gdb::function_view
2993 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2994 get_gdb_index_contents_ftype
;
2995 typedef gdb::function_view
2996 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2997 get_gdb_index_contents_dwz_ftype
;
2999 /* Read .gdb_index. If everything went ok, initialize the "quick"
3000 elements of all the CUs and return 1. Otherwise, return 0. */
3003 dwarf2_read_gdb_index
3004 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3005 get_gdb_index_contents_ftype get_gdb_index_contents
,
3006 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3008 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3009 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3010 struct dwz_file
*dwz
;
3011 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3013 gdb::array_view
<const gdb_byte
> main_index_contents
3014 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3016 if (main_index_contents
.empty ())
3019 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3020 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3021 use_deprecated_index_sections
,
3022 main_index_contents
, map
.get (), &cu_list
,
3023 &cu_list_elements
, &types_list
,
3024 &types_list_elements
))
3027 /* Don't use the index if it's empty. */
3028 if (map
->symbol_table
.empty ())
3031 /* If there is a .dwz file, read it so we can get its CU list as
3033 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3036 struct mapped_index dwz_map
;
3037 const gdb_byte
*dwz_types_ignore
;
3038 offset_type dwz_types_elements_ignore
;
3040 gdb::array_view
<const gdb_byte
> dwz_index_content
3041 = get_gdb_index_contents_dwz (objfile
, dwz
);
3043 if (dwz_index_content
.empty ())
3046 if (!read_gdb_index_from_buffer (objfile
,
3047 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3048 1, dwz_index_content
, &dwz_map
,
3049 &dwz_list
, &dwz_list_elements
,
3051 &dwz_types_elements_ignore
))
3053 warning (_("could not read '.gdb_index' section from %s; skipping"),
3054 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3059 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3060 dwz_list
, dwz_list_elements
);
3062 if (types_list_elements
)
3064 /* We can only handle a single .debug_types when we have an
3066 if (dwarf2_per_objfile
->types
.size () != 1)
3069 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3071 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3072 types_list
, types_list_elements
);
3075 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3077 dwarf2_per_objfile
->index_table
= std::move (map
);
3078 dwarf2_per_objfile
->using_index
= 1;
3079 dwarf2_per_objfile
->quick_file_names_table
=
3080 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3085 /* die_reader_func for dw2_get_file_names. */
3088 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3089 const gdb_byte
*info_ptr
,
3090 struct die_info
*comp_unit_die
)
3092 struct dwarf2_cu
*cu
= reader
->cu
;
3093 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3094 struct dwarf2_per_objfile
*dwarf2_per_objfile
3095 = cu
->per_cu
->dwarf2_per_objfile
;
3096 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3097 struct dwarf2_per_cu_data
*lh_cu
;
3098 struct attribute
*attr
;
3100 struct quick_file_names
*qfn
;
3102 gdb_assert (! this_cu
->is_debug_types
);
3104 /* Our callers never want to match partial units -- instead they
3105 will match the enclosing full CU. */
3106 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3108 this_cu
->v
.quick
->no_file_data
= 1;
3116 sect_offset line_offset
{};
3118 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3119 if (attr
!= nullptr)
3121 struct quick_file_names find_entry
;
3123 line_offset
= (sect_offset
) DW_UNSND (attr
);
3125 /* We may have already read in this line header (TU line header sharing).
3126 If we have we're done. */
3127 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3128 find_entry
.hash
.line_sect_off
= line_offset
;
3129 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3130 &find_entry
, INSERT
);
3133 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3137 lh
= dwarf_decode_line_header (line_offset
, cu
);
3141 lh_cu
->v
.quick
->no_file_data
= 1;
3145 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3146 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3147 qfn
->hash
.line_sect_off
= line_offset
;
3148 gdb_assert (slot
!= NULL
);
3151 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3154 if (strcmp (fnd
.name
, "<unknown>") != 0)
3157 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3159 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3161 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3162 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3163 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3164 fnd
.comp_dir
).release ();
3165 qfn
->real_names
= NULL
;
3167 lh_cu
->v
.quick
->file_names
= qfn
;
3170 /* A helper for the "quick" functions which attempts to read the line
3171 table for THIS_CU. */
3173 static struct quick_file_names
*
3174 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3176 /* This should never be called for TUs. */
3177 gdb_assert (! this_cu
->is_debug_types
);
3178 /* Nor type unit groups. */
3179 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3181 if (this_cu
->v
.quick
->file_names
!= NULL
)
3182 return this_cu
->v
.quick
->file_names
;
3183 /* If we know there is no line data, no point in looking again. */
3184 if (this_cu
->v
.quick
->no_file_data
)
3187 cutu_reader
reader (this_cu
);
3188 if (!reader
.dummy_p
)
3189 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3191 if (this_cu
->v
.quick
->no_file_data
)
3193 return this_cu
->v
.quick
->file_names
;
3196 /* A helper for the "quick" functions which computes and caches the
3197 real path for a given file name from the line table. */
3200 dw2_get_real_path (struct objfile
*objfile
,
3201 struct quick_file_names
*qfn
, int index
)
3203 if (qfn
->real_names
== NULL
)
3204 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3205 qfn
->num_file_names
, const char *);
3207 if (qfn
->real_names
[index
] == NULL
)
3208 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3210 return qfn
->real_names
[index
];
3213 static struct symtab
*
3214 dw2_find_last_source_symtab (struct objfile
*objfile
)
3216 struct dwarf2_per_objfile
*dwarf2_per_objfile
3217 = get_dwarf2_per_objfile (objfile
);
3218 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3219 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3224 return compunit_primary_filetab (cust
);
3227 /* Traversal function for dw2_forget_cached_source_info. */
3230 dw2_free_cached_file_names (void **slot
, void *info
)
3232 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3234 if (file_data
->real_names
)
3238 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3240 xfree ((void*) file_data
->real_names
[i
]);
3241 file_data
->real_names
[i
] = NULL
;
3249 dw2_forget_cached_source_info (struct objfile
*objfile
)
3251 struct dwarf2_per_objfile
*dwarf2_per_objfile
3252 = get_dwarf2_per_objfile (objfile
);
3254 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3255 dw2_free_cached_file_names
, NULL
);
3258 /* Helper function for dw2_map_symtabs_matching_filename that expands
3259 the symtabs and calls the iterator. */
3262 dw2_map_expand_apply (struct objfile
*objfile
,
3263 struct dwarf2_per_cu_data
*per_cu
,
3264 const char *name
, const char *real_path
,
3265 gdb::function_view
<bool (symtab
*)> callback
)
3267 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3269 /* Don't visit already-expanded CUs. */
3270 if (per_cu
->v
.quick
->compunit_symtab
)
3273 /* This may expand more than one symtab, and we want to iterate over
3275 dw2_instantiate_symtab (per_cu
, false);
3277 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3278 last_made
, callback
);
3281 /* Implementation of the map_symtabs_matching_filename method. */
3284 dw2_map_symtabs_matching_filename
3285 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3286 gdb::function_view
<bool (symtab
*)> callback
)
3288 const char *name_basename
= lbasename (name
);
3289 struct dwarf2_per_objfile
*dwarf2_per_objfile
3290 = get_dwarf2_per_objfile (objfile
);
3292 /* The rule is CUs specify all the files, including those used by
3293 any TU, so there's no need to scan TUs here. */
3295 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3297 /* We only need to look at symtabs not already expanded. */
3298 if (per_cu
->v
.quick
->compunit_symtab
)
3301 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3302 if (file_data
== NULL
)
3305 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3307 const char *this_name
= file_data
->file_names
[j
];
3308 const char *this_real_name
;
3310 if (compare_filenames_for_search (this_name
, name
))
3312 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3318 /* Before we invoke realpath, which can get expensive when many
3319 files are involved, do a quick comparison of the basenames. */
3320 if (! basenames_may_differ
3321 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3324 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3325 if (compare_filenames_for_search (this_real_name
, name
))
3327 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3333 if (real_path
!= NULL
)
3335 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3336 gdb_assert (IS_ABSOLUTE_PATH (name
));
3337 if (this_real_name
!= NULL
3338 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3340 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3352 /* Struct used to manage iterating over all CUs looking for a symbol. */
3354 struct dw2_symtab_iterator
3356 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3357 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3358 /* If set, only look for symbols that match that block. Valid values are
3359 GLOBAL_BLOCK and STATIC_BLOCK. */
3360 gdb::optional
<block_enum
> block_index
;
3361 /* The kind of symbol we're looking for. */
3363 /* The list of CUs from the index entry of the symbol,
3364 or NULL if not found. */
3366 /* The next element in VEC to look at. */
3368 /* The number of elements in VEC, or zero if there is no match. */
3370 /* Have we seen a global version of the symbol?
3371 If so we can ignore all further global instances.
3372 This is to work around gold/15646, inefficient gold-generated
3377 /* Initialize the index symtab iterator ITER. */
3380 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3381 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3382 gdb::optional
<block_enum
> block_index
,
3386 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3387 iter
->block_index
= block_index
;
3388 iter
->domain
= domain
;
3390 iter
->global_seen
= 0;
3392 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3394 /* index is NULL if OBJF_READNOW. */
3395 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3396 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3404 /* Return the next matching CU or NULL if there are no more. */
3406 static struct dwarf2_per_cu_data
*
3407 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3409 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3411 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3413 offset_type cu_index_and_attrs
=
3414 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3415 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3416 gdb_index_symbol_kind symbol_kind
=
3417 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3418 /* Only check the symbol attributes if they're present.
3419 Indices prior to version 7 don't record them,
3420 and indices >= 7 may elide them for certain symbols
3421 (gold does this). */
3423 (dwarf2_per_objfile
->index_table
->version
>= 7
3424 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3426 /* Don't crash on bad data. */
3427 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3428 + dwarf2_per_objfile
->all_type_units
.size ()))
3430 complaint (_(".gdb_index entry has bad CU index"
3432 objfile_name (dwarf2_per_objfile
->objfile
));
3436 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3438 /* Skip if already read in. */
3439 if (per_cu
->v
.quick
->compunit_symtab
)
3442 /* Check static vs global. */
3445 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3447 if (iter
->block_index
.has_value ())
3449 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3451 if (is_static
!= want_static
)
3455 /* Work around gold/15646. */
3456 if (!is_static
&& iter
->global_seen
)
3459 iter
->global_seen
= 1;
3462 /* Only check the symbol's kind if it has one. */
3465 switch (iter
->domain
)
3468 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3469 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3470 /* Some types are also in VAR_DOMAIN. */
3471 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3475 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3479 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3483 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3498 static struct compunit_symtab
*
3499 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3500 const char *name
, domain_enum domain
)
3502 struct compunit_symtab
*stab_best
= NULL
;
3503 struct dwarf2_per_objfile
*dwarf2_per_objfile
3504 = get_dwarf2_per_objfile (objfile
);
3506 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3508 struct dw2_symtab_iterator iter
;
3509 struct dwarf2_per_cu_data
*per_cu
;
3511 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3513 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3515 struct symbol
*sym
, *with_opaque
= NULL
;
3516 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3517 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3518 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3520 sym
= block_find_symbol (block
, name
, domain
,
3521 block_find_non_opaque_type_preferred
,
3524 /* Some caution must be observed with overloaded functions
3525 and methods, since the index will not contain any overload
3526 information (but NAME might contain it). */
3529 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3531 if (with_opaque
!= NULL
3532 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3535 /* Keep looking through other CUs. */
3542 dw2_print_stats (struct objfile
*objfile
)
3544 struct dwarf2_per_objfile
*dwarf2_per_objfile
3545 = get_dwarf2_per_objfile (objfile
);
3546 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3547 + dwarf2_per_objfile
->all_type_units
.size ());
3550 for (int i
= 0; i
< total
; ++i
)
3552 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3554 if (!per_cu
->v
.quick
->compunit_symtab
)
3557 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3558 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3561 /* This dumps minimal information about the index.
3562 It is called via "mt print objfiles".
3563 One use is to verify .gdb_index has been loaded by the
3564 gdb.dwarf2/gdb-index.exp testcase. */
3567 dw2_dump (struct objfile
*objfile
)
3569 struct dwarf2_per_objfile
*dwarf2_per_objfile
3570 = get_dwarf2_per_objfile (objfile
);
3572 gdb_assert (dwarf2_per_objfile
->using_index
);
3573 printf_filtered (".gdb_index:");
3574 if (dwarf2_per_objfile
->index_table
!= NULL
)
3576 printf_filtered (" version %d\n",
3577 dwarf2_per_objfile
->index_table
->version
);
3580 printf_filtered (" faked for \"readnow\"\n");
3581 printf_filtered ("\n");
3585 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3586 const char *func_name
)
3588 struct dwarf2_per_objfile
*dwarf2_per_objfile
3589 = get_dwarf2_per_objfile (objfile
);
3591 struct dw2_symtab_iterator iter
;
3592 struct dwarf2_per_cu_data
*per_cu
;
3594 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3596 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3597 dw2_instantiate_symtab (per_cu
, false);
3602 dw2_expand_all_symtabs (struct objfile
*objfile
)
3604 struct dwarf2_per_objfile
*dwarf2_per_objfile
3605 = get_dwarf2_per_objfile (objfile
);
3606 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3607 + dwarf2_per_objfile
->all_type_units
.size ());
3609 for (int i
= 0; i
< total_units
; ++i
)
3611 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3613 /* We don't want to directly expand a partial CU, because if we
3614 read it with the wrong language, then assertion failures can
3615 be triggered later on. See PR symtab/23010. So, tell
3616 dw2_instantiate_symtab to skip partial CUs -- any important
3617 partial CU will be read via DW_TAG_imported_unit anyway. */
3618 dw2_instantiate_symtab (per_cu
, true);
3623 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3624 const char *fullname
)
3626 struct dwarf2_per_objfile
*dwarf2_per_objfile
3627 = get_dwarf2_per_objfile (objfile
);
3629 /* We don't need to consider type units here.
3630 This is only called for examining code, e.g. expand_line_sal.
3631 There can be an order of magnitude (or more) more type units
3632 than comp units, and we avoid them if we can. */
3634 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3636 /* We only need to look at symtabs not already expanded. */
3637 if (per_cu
->v
.quick
->compunit_symtab
)
3640 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3641 if (file_data
== NULL
)
3644 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3646 const char *this_fullname
= file_data
->file_names
[j
];
3648 if (filename_cmp (this_fullname
, fullname
) == 0)
3650 dw2_instantiate_symtab (per_cu
, false);
3658 dw2_map_matching_symbols
3659 (struct objfile
*objfile
,
3660 const lookup_name_info
&name
, domain_enum domain
,
3662 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3663 symbol_compare_ftype
*ordered_compare
)
3665 /* Currently unimplemented; used for Ada. The function can be called if the
3666 current language is Ada for a non-Ada objfile using GNU index. As Ada
3667 does not look for non-Ada symbols this function should just return. */
3670 /* Starting from a search name, return the string that finds the upper
3671 bound of all strings that start with SEARCH_NAME in a sorted name
3672 list. Returns the empty string to indicate that the upper bound is
3673 the end of the list. */
3676 make_sort_after_prefix_name (const char *search_name
)
3678 /* When looking to complete "func", we find the upper bound of all
3679 symbols that start with "func" by looking for where we'd insert
3680 the closest string that would follow "func" in lexicographical
3681 order. Usually, that's "func"-with-last-character-incremented,
3682 i.e. "fund". Mind non-ASCII characters, though. Usually those
3683 will be UTF-8 multi-byte sequences, but we can't be certain.
3684 Especially mind the 0xff character, which is a valid character in
3685 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3686 rule out compilers allowing it in identifiers. Note that
3687 conveniently, strcmp/strcasecmp are specified to compare
3688 characters interpreted as unsigned char. So what we do is treat
3689 the whole string as a base 256 number composed of a sequence of
3690 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3691 to 0, and carries 1 to the following more-significant position.
3692 If the very first character in SEARCH_NAME ends up incremented
3693 and carries/overflows, then the upper bound is the end of the
3694 list. The string after the empty string is also the empty
3697 Some examples of this operation:
3699 SEARCH_NAME => "+1" RESULT
3703 "\xff" "a" "\xff" => "\xff" "b"
3708 Then, with these symbols for example:
3714 completing "func" looks for symbols between "func" and
3715 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3716 which finds "func" and "func1", but not "fund".
3720 funcÿ (Latin1 'ÿ' [0xff])
3724 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3725 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3729 ÿÿ (Latin1 'ÿ' [0xff])
3732 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3733 the end of the list.
3735 std::string after
= search_name
;
3736 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3738 if (!after
.empty ())
3739 after
.back () = (unsigned char) after
.back () + 1;
3743 /* See declaration. */
3745 std::pair
<std::vector
<name_component
>::const_iterator
,
3746 std::vector
<name_component
>::const_iterator
>
3747 mapped_index_base::find_name_components_bounds
3748 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3751 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3753 const char *lang_name
3754 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
3756 /* Comparison function object for lower_bound that matches against a
3757 given symbol name. */
3758 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3761 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3762 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3763 return name_cmp (elem_name
, name
) < 0;
3766 /* Comparison function object for upper_bound that matches against a
3767 given symbol name. */
3768 auto lookup_compare_upper
= [&] (const char *name
,
3769 const name_component
&elem
)
3771 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3772 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3773 return name_cmp (name
, elem_name
) < 0;
3776 auto begin
= this->name_components
.begin ();
3777 auto end
= this->name_components
.end ();
3779 /* Find the lower bound. */
3782 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3785 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3788 /* Find the upper bound. */
3791 if (lookup_name_without_params
.completion_mode ())
3793 /* In completion mode, we want UPPER to point past all
3794 symbols names that have the same prefix. I.e., with
3795 these symbols, and completing "func":
3797 function << lower bound
3799 other_function << upper bound
3801 We find the upper bound by looking for the insertion
3802 point of "func"-with-last-character-incremented,
3804 std::string after
= make_sort_after_prefix_name (lang_name
);
3807 return std::lower_bound (lower
, end
, after
.c_str (),
3808 lookup_compare_lower
);
3811 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3814 return {lower
, upper
};
3817 /* See declaration. */
3820 mapped_index_base::build_name_components ()
3822 if (!this->name_components
.empty ())
3825 this->name_components_casing
= case_sensitivity
;
3827 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3829 /* The code below only knows how to break apart components of C++
3830 symbol names (and other languages that use '::' as
3831 namespace/module separator) and Ada symbol names. */
3832 auto count
= this->symbol_name_count ();
3833 for (offset_type idx
= 0; idx
< count
; idx
++)
3835 if (this->symbol_name_slot_invalid (idx
))
3838 const char *name
= this->symbol_name_at (idx
);
3840 /* Add each name component to the name component table. */
3841 unsigned int previous_len
= 0;
3843 if (strstr (name
, "::") != nullptr)
3845 for (unsigned int current_len
= cp_find_first_component (name
);
3846 name
[current_len
] != '\0';
3847 current_len
+= cp_find_first_component (name
+ current_len
))
3849 gdb_assert (name
[current_len
] == ':');
3850 this->name_components
.push_back ({previous_len
, idx
});
3851 /* Skip the '::'. */
3853 previous_len
= current_len
;
3858 /* Handle the Ada encoded (aka mangled) form here. */
3859 for (const char *iter
= strstr (name
, "__");
3861 iter
= strstr (iter
, "__"))
3863 this->name_components
.push_back ({previous_len
, idx
});
3865 previous_len
= iter
- name
;
3869 this->name_components
.push_back ({previous_len
, idx
});
3872 /* Sort name_components elements by name. */
3873 auto name_comp_compare
= [&] (const name_component
&left
,
3874 const name_component
&right
)
3876 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3877 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3879 const char *left_name
= left_qualified
+ left
.name_offset
;
3880 const char *right_name
= right_qualified
+ right
.name_offset
;
3882 return name_cmp (left_name
, right_name
) < 0;
3885 std::sort (this->name_components
.begin (),
3886 this->name_components
.end (),
3890 /* Helper for dw2_expand_symtabs_matching that works with a
3891 mapped_index_base instead of the containing objfile. This is split
3892 to a separate function in order to be able to unit test the
3893 name_components matching using a mock mapped_index_base. For each
3894 symbol name that matches, calls MATCH_CALLBACK, passing it the
3895 symbol's index in the mapped_index_base symbol table. */
3898 dw2_expand_symtabs_matching_symbol
3899 (mapped_index_base
&index
,
3900 const lookup_name_info
&lookup_name_in
,
3901 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3902 enum search_domain kind
,
3903 gdb::function_view
<bool (offset_type
)> match_callback
)
3905 lookup_name_info lookup_name_without_params
3906 = lookup_name_in
.make_ignore_params ();
3908 /* Build the symbol name component sorted vector, if we haven't
3910 index
.build_name_components ();
3912 /* The same symbol may appear more than once in the range though.
3913 E.g., if we're looking for symbols that complete "w", and we have
3914 a symbol named "w1::w2", we'll find the two name components for
3915 that same symbol in the range. To be sure we only call the
3916 callback once per symbol, we first collect the symbol name
3917 indexes that matched in a temporary vector and ignore
3919 std::vector
<offset_type
> matches
;
3921 struct name_and_matcher
3923 symbol_name_matcher_ftype
*matcher
;
3924 const std::string
&name
;
3926 bool operator== (const name_and_matcher
&other
) const
3928 return matcher
== other
.matcher
&& name
== other
.name
;
3932 /* A vector holding all the different symbol name matchers, for all
3934 std::vector
<name_and_matcher
> matchers
;
3936 for (int i
= 0; i
< nr_languages
; i
++)
3938 enum language lang_e
= (enum language
) i
;
3940 const language_defn
*lang
= language_def (lang_e
);
3941 symbol_name_matcher_ftype
*name_matcher
3942 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3944 name_and_matcher key
{
3946 lookup_name_without_params
.language_lookup_name (lang_e
)
3949 /* Don't insert the same comparison routine more than once.
3950 Note that we do this linear walk. This is not a problem in
3951 practice because the number of supported languages is
3953 if (std::find (matchers
.begin (), matchers
.end (), key
)
3956 matchers
.push_back (std::move (key
));
3959 = index
.find_name_components_bounds (lookup_name_without_params
,
3962 /* Now for each symbol name in range, check to see if we have a name
3963 match, and if so, call the MATCH_CALLBACK callback. */
3965 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3967 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3969 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3970 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3973 matches
.push_back (bounds
.first
->idx
);
3977 std::sort (matches
.begin (), matches
.end ());
3979 /* Finally call the callback, once per match. */
3981 for (offset_type idx
: matches
)
3985 if (!match_callback (idx
))
3991 /* Above we use a type wider than idx's for 'prev', since 0 and
3992 (offset_type)-1 are both possible values. */
3993 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3998 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4000 /* A mock .gdb_index/.debug_names-like name index table, enough to
4001 exercise dw2_expand_symtabs_matching_symbol, which works with the
4002 mapped_index_base interface. Builds an index from the symbol list
4003 passed as parameter to the constructor. */
4004 class mock_mapped_index
: public mapped_index_base
4007 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4008 : m_symbol_table (symbols
)
4011 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4013 /* Return the number of names in the symbol table. */
4014 size_t symbol_name_count () const override
4016 return m_symbol_table
.size ();
4019 /* Get the name of the symbol at IDX in the symbol table. */
4020 const char *symbol_name_at (offset_type idx
) const override
4022 return m_symbol_table
[idx
];
4026 gdb::array_view
<const char *> m_symbol_table
;
4029 /* Convenience function that converts a NULL pointer to a "<null>"
4030 string, to pass to print routines. */
4033 string_or_null (const char *str
)
4035 return str
!= NULL
? str
: "<null>";
4038 /* Check if a lookup_name_info built from
4039 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4040 index. EXPECTED_LIST is the list of expected matches, in expected
4041 matching order. If no match expected, then an empty list is
4042 specified. Returns true on success. On failure prints a warning
4043 indicating the file:line that failed, and returns false. */
4046 check_match (const char *file
, int line
,
4047 mock_mapped_index
&mock_index
,
4048 const char *name
, symbol_name_match_type match_type
,
4049 bool completion_mode
,
4050 std::initializer_list
<const char *> expected_list
)
4052 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4054 bool matched
= true;
4056 auto mismatch
= [&] (const char *expected_str
,
4059 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4060 "expected=\"%s\", got=\"%s\"\n"),
4062 (match_type
== symbol_name_match_type::FULL
4064 name
, string_or_null (expected_str
), string_or_null (got
));
4068 auto expected_it
= expected_list
.begin ();
4069 auto expected_end
= expected_list
.end ();
4071 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4073 [&] (offset_type idx
)
4075 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4076 const char *expected_str
4077 = expected_it
== expected_end
? NULL
: *expected_it
++;
4079 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4080 mismatch (expected_str
, matched_name
);
4084 const char *expected_str
4085 = expected_it
== expected_end
? NULL
: *expected_it
++;
4086 if (expected_str
!= NULL
)
4087 mismatch (expected_str
, NULL
);
4092 /* The symbols added to the mock mapped_index for testing (in
4094 static const char *test_symbols
[] = {
4103 "ns2::tmpl<int>::foo2",
4104 "(anonymous namespace)::A::B::C",
4106 /* These are used to check that the increment-last-char in the
4107 matching algorithm for completion doesn't match "t1_fund" when
4108 completing "t1_func". */
4114 /* A UTF-8 name with multi-byte sequences to make sure that
4115 cp-name-parser understands this as a single identifier ("função"
4116 is "function" in PT). */
4119 /* \377 (0xff) is Latin1 'ÿ'. */
4122 /* \377 (0xff) is Latin1 'ÿ'. */
4126 /* A name with all sorts of complications. Starts with "z" to make
4127 it easier for the completion tests below. */
4128 #define Z_SYM_NAME \
4129 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4130 "::tuple<(anonymous namespace)::ui*, " \
4131 "std::default_delete<(anonymous namespace)::ui>, void>"
4136 /* Returns true if the mapped_index_base::find_name_component_bounds
4137 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4138 in completion mode. */
4141 check_find_bounds_finds (mapped_index_base
&index
,
4142 const char *search_name
,
4143 gdb::array_view
<const char *> expected_syms
)
4145 lookup_name_info
lookup_name (search_name
,
4146 symbol_name_match_type::FULL
, true);
4148 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4151 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4152 if (distance
!= expected_syms
.size ())
4155 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4157 auto nc_elem
= bounds
.first
+ exp_elem
;
4158 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4159 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4166 /* Test the lower-level mapped_index::find_name_component_bounds
4170 test_mapped_index_find_name_component_bounds ()
4172 mock_mapped_index
mock_index (test_symbols
);
4174 mock_index
.build_name_components ();
4176 /* Test the lower-level mapped_index::find_name_component_bounds
4177 method in completion mode. */
4179 static const char *expected_syms
[] = {
4184 SELF_CHECK (check_find_bounds_finds (mock_index
,
4185 "t1_func", expected_syms
));
4188 /* Check that the increment-last-char in the name matching algorithm
4189 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4191 static const char *expected_syms1
[] = {
4195 SELF_CHECK (check_find_bounds_finds (mock_index
,
4196 "\377", expected_syms1
));
4198 static const char *expected_syms2
[] = {
4201 SELF_CHECK (check_find_bounds_finds (mock_index
,
4202 "\377\377", expected_syms2
));
4206 /* Test dw2_expand_symtabs_matching_symbol. */
4209 test_dw2_expand_symtabs_matching_symbol ()
4211 mock_mapped_index
mock_index (test_symbols
);
4213 /* We let all tests run until the end even if some fails, for debug
4215 bool any_mismatch
= false;
4217 /* Create the expected symbols list (an initializer_list). Needed
4218 because lists have commas, and we need to pass them to CHECK,
4219 which is a macro. */
4220 #define EXPECT(...) { __VA_ARGS__ }
4222 /* Wrapper for check_match that passes down the current
4223 __FILE__/__LINE__. */
4224 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4225 any_mismatch |= !check_match (__FILE__, __LINE__, \
4227 NAME, MATCH_TYPE, COMPLETION_MODE, \
4230 /* Identity checks. */
4231 for (const char *sym
: test_symbols
)
4233 /* Should be able to match all existing symbols. */
4234 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4237 /* Should be able to match all existing symbols with
4239 std::string with_params
= std::string (sym
) + "(int)";
4240 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4243 /* Should be able to match all existing symbols with
4244 parameters and qualifiers. */
4245 with_params
= std::string (sym
) + " ( int ) const";
4246 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4249 /* This should really find sym, but cp-name-parser.y doesn't
4250 know about lvalue/rvalue qualifiers yet. */
4251 with_params
= std::string (sym
) + " ( int ) &&";
4252 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4256 /* Check that the name matching algorithm for completion doesn't get
4257 confused with Latin1 'ÿ' / 0xff. */
4259 static const char str
[] = "\377";
4260 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4261 EXPECT ("\377", "\377\377123"));
4264 /* Check that the increment-last-char in the matching algorithm for
4265 completion doesn't match "t1_fund" when completing "t1_func". */
4267 static const char str
[] = "t1_func";
4268 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4269 EXPECT ("t1_func", "t1_func1"));
4272 /* Check that completion mode works at each prefix of the expected
4275 static const char str
[] = "function(int)";
4276 size_t len
= strlen (str
);
4279 for (size_t i
= 1; i
< len
; i
++)
4281 lookup
.assign (str
, i
);
4282 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4283 EXPECT ("function"));
4287 /* While "w" is a prefix of both components, the match function
4288 should still only be called once. */
4290 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4292 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4296 /* Same, with a "complicated" symbol. */
4298 static const char str
[] = Z_SYM_NAME
;
4299 size_t len
= strlen (str
);
4302 for (size_t i
= 1; i
< len
; i
++)
4304 lookup
.assign (str
, i
);
4305 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4306 EXPECT (Z_SYM_NAME
));
4310 /* In FULL mode, an incomplete symbol doesn't match. */
4312 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4316 /* A complete symbol with parameters matches any overload, since the
4317 index has no overload info. */
4319 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4320 EXPECT ("std::zfunction", "std::zfunction2"));
4321 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4322 EXPECT ("std::zfunction", "std::zfunction2"));
4323 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4324 EXPECT ("std::zfunction", "std::zfunction2"));
4327 /* Check that whitespace is ignored appropriately. A symbol with a
4328 template argument list. */
4330 static const char expected
[] = "ns::foo<int>";
4331 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4333 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4337 /* Check that whitespace is ignored appropriately. A symbol with a
4338 template argument list that includes a pointer. */
4340 static const char expected
[] = "ns::foo<char*>";
4341 /* Try both completion and non-completion modes. */
4342 static const bool completion_mode
[2] = {false, true};
4343 for (size_t i
= 0; i
< 2; i
++)
4345 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4346 completion_mode
[i
], EXPECT (expected
));
4347 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4348 completion_mode
[i
], EXPECT (expected
));
4350 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4351 completion_mode
[i
], EXPECT (expected
));
4352 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4353 completion_mode
[i
], EXPECT (expected
));
4358 /* Check method qualifiers are ignored. */
4359 static const char expected
[] = "ns::foo<char*>";
4360 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4361 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4362 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4363 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4364 CHECK_MATCH ("foo < char * > ( int ) const",
4365 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4366 CHECK_MATCH ("foo < char * > ( int ) &&",
4367 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4370 /* Test lookup names that don't match anything. */
4372 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4375 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4379 /* Some wild matching tests, exercising "(anonymous namespace)",
4380 which should not be confused with a parameter list. */
4382 static const char *syms
[] = {
4386 "A :: B :: C ( int )",
4391 for (const char *s
: syms
)
4393 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4394 EXPECT ("(anonymous namespace)::A::B::C"));
4399 static const char expected
[] = "ns2::tmpl<int>::foo2";
4400 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4402 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4406 SELF_CHECK (!any_mismatch
);
4415 test_mapped_index_find_name_component_bounds ();
4416 test_dw2_expand_symtabs_matching_symbol ();
4419 }} // namespace selftests::dw2_expand_symtabs_matching
4421 #endif /* GDB_SELF_TEST */
4423 /* If FILE_MATCHER is NULL or if PER_CU has
4424 dwarf2_per_cu_quick_data::MARK set (see
4425 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4426 EXPANSION_NOTIFY on it. */
4429 dw2_expand_symtabs_matching_one
4430 (struct dwarf2_per_cu_data
*per_cu
,
4431 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4432 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4434 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4436 bool symtab_was_null
4437 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4439 dw2_instantiate_symtab (per_cu
, false);
4441 if (expansion_notify
!= NULL
4443 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4444 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4448 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4449 matched, to expand corresponding CUs that were marked. IDX is the
4450 index of the symbol name that matched. */
4453 dw2_expand_marked_cus
4454 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4455 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4456 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4459 offset_type
*vec
, vec_len
, vec_idx
;
4460 bool global_seen
= false;
4461 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4463 vec
= (offset_type
*) (index
.constant_pool
4464 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4465 vec_len
= MAYBE_SWAP (vec
[0]);
4466 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4468 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4469 /* This value is only valid for index versions >= 7. */
4470 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4471 gdb_index_symbol_kind symbol_kind
=
4472 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4473 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4474 /* Only check the symbol attributes if they're present.
4475 Indices prior to version 7 don't record them,
4476 and indices >= 7 may elide them for certain symbols
4477 (gold does this). */
4480 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4482 /* Work around gold/15646. */
4485 if (!is_static
&& global_seen
)
4491 /* Only check the symbol's kind if it has one. */
4496 case VARIABLES_DOMAIN
:
4497 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4500 case FUNCTIONS_DOMAIN
:
4501 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4505 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4508 case MODULES_DOMAIN
:
4509 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4517 /* Don't crash on bad data. */
4518 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4519 + dwarf2_per_objfile
->all_type_units
.size ()))
4521 complaint (_(".gdb_index entry has bad CU index"
4523 objfile_name (dwarf2_per_objfile
->objfile
));
4527 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4528 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4533 /* If FILE_MATCHER is non-NULL, set all the
4534 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4535 that match FILE_MATCHER. */
4538 dw_expand_symtabs_matching_file_matcher
4539 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4540 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4542 if (file_matcher
== NULL
)
4545 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4547 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4549 NULL
, xcalloc
, xfree
));
4550 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4552 NULL
, xcalloc
, xfree
));
4554 /* The rule is CUs specify all the files, including those used by
4555 any TU, so there's no need to scan TUs here. */
4557 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4561 per_cu
->v
.quick
->mark
= 0;
4563 /* We only need to look at symtabs not already expanded. */
4564 if (per_cu
->v
.quick
->compunit_symtab
)
4567 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4568 if (file_data
== NULL
)
4571 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4573 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4575 per_cu
->v
.quick
->mark
= 1;
4579 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4581 const char *this_real_name
;
4583 if (file_matcher (file_data
->file_names
[j
], false))
4585 per_cu
->v
.quick
->mark
= 1;
4589 /* Before we invoke realpath, which can get expensive when many
4590 files are involved, do a quick comparison of the basenames. */
4591 if (!basenames_may_differ
4592 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4596 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4597 if (file_matcher (this_real_name
, false))
4599 per_cu
->v
.quick
->mark
= 1;
4604 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4605 ? visited_found
.get ()
4606 : visited_not_found
.get (),
4613 dw2_expand_symtabs_matching
4614 (struct objfile
*objfile
,
4615 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4616 const lookup_name_info
&lookup_name
,
4617 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4618 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4619 enum search_domain kind
)
4621 struct dwarf2_per_objfile
*dwarf2_per_objfile
4622 = get_dwarf2_per_objfile (objfile
);
4624 /* index_table is NULL if OBJF_READNOW. */
4625 if (!dwarf2_per_objfile
->index_table
)
4628 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4630 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4632 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4634 kind
, [&] (offset_type idx
)
4636 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4637 expansion_notify
, kind
);
4642 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4645 static struct compunit_symtab
*
4646 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4651 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4652 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4655 if (cust
->includes
== NULL
)
4658 for (i
= 0; cust
->includes
[i
]; ++i
)
4660 struct compunit_symtab
*s
= cust
->includes
[i
];
4662 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4670 static struct compunit_symtab
*
4671 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4672 struct bound_minimal_symbol msymbol
,
4674 struct obj_section
*section
,
4677 struct dwarf2_per_cu_data
*data
;
4678 struct compunit_symtab
*result
;
4680 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4683 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4684 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4685 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4689 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4690 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4691 paddress (get_objfile_arch (objfile
), pc
));
4694 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4697 gdb_assert (result
!= NULL
);
4702 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4703 void *data
, int need_fullname
)
4705 struct dwarf2_per_objfile
*dwarf2_per_objfile
4706 = get_dwarf2_per_objfile (objfile
);
4708 if (!dwarf2_per_objfile
->filenames_cache
)
4710 dwarf2_per_objfile
->filenames_cache
.emplace ();
4712 htab_up
visited (htab_create_alloc (10,
4713 htab_hash_pointer
, htab_eq_pointer
,
4714 NULL
, xcalloc
, xfree
));
4716 /* The rule is CUs specify all the files, including those used
4717 by any TU, so there's no need to scan TUs here. We can
4718 ignore file names coming from already-expanded CUs. */
4720 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4722 if (per_cu
->v
.quick
->compunit_symtab
)
4724 void **slot
= htab_find_slot (visited
.get (),
4725 per_cu
->v
.quick
->file_names
,
4728 *slot
= per_cu
->v
.quick
->file_names
;
4732 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4734 /* We only need to look at symtabs not already expanded. */
4735 if (per_cu
->v
.quick
->compunit_symtab
)
4738 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4739 if (file_data
== NULL
)
4742 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4745 /* Already visited. */
4750 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4752 const char *filename
= file_data
->file_names
[j
];
4753 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4758 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4760 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4763 this_real_name
= gdb_realpath (filename
);
4764 (*fun
) (filename
, this_real_name
.get (), data
);
4769 dw2_has_symbols (struct objfile
*objfile
)
4774 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4777 dw2_find_last_source_symtab
,
4778 dw2_forget_cached_source_info
,
4779 dw2_map_symtabs_matching_filename
,
4783 dw2_expand_symtabs_for_function
,
4784 dw2_expand_all_symtabs
,
4785 dw2_expand_symtabs_with_fullname
,
4786 dw2_map_matching_symbols
,
4787 dw2_expand_symtabs_matching
,
4788 dw2_find_pc_sect_compunit_symtab
,
4790 dw2_map_symbol_filenames
4793 /* DWARF-5 debug_names reader. */
4795 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4796 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4798 /* A helper function that reads the .debug_names section in SECTION
4799 and fills in MAP. FILENAME is the name of the file containing the
4800 section; it is used for error reporting.
4802 Returns true if all went well, false otherwise. */
4805 read_debug_names_from_section (struct objfile
*objfile
,
4806 const char *filename
,
4807 struct dwarf2_section_info
*section
,
4808 mapped_debug_names
&map
)
4810 if (section
->empty ())
4813 /* Older elfutils strip versions could keep the section in the main
4814 executable while splitting it for the separate debug info file. */
4815 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4818 section
->read (objfile
);
4820 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4822 const gdb_byte
*addr
= section
->buffer
;
4824 bfd
*const abfd
= section
->get_bfd_owner ();
4826 unsigned int bytes_read
;
4827 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4830 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4831 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4832 if (bytes_read
+ length
!= section
->size
)
4834 /* There may be multiple per-CU indices. */
4835 warning (_("Section .debug_names in %s length %s does not match "
4836 "section length %s, ignoring .debug_names."),
4837 filename
, plongest (bytes_read
+ length
),
4838 pulongest (section
->size
));
4842 /* The version number. */
4843 uint16_t version
= read_2_bytes (abfd
, addr
);
4847 warning (_("Section .debug_names in %s has unsupported version %d, "
4848 "ignoring .debug_names."),
4854 uint16_t padding
= read_2_bytes (abfd
, addr
);
4858 warning (_("Section .debug_names in %s has unsupported padding %d, "
4859 "ignoring .debug_names."),
4864 /* comp_unit_count - The number of CUs in the CU list. */
4865 map
.cu_count
= read_4_bytes (abfd
, addr
);
4868 /* local_type_unit_count - The number of TUs in the local TU
4870 map
.tu_count
= read_4_bytes (abfd
, addr
);
4873 /* foreign_type_unit_count - The number of TUs in the foreign TU
4875 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4877 if (foreign_tu_count
!= 0)
4879 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4880 "ignoring .debug_names."),
4881 filename
, static_cast<unsigned long> (foreign_tu_count
));
4885 /* bucket_count - The number of hash buckets in the hash lookup
4887 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4890 /* name_count - The number of unique names in the index. */
4891 map
.name_count
= read_4_bytes (abfd
, addr
);
4894 /* abbrev_table_size - The size in bytes of the abbreviations
4896 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4899 /* augmentation_string_size - The size in bytes of the augmentation
4900 string. This value is rounded up to a multiple of 4. */
4901 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4903 map
.augmentation_is_gdb
= ((augmentation_string_size
4904 == sizeof (dwarf5_augmentation
))
4905 && memcmp (addr
, dwarf5_augmentation
,
4906 sizeof (dwarf5_augmentation
)) == 0);
4907 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4908 addr
+= augmentation_string_size
;
4911 map
.cu_table_reordered
= addr
;
4912 addr
+= map
.cu_count
* map
.offset_size
;
4914 /* List of Local TUs */
4915 map
.tu_table_reordered
= addr
;
4916 addr
+= map
.tu_count
* map
.offset_size
;
4918 /* Hash Lookup Table */
4919 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4920 addr
+= map
.bucket_count
* 4;
4921 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4922 addr
+= map
.name_count
* 4;
4925 map
.name_table_string_offs_reordered
= addr
;
4926 addr
+= map
.name_count
* map
.offset_size
;
4927 map
.name_table_entry_offs_reordered
= addr
;
4928 addr
+= map
.name_count
* map
.offset_size
;
4930 const gdb_byte
*abbrev_table_start
= addr
;
4933 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4938 const auto insertpair
4939 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4940 if (!insertpair
.second
)
4942 warning (_("Section .debug_names in %s has duplicate index %s, "
4943 "ignoring .debug_names."),
4944 filename
, pulongest (index_num
));
4947 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4948 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4953 mapped_debug_names::index_val::attr attr
;
4954 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4956 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4958 if (attr
.form
== DW_FORM_implicit_const
)
4960 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4964 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4966 indexval
.attr_vec
.push_back (std::move (attr
));
4969 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4971 warning (_("Section .debug_names in %s has abbreviation_table "
4972 "of size %s vs. written as %u, ignoring .debug_names."),
4973 filename
, plongest (addr
- abbrev_table_start
),
4977 map
.entry_pool
= addr
;
4982 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4986 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4987 const mapped_debug_names
&map
,
4988 dwarf2_section_info
§ion
,
4991 sect_offset sect_off_prev
;
4992 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4994 sect_offset sect_off_next
;
4995 if (i
< map
.cu_count
)
4998 = (sect_offset
) (extract_unsigned_integer
4999 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5001 map
.dwarf5_byte_order
));
5004 sect_off_next
= (sect_offset
) section
.size
;
5007 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5008 dwarf2_per_cu_data
*per_cu
5009 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5010 sect_off_prev
, length
);
5011 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5013 sect_off_prev
= sect_off_next
;
5017 /* Read the CU list from the mapped index, and use it to create all
5018 the CU objects for this dwarf2_per_objfile. */
5021 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5022 const mapped_debug_names
&map
,
5023 const mapped_debug_names
&dwz_map
)
5025 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5026 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5028 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5029 dwarf2_per_objfile
->info
,
5030 false /* is_dwz */);
5032 if (dwz_map
.cu_count
== 0)
5035 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5036 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5040 /* Read .debug_names. If everything went ok, initialize the "quick"
5041 elements of all the CUs and return true. Otherwise, return false. */
5044 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5046 std::unique_ptr
<mapped_debug_names
> map
5047 (new mapped_debug_names (dwarf2_per_objfile
));
5048 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5049 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5051 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5052 &dwarf2_per_objfile
->debug_names
,
5056 /* Don't use the index if it's empty. */
5057 if (map
->name_count
== 0)
5060 /* If there is a .dwz file, read it so we can get its CU list as
5062 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5065 if (!read_debug_names_from_section (objfile
,
5066 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5067 &dwz
->debug_names
, dwz_map
))
5069 warning (_("could not read '.debug_names' section from %s; skipping"),
5070 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5075 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5077 if (map
->tu_count
!= 0)
5079 /* We can only handle a single .debug_types when we have an
5081 if (dwarf2_per_objfile
->types
.size () != 1)
5084 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5086 create_signatured_type_table_from_debug_names
5087 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5090 create_addrmap_from_aranges (dwarf2_per_objfile
,
5091 &dwarf2_per_objfile
->debug_aranges
);
5093 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5094 dwarf2_per_objfile
->using_index
= 1;
5095 dwarf2_per_objfile
->quick_file_names_table
=
5096 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5101 /* Type used to manage iterating over all CUs looking for a symbol for
5104 class dw2_debug_names_iterator
5107 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5108 gdb::optional
<block_enum
> block_index
,
5111 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5112 m_addr (find_vec_in_debug_names (map
, name
))
5115 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5116 search_domain search
, uint32_t namei
)
5119 m_addr (find_vec_in_debug_names (map
, namei
))
5122 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5123 block_enum block_index
, domain_enum domain
,
5125 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5126 m_addr (find_vec_in_debug_names (map
, namei
))
5129 /* Return the next matching CU or NULL if there are no more. */
5130 dwarf2_per_cu_data
*next ();
5133 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5135 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5138 /* The internalized form of .debug_names. */
5139 const mapped_debug_names
&m_map
;
5141 /* If set, only look for symbols that match that block. Valid values are
5142 GLOBAL_BLOCK and STATIC_BLOCK. */
5143 const gdb::optional
<block_enum
> m_block_index
;
5145 /* The kind of symbol we're looking for. */
5146 const domain_enum m_domain
= UNDEF_DOMAIN
;
5147 const search_domain m_search
= ALL_DOMAIN
;
5149 /* The list of CUs from the index entry of the symbol, or NULL if
5151 const gdb_byte
*m_addr
;
5155 mapped_debug_names::namei_to_name (uint32_t namei
) const
5157 const ULONGEST namei_string_offs
5158 = extract_unsigned_integer ((name_table_string_offs_reordered
5159 + namei
* offset_size
),
5162 return read_indirect_string_at_offset
5163 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5166 /* Find a slot in .debug_names for the object named NAME. If NAME is
5167 found, return pointer to its pool data. If NAME cannot be found,
5171 dw2_debug_names_iterator::find_vec_in_debug_names
5172 (const mapped_debug_names
&map
, const char *name
)
5174 int (*cmp
) (const char *, const char *);
5176 gdb::unique_xmalloc_ptr
<char> without_params
;
5177 if (current_language
->la_language
== language_cplus
5178 || current_language
->la_language
== language_fortran
5179 || current_language
->la_language
== language_d
)
5181 /* NAME is already canonical. Drop any qualifiers as
5182 .debug_names does not contain any. */
5184 if (strchr (name
, '(') != NULL
)
5186 without_params
= cp_remove_params (name
);
5187 if (without_params
!= NULL
)
5188 name
= without_params
.get ();
5192 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5194 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5196 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5197 (map
.bucket_table_reordered
5198 + (full_hash
% map
.bucket_count
)), 4,
5199 map
.dwarf5_byte_order
);
5203 if (namei
>= map
.name_count
)
5205 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5207 namei
, map
.name_count
,
5208 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5214 const uint32_t namei_full_hash
5215 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5216 (map
.hash_table_reordered
+ namei
), 4,
5217 map
.dwarf5_byte_order
);
5218 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5221 if (full_hash
== namei_full_hash
)
5223 const char *const namei_string
= map
.namei_to_name (namei
);
5225 #if 0 /* An expensive sanity check. */
5226 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5228 complaint (_("Wrong .debug_names hash for string at index %u "
5230 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5235 if (cmp (namei_string
, name
) == 0)
5237 const ULONGEST namei_entry_offs
5238 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5239 + namei
* map
.offset_size
),
5240 map
.offset_size
, map
.dwarf5_byte_order
);
5241 return map
.entry_pool
+ namei_entry_offs
;
5246 if (namei
>= map
.name_count
)
5252 dw2_debug_names_iterator::find_vec_in_debug_names
5253 (const mapped_debug_names
&map
, uint32_t namei
)
5255 if (namei
>= map
.name_count
)
5257 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5259 namei
, map
.name_count
,
5260 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5264 const ULONGEST namei_entry_offs
5265 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5266 + namei
* map
.offset_size
),
5267 map
.offset_size
, map
.dwarf5_byte_order
);
5268 return map
.entry_pool
+ namei_entry_offs
;
5271 /* See dw2_debug_names_iterator. */
5273 dwarf2_per_cu_data
*
5274 dw2_debug_names_iterator::next ()
5279 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5280 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5281 bfd
*const abfd
= objfile
->obfd
;
5285 unsigned int bytes_read
;
5286 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5287 m_addr
+= bytes_read
;
5291 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5292 if (indexval_it
== m_map
.abbrev_map
.cend ())
5294 complaint (_("Wrong .debug_names undefined abbrev code %s "
5296 pulongest (abbrev
), objfile_name (objfile
));
5299 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5300 enum class symbol_linkage
{
5304 } symbol_linkage_
= symbol_linkage::unknown
;
5305 dwarf2_per_cu_data
*per_cu
= NULL
;
5306 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5311 case DW_FORM_implicit_const
:
5312 ull
= attr
.implicit_const
;
5314 case DW_FORM_flag_present
:
5318 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5319 m_addr
+= bytes_read
;
5322 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5323 dwarf_form_name (attr
.form
),
5324 objfile_name (objfile
));
5327 switch (attr
.dw_idx
)
5329 case DW_IDX_compile_unit
:
5330 /* Don't crash on bad data. */
5331 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5333 complaint (_(".debug_names entry has bad CU index %s"
5336 objfile_name (dwarf2_per_objfile
->objfile
));
5339 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5341 case DW_IDX_type_unit
:
5342 /* Don't crash on bad data. */
5343 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5345 complaint (_(".debug_names entry has bad TU index %s"
5348 objfile_name (dwarf2_per_objfile
->objfile
));
5351 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5353 case DW_IDX_GNU_internal
:
5354 if (!m_map
.augmentation_is_gdb
)
5356 symbol_linkage_
= symbol_linkage::static_
;
5358 case DW_IDX_GNU_external
:
5359 if (!m_map
.augmentation_is_gdb
)
5361 symbol_linkage_
= symbol_linkage::extern_
;
5366 /* Skip if already read in. */
5367 if (per_cu
->v
.quick
->compunit_symtab
)
5370 /* Check static vs global. */
5371 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5373 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5374 const bool symbol_is_static
=
5375 symbol_linkage_
== symbol_linkage::static_
;
5376 if (want_static
!= symbol_is_static
)
5380 /* Match dw2_symtab_iter_next, symbol_kind
5381 and debug_names::psymbol_tag. */
5385 switch (indexval
.dwarf_tag
)
5387 case DW_TAG_variable
:
5388 case DW_TAG_subprogram
:
5389 /* Some types are also in VAR_DOMAIN. */
5390 case DW_TAG_typedef
:
5391 case DW_TAG_structure_type
:
5398 switch (indexval
.dwarf_tag
)
5400 case DW_TAG_typedef
:
5401 case DW_TAG_structure_type
:
5408 switch (indexval
.dwarf_tag
)
5411 case DW_TAG_variable
:
5418 switch (indexval
.dwarf_tag
)
5430 /* Match dw2_expand_symtabs_matching, symbol_kind and
5431 debug_names::psymbol_tag. */
5434 case VARIABLES_DOMAIN
:
5435 switch (indexval
.dwarf_tag
)
5437 case DW_TAG_variable
:
5443 case FUNCTIONS_DOMAIN
:
5444 switch (indexval
.dwarf_tag
)
5446 case DW_TAG_subprogram
:
5453 switch (indexval
.dwarf_tag
)
5455 case DW_TAG_typedef
:
5456 case DW_TAG_structure_type
:
5462 case MODULES_DOMAIN
:
5463 switch (indexval
.dwarf_tag
)
5477 static struct compunit_symtab
*
5478 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5479 const char *name
, domain_enum domain
)
5481 struct dwarf2_per_objfile
*dwarf2_per_objfile
5482 = get_dwarf2_per_objfile (objfile
);
5484 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5487 /* index is NULL if OBJF_READNOW. */
5490 const auto &map
= *mapp
;
5492 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5494 struct compunit_symtab
*stab_best
= NULL
;
5495 struct dwarf2_per_cu_data
*per_cu
;
5496 while ((per_cu
= iter
.next ()) != NULL
)
5498 struct symbol
*sym
, *with_opaque
= NULL
;
5499 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5500 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5501 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5503 sym
= block_find_symbol (block
, name
, domain
,
5504 block_find_non_opaque_type_preferred
,
5507 /* Some caution must be observed with overloaded functions and
5508 methods, since the index will not contain any overload
5509 information (but NAME might contain it). */
5512 && strcmp_iw (sym
->search_name (), name
) == 0)
5514 if (with_opaque
!= NULL
5515 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5518 /* Keep looking through other CUs. */
5524 /* This dumps minimal information about .debug_names. It is called
5525 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5526 uses this to verify that .debug_names has been loaded. */
5529 dw2_debug_names_dump (struct objfile
*objfile
)
5531 struct dwarf2_per_objfile
*dwarf2_per_objfile
5532 = get_dwarf2_per_objfile (objfile
);
5534 gdb_assert (dwarf2_per_objfile
->using_index
);
5535 printf_filtered (".debug_names:");
5536 if (dwarf2_per_objfile
->debug_names_table
)
5537 printf_filtered (" exists\n");
5539 printf_filtered (" faked for \"readnow\"\n");
5540 printf_filtered ("\n");
5544 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5545 const char *func_name
)
5547 struct dwarf2_per_objfile
*dwarf2_per_objfile
5548 = get_dwarf2_per_objfile (objfile
);
5550 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5551 if (dwarf2_per_objfile
->debug_names_table
)
5553 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5555 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5557 struct dwarf2_per_cu_data
*per_cu
;
5558 while ((per_cu
= iter
.next ()) != NULL
)
5559 dw2_instantiate_symtab (per_cu
, false);
5564 dw2_debug_names_map_matching_symbols
5565 (struct objfile
*objfile
,
5566 const lookup_name_info
&name
, domain_enum domain
,
5568 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5569 symbol_compare_ftype
*ordered_compare
)
5571 struct dwarf2_per_objfile
*dwarf2_per_objfile
5572 = get_dwarf2_per_objfile (objfile
);
5574 /* debug_names_table is NULL if OBJF_READNOW. */
5575 if (!dwarf2_per_objfile
->debug_names_table
)
5578 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5579 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5581 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5582 auto matcher
= [&] (const char *symname
)
5584 if (ordered_compare
== nullptr)
5586 return ordered_compare (symname
, match_name
) == 0;
5589 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5590 [&] (offset_type namei
)
5592 /* The name was matched, now expand corresponding CUs that were
5594 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5596 struct dwarf2_per_cu_data
*per_cu
;
5597 while ((per_cu
= iter
.next ()) != NULL
)
5598 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5602 /* It's a shame we couldn't do this inside the
5603 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5604 that have already been expanded. Instead, this loop matches what
5605 the psymtab code does. */
5606 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5608 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5609 if (cust
!= nullptr)
5611 const struct block
*block
5612 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5613 if (!iterate_over_symbols_terminated (block
, name
,
5621 dw2_debug_names_expand_symtabs_matching
5622 (struct objfile
*objfile
,
5623 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5624 const lookup_name_info
&lookup_name
,
5625 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5626 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5627 enum search_domain kind
)
5629 struct dwarf2_per_objfile
*dwarf2_per_objfile
5630 = get_dwarf2_per_objfile (objfile
);
5632 /* debug_names_table is NULL if OBJF_READNOW. */
5633 if (!dwarf2_per_objfile
->debug_names_table
)
5636 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5638 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5640 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5642 kind
, [&] (offset_type namei
)
5644 /* The name was matched, now expand corresponding CUs that were
5646 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5648 struct dwarf2_per_cu_data
*per_cu
;
5649 while ((per_cu
= iter
.next ()) != NULL
)
5650 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5656 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5659 dw2_find_last_source_symtab
,
5660 dw2_forget_cached_source_info
,
5661 dw2_map_symtabs_matching_filename
,
5662 dw2_debug_names_lookup_symbol
,
5664 dw2_debug_names_dump
,
5665 dw2_debug_names_expand_symtabs_for_function
,
5666 dw2_expand_all_symtabs
,
5667 dw2_expand_symtabs_with_fullname
,
5668 dw2_debug_names_map_matching_symbols
,
5669 dw2_debug_names_expand_symtabs_matching
,
5670 dw2_find_pc_sect_compunit_symtab
,
5672 dw2_map_symbol_filenames
5675 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5676 to either a dwarf2_per_objfile or dwz_file object. */
5678 template <typename T
>
5679 static gdb::array_view
<const gdb_byte
>
5680 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5682 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5684 if (section
->empty ())
5687 /* Older elfutils strip versions could keep the section in the main
5688 executable while splitting it for the separate debug info file. */
5689 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5692 section
->read (obj
);
5694 /* dwarf2_section_info::size is a bfd_size_type, while
5695 gdb::array_view works with size_t. On 32-bit hosts, with
5696 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5697 is 32-bit. So we need an explicit narrowing conversion here.
5698 This is fine, because it's impossible to allocate or mmap an
5699 array/buffer larger than what size_t can represent. */
5700 return gdb::make_array_view (section
->buffer
, section
->size
);
5703 /* Lookup the index cache for the contents of the index associated to
5706 static gdb::array_view
<const gdb_byte
>
5707 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5709 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5710 if (build_id
== nullptr)
5713 return global_index_cache
.lookup_gdb_index (build_id
,
5714 &dwarf2_obj
->index_cache_res
);
5717 /* Same as the above, but for DWZ. */
5719 static gdb::array_view
<const gdb_byte
>
5720 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5722 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5723 if (build_id
== nullptr)
5726 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5729 /* See symfile.h. */
5732 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5734 struct dwarf2_per_objfile
*dwarf2_per_objfile
5735 = get_dwarf2_per_objfile (objfile
);
5737 /* If we're about to read full symbols, don't bother with the
5738 indices. In this case we also don't care if some other debug
5739 format is making psymtabs, because they are all about to be
5741 if ((objfile
->flags
& OBJF_READNOW
))
5743 dwarf2_per_objfile
->using_index
= 1;
5744 create_all_comp_units (dwarf2_per_objfile
);
5745 create_all_type_units (dwarf2_per_objfile
);
5746 dwarf2_per_objfile
->quick_file_names_table
5747 = create_quick_file_names_table
5748 (dwarf2_per_objfile
->all_comp_units
.size ());
5750 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5751 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5753 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5755 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5756 struct dwarf2_per_cu_quick_data
);
5759 /* Return 1 so that gdb sees the "quick" functions. However,
5760 these functions will be no-ops because we will have expanded
5762 *index_kind
= dw_index_kind::GDB_INDEX
;
5766 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5768 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5772 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5773 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5774 get_gdb_index_contents_from_section
<dwz_file
>))
5776 *index_kind
= dw_index_kind::GDB_INDEX
;
5780 /* ... otherwise, try to find the index in the index cache. */
5781 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5782 get_gdb_index_contents_from_cache
,
5783 get_gdb_index_contents_from_cache_dwz
))
5785 global_index_cache
.hit ();
5786 *index_kind
= dw_index_kind::GDB_INDEX
;
5790 global_index_cache
.miss ();
5796 /* Build a partial symbol table. */
5799 dwarf2_build_psymtabs (struct objfile
*objfile
)
5801 struct dwarf2_per_objfile
*dwarf2_per_objfile
5802 = get_dwarf2_per_objfile (objfile
);
5804 init_psymbol_list (objfile
, 1024);
5808 /* This isn't really ideal: all the data we allocate on the
5809 objfile's obstack is still uselessly kept around. However,
5810 freeing it seems unsafe. */
5811 psymtab_discarder
psymtabs (objfile
);
5812 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5815 /* (maybe) store an index in the cache. */
5816 global_index_cache
.store (dwarf2_per_objfile
);
5818 catch (const gdb_exception_error
&except
)
5820 exception_print (gdb_stderr
, except
);
5824 /* Find the base address of the compilation unit for range lists and
5825 location lists. It will normally be specified by DW_AT_low_pc.
5826 In DWARF-3 draft 4, the base address could be overridden by
5827 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5828 compilation units with discontinuous ranges. */
5831 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5833 struct attribute
*attr
;
5836 cu
->base_address
= 0;
5838 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5839 if (attr
!= nullptr)
5841 cu
->base_address
= attr
->value_as_address ();
5846 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5847 if (attr
!= nullptr)
5849 cu
->base_address
= attr
->value_as_address ();
5855 /* Helper function that returns the proper abbrev section for
5858 static struct dwarf2_section_info
*
5859 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5861 struct dwarf2_section_info
*abbrev
;
5862 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5864 if (this_cu
->is_dwz
)
5865 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5867 abbrev
= &dwarf2_per_objfile
->abbrev
;
5872 /* Fetch the abbreviation table offset from a comp or type unit header. */
5875 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5876 struct dwarf2_section_info
*section
,
5877 sect_offset sect_off
)
5879 bfd
*abfd
= section
->get_bfd_owner ();
5880 const gdb_byte
*info_ptr
;
5881 unsigned int initial_length_size
, offset_size
;
5884 section
->read (dwarf2_per_objfile
->objfile
);
5885 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5886 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5887 offset_size
= initial_length_size
== 4 ? 4 : 8;
5888 info_ptr
+= initial_length_size
;
5890 version
= read_2_bytes (abfd
, info_ptr
);
5894 /* Skip unit type and address size. */
5898 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5901 /* Allocate a new partial symtab for file named NAME and mark this new
5902 partial symtab as being an include of PST. */
5905 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5906 struct objfile
*objfile
)
5908 dwarf2_psymtab
*subpst
= new dwarf2_psymtab (name
, objfile
);
5910 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5912 /* It shares objfile->objfile_obstack. */
5913 subpst
->dirname
= pst
->dirname
;
5916 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5917 subpst
->dependencies
[0] = pst
;
5918 subpst
->number_of_dependencies
= 1;
5920 /* No private part is necessary for include psymtabs. This property
5921 can be used to differentiate between such include psymtabs and
5922 the regular ones. */
5923 subpst
->per_cu_data
= nullptr;
5926 /* Read the Line Number Program data and extract the list of files
5927 included by the source file represented by PST. Build an include
5928 partial symtab for each of these included files. */
5931 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5932 struct die_info
*die
,
5933 dwarf2_psymtab
*pst
)
5936 struct attribute
*attr
;
5938 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5939 if (attr
!= nullptr)
5940 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5942 return; /* No linetable, so no includes. */
5944 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5945 that we pass in the raw text_low here; that is ok because we're
5946 only decoding the line table to make include partial symtabs, and
5947 so the addresses aren't really used. */
5948 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5949 pst
->raw_text_low (), 1);
5953 hash_signatured_type (const void *item
)
5955 const struct signatured_type
*sig_type
5956 = (const struct signatured_type
*) item
;
5958 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5959 return sig_type
->signature
;
5963 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5965 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5966 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5968 return lhs
->signature
== rhs
->signature
;
5971 /* Allocate a hash table for signatured types. */
5974 allocate_signatured_type_table (struct objfile
*objfile
)
5976 return htab_up (htab_create_alloc (41,
5977 hash_signatured_type
,
5979 NULL
, xcalloc
, xfree
));
5982 /* A helper function to add a signatured type CU to a table. */
5985 add_signatured_type_cu_to_table (void **slot
, void *datum
)
5987 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
5988 std::vector
<signatured_type
*> *all_type_units
5989 = (std::vector
<signatured_type
*> *) datum
;
5991 all_type_units
->push_back (sigt
);
5996 /* A helper for create_debug_types_hash_table. Read types from SECTION
5997 and fill them into TYPES_HTAB. It will process only type units,
5998 therefore DW_UT_type. */
6001 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6002 struct dwo_file
*dwo_file
,
6003 dwarf2_section_info
*section
, htab_up
&types_htab
,
6004 rcuh_kind section_kind
)
6006 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6007 struct dwarf2_section_info
*abbrev_section
;
6009 const gdb_byte
*info_ptr
, *end_ptr
;
6011 abbrev_section
= (dwo_file
!= NULL
6012 ? &dwo_file
->sections
.abbrev
6013 : &dwarf2_per_objfile
->abbrev
);
6015 if (dwarf_read_debug
)
6016 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6017 section
->get_name (),
6018 abbrev_section
->get_file_name ());
6020 section
->read (objfile
);
6021 info_ptr
= section
->buffer
;
6023 if (info_ptr
== NULL
)
6026 /* We can't set abfd until now because the section may be empty or
6027 not present, in which case the bfd is unknown. */
6028 abfd
= section
->get_bfd_owner ();
6030 /* We don't use cutu_reader here because we don't need to read
6031 any dies: the signature is in the header. */
6033 end_ptr
= info_ptr
+ section
->size
;
6034 while (info_ptr
< end_ptr
)
6036 struct signatured_type
*sig_type
;
6037 struct dwo_unit
*dwo_tu
;
6039 const gdb_byte
*ptr
= info_ptr
;
6040 struct comp_unit_head header
;
6041 unsigned int length
;
6043 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6045 /* Initialize it due to a false compiler warning. */
6046 header
.signature
= -1;
6047 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6049 /* We need to read the type's signature in order to build the hash
6050 table, but we don't need anything else just yet. */
6052 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6053 abbrev_section
, ptr
, section_kind
);
6055 length
= header
.get_length ();
6057 /* Skip dummy type units. */
6058 if (ptr
>= info_ptr
+ length
6059 || peek_abbrev_code (abfd
, ptr
) == 0
6060 || header
.unit_type
!= DW_UT_type
)
6066 if (types_htab
== NULL
)
6069 types_htab
= allocate_dwo_unit_table (objfile
);
6071 types_htab
= allocate_signatured_type_table (objfile
);
6077 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6079 dwo_tu
->dwo_file
= dwo_file
;
6080 dwo_tu
->signature
= header
.signature
;
6081 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6082 dwo_tu
->section
= section
;
6083 dwo_tu
->sect_off
= sect_off
;
6084 dwo_tu
->length
= length
;
6088 /* N.B.: type_offset is not usable if this type uses a DWO file.
6089 The real type_offset is in the DWO file. */
6091 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6092 struct signatured_type
);
6093 sig_type
->signature
= header
.signature
;
6094 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6095 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6096 sig_type
->per_cu
.is_debug_types
= 1;
6097 sig_type
->per_cu
.section
= section
;
6098 sig_type
->per_cu
.sect_off
= sect_off
;
6099 sig_type
->per_cu
.length
= length
;
6102 slot
= htab_find_slot (types_htab
.get (),
6103 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6105 gdb_assert (slot
!= NULL
);
6108 sect_offset dup_sect_off
;
6112 const struct dwo_unit
*dup_tu
6113 = (const struct dwo_unit
*) *slot
;
6115 dup_sect_off
= dup_tu
->sect_off
;
6119 const struct signatured_type
*dup_tu
6120 = (const struct signatured_type
*) *slot
;
6122 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6125 complaint (_("debug type entry at offset %s is duplicate to"
6126 " the entry at offset %s, signature %s"),
6127 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6128 hex_string (header
.signature
));
6130 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6132 if (dwarf_read_debug
> 1)
6133 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6134 sect_offset_str (sect_off
),
6135 hex_string (header
.signature
));
6141 /* Create the hash table of all entries in the .debug_types
6142 (or .debug_types.dwo) section(s).
6143 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6144 otherwise it is NULL.
6146 The result is a pointer to the hash table or NULL if there are no types.
6148 Note: This function processes DWO files only, not DWP files. */
6151 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6152 struct dwo_file
*dwo_file
,
6153 gdb::array_view
<dwarf2_section_info
> type_sections
,
6154 htab_up
&types_htab
)
6156 for (dwarf2_section_info
§ion
: type_sections
)
6157 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6158 types_htab
, rcuh_kind::TYPE
);
6161 /* Create the hash table of all entries in the .debug_types section,
6162 and initialize all_type_units.
6163 The result is zero if there is an error (e.g. missing .debug_types section),
6164 otherwise non-zero. */
6167 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6171 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6172 &dwarf2_per_objfile
->info
, types_htab
,
6173 rcuh_kind::COMPILE
);
6174 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6175 dwarf2_per_objfile
->types
, types_htab
);
6176 if (types_htab
== NULL
)
6178 dwarf2_per_objfile
->signatured_types
= NULL
;
6182 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6184 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6185 dwarf2_per_objfile
->all_type_units
.reserve
6186 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6188 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6189 add_signatured_type_cu_to_table
,
6190 &dwarf2_per_objfile
->all_type_units
);
6195 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6196 If SLOT is non-NULL, it is the entry to use in the hash table.
6197 Otherwise we find one. */
6199 static struct signatured_type
*
6200 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6203 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6205 if (dwarf2_per_objfile
->all_type_units
.size ()
6206 == dwarf2_per_objfile
->all_type_units
.capacity ())
6207 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6209 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6210 struct signatured_type
);
6212 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6213 sig_type
->signature
= sig
;
6214 sig_type
->per_cu
.is_debug_types
= 1;
6215 if (dwarf2_per_objfile
->using_index
)
6217 sig_type
->per_cu
.v
.quick
=
6218 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6219 struct dwarf2_per_cu_quick_data
);
6224 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6227 gdb_assert (*slot
== NULL
);
6229 /* The rest of sig_type must be filled in by the caller. */
6233 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6234 Fill in SIG_ENTRY with DWO_ENTRY. */
6237 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6238 struct signatured_type
*sig_entry
,
6239 struct dwo_unit
*dwo_entry
)
6241 /* Make sure we're not clobbering something we don't expect to. */
6242 gdb_assert (! sig_entry
->per_cu
.queued
);
6243 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6244 if (dwarf2_per_objfile
->using_index
)
6246 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6247 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6250 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6251 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6252 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6253 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6254 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6256 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6257 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6258 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6259 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6260 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6261 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6262 sig_entry
->dwo_unit
= dwo_entry
;
6265 /* Subroutine of lookup_signatured_type.
6266 If we haven't read the TU yet, create the signatured_type data structure
6267 for a TU to be read in directly from a DWO file, bypassing the stub.
6268 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6269 using .gdb_index, then when reading a CU we want to stay in the DWO file
6270 containing that CU. Otherwise we could end up reading several other DWO
6271 files (due to comdat folding) to process the transitive closure of all the
6272 mentioned TUs, and that can be slow. The current DWO file will have every
6273 type signature that it needs.
6274 We only do this for .gdb_index because in the psymtab case we already have
6275 to read all the DWOs to build the type unit groups. */
6277 static struct signatured_type
*
6278 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6280 struct dwarf2_per_objfile
*dwarf2_per_objfile
6281 = cu
->per_cu
->dwarf2_per_objfile
;
6282 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6283 struct dwo_file
*dwo_file
;
6284 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6285 struct signatured_type find_sig_entry
, *sig_entry
;
6288 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6290 /* If TU skeletons have been removed then we may not have read in any
6292 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6294 dwarf2_per_objfile
->signatured_types
6295 = allocate_signatured_type_table (objfile
);
6298 /* We only ever need to read in one copy of a signatured type.
6299 Use the global signatured_types array to do our own comdat-folding
6300 of types. If this is the first time we're reading this TU, and
6301 the TU has an entry in .gdb_index, replace the recorded data from
6302 .gdb_index with this TU. */
6304 find_sig_entry
.signature
= sig
;
6305 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6306 &find_sig_entry
, INSERT
);
6307 sig_entry
= (struct signatured_type
*) *slot
;
6309 /* We can get here with the TU already read, *or* in the process of being
6310 read. Don't reassign the global entry to point to this DWO if that's
6311 the case. Also note that if the TU is already being read, it may not
6312 have come from a DWO, the program may be a mix of Fission-compiled
6313 code and non-Fission-compiled code. */
6315 /* Have we already tried to read this TU?
6316 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6317 needn't exist in the global table yet). */
6318 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6321 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6322 dwo_unit of the TU itself. */
6323 dwo_file
= cu
->dwo_unit
->dwo_file
;
6325 /* Ok, this is the first time we're reading this TU. */
6326 if (dwo_file
->tus
== NULL
)
6328 find_dwo_entry
.signature
= sig
;
6329 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6331 if (dwo_entry
== NULL
)
6334 /* If the global table doesn't have an entry for this TU, add one. */
6335 if (sig_entry
== NULL
)
6336 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6338 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6339 sig_entry
->per_cu
.tu_read
= 1;
6343 /* Subroutine of lookup_signatured_type.
6344 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6345 then try the DWP file. If the TU stub (skeleton) has been removed then
6346 it won't be in .gdb_index. */
6348 static struct signatured_type
*
6349 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6351 struct dwarf2_per_objfile
*dwarf2_per_objfile
6352 = cu
->per_cu
->dwarf2_per_objfile
;
6353 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6354 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6355 struct dwo_unit
*dwo_entry
;
6356 struct signatured_type find_sig_entry
, *sig_entry
;
6359 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6360 gdb_assert (dwp_file
!= NULL
);
6362 /* If TU skeletons have been removed then we may not have read in any
6364 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6366 dwarf2_per_objfile
->signatured_types
6367 = allocate_signatured_type_table (objfile
);
6370 find_sig_entry
.signature
= sig
;
6371 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6372 &find_sig_entry
, INSERT
);
6373 sig_entry
= (struct signatured_type
*) *slot
;
6375 /* Have we already tried to read this TU?
6376 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6377 needn't exist in the global table yet). */
6378 if (sig_entry
!= NULL
)
6381 if (dwp_file
->tus
== NULL
)
6383 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6384 sig
, 1 /* is_debug_types */);
6385 if (dwo_entry
== NULL
)
6388 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6389 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6394 /* Lookup a signature based type for DW_FORM_ref_sig8.
6395 Returns NULL if signature SIG is not present in the table.
6396 It is up to the caller to complain about this. */
6398 static struct signatured_type
*
6399 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6401 struct dwarf2_per_objfile
*dwarf2_per_objfile
6402 = cu
->per_cu
->dwarf2_per_objfile
;
6405 && dwarf2_per_objfile
->using_index
)
6407 /* We're in a DWO/DWP file, and we're using .gdb_index.
6408 These cases require special processing. */
6409 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6410 return lookup_dwo_signatured_type (cu
, sig
);
6412 return lookup_dwp_signatured_type (cu
, sig
);
6416 struct signatured_type find_entry
, *entry
;
6418 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6420 find_entry
.signature
= sig
;
6421 entry
= ((struct signatured_type
*)
6422 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6428 /* Return the address base of the compile unit, which, if exists, is stored
6429 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6430 static gdb::optional
<ULONGEST
>
6431 lookup_addr_base (struct die_info
*comp_unit_die
)
6433 struct attribute
*attr
;
6434 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
6435 if (attr
== nullptr)
6436 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
6437 if (attr
== nullptr)
6438 return gdb::optional
<ULONGEST
> ();
6439 return DW_UNSND (attr
);
6442 /* Return range lists base of the compile unit, which, if exists, is stored
6443 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6445 lookup_ranges_base (struct die_info
*comp_unit_die
)
6447 struct attribute
*attr
;
6448 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
6449 if (attr
== nullptr)
6450 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
6451 if (attr
== nullptr)
6453 return DW_UNSND (attr
);
6456 /* Low level DIE reading support. */
6458 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6461 init_cu_die_reader (struct die_reader_specs
*reader
,
6462 struct dwarf2_cu
*cu
,
6463 struct dwarf2_section_info
*section
,
6464 struct dwo_file
*dwo_file
,
6465 struct abbrev_table
*abbrev_table
)
6467 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6468 reader
->abfd
= section
->get_bfd_owner ();
6470 reader
->dwo_file
= dwo_file
;
6471 reader
->die_section
= section
;
6472 reader
->buffer
= section
->buffer
;
6473 reader
->buffer_end
= section
->buffer
+ section
->size
;
6474 reader
->abbrev_table
= abbrev_table
;
6477 /* Subroutine of cutu_reader to simplify it.
6478 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6479 There's just a lot of work to do, and cutu_reader is big enough
6482 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6483 from it to the DIE in the DWO. If NULL we are skipping the stub.
6484 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6485 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6486 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6487 STUB_COMP_DIR may be non-NULL.
6488 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6489 are filled in with the info of the DIE from the DWO file.
6490 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6491 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6492 kept around for at least as long as *RESULT_READER.
6494 The result is non-zero if a valid (non-dummy) DIE was found. */
6497 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6498 struct dwo_unit
*dwo_unit
,
6499 struct die_info
*stub_comp_unit_die
,
6500 const char *stub_comp_dir
,
6501 struct die_reader_specs
*result_reader
,
6502 const gdb_byte
**result_info_ptr
,
6503 struct die_info
**result_comp_unit_die
,
6504 abbrev_table_up
*result_dwo_abbrev_table
)
6506 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6507 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6508 struct dwarf2_cu
*cu
= this_cu
->cu
;
6510 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6511 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6512 int i
,num_extra_attrs
;
6513 struct dwarf2_section_info
*dwo_abbrev_section
;
6514 struct die_info
*comp_unit_die
;
6516 /* At most one of these may be provided. */
6517 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6519 /* These attributes aren't processed until later:
6520 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6521 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6522 referenced later. However, these attributes are found in the stub
6523 which we won't have later. In order to not impose this complication
6524 on the rest of the code, we read them here and copy them to the
6533 if (stub_comp_unit_die
!= NULL
)
6535 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6537 if (! this_cu
->is_debug_types
)
6538 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6539 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6540 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6541 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6542 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6544 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
6546 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6547 here (if needed). We need the value before we can process
6549 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
6551 else if (stub_comp_dir
!= NULL
)
6553 /* Reconstruct the comp_dir attribute to simplify the code below. */
6554 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6555 comp_dir
->name
= DW_AT_comp_dir
;
6556 comp_dir
->form
= DW_FORM_string
;
6557 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6558 DW_STRING (comp_dir
) = stub_comp_dir
;
6561 /* Set up for reading the DWO CU/TU. */
6562 cu
->dwo_unit
= dwo_unit
;
6563 dwarf2_section_info
*section
= dwo_unit
->section
;
6564 section
->read (objfile
);
6565 abfd
= section
->get_bfd_owner ();
6566 begin_info_ptr
= info_ptr
= (section
->buffer
6567 + to_underlying (dwo_unit
->sect_off
));
6568 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6570 if (this_cu
->is_debug_types
)
6572 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6574 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6575 &cu
->header
, section
,
6577 info_ptr
, rcuh_kind::TYPE
);
6578 /* This is not an assert because it can be caused by bad debug info. */
6579 if (sig_type
->signature
!= cu
->header
.signature
)
6581 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6582 " TU at offset %s [in module %s]"),
6583 hex_string (sig_type
->signature
),
6584 hex_string (cu
->header
.signature
),
6585 sect_offset_str (dwo_unit
->sect_off
),
6586 bfd_get_filename (abfd
));
6588 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6589 /* For DWOs coming from DWP files, we don't know the CU length
6590 nor the type's offset in the TU until now. */
6591 dwo_unit
->length
= cu
->header
.get_length ();
6592 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6594 /* Establish the type offset that can be used to lookup the type.
6595 For DWO files, we don't know it until now. */
6596 sig_type
->type_offset_in_section
6597 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6601 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6602 &cu
->header
, section
,
6604 info_ptr
, rcuh_kind::COMPILE
);
6605 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6606 /* For DWOs coming from DWP files, we don't know the CU length
6608 dwo_unit
->length
= cu
->header
.get_length ();
6611 *result_dwo_abbrev_table
6612 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6613 cu
->header
.abbrev_sect_off
);
6614 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6615 result_dwo_abbrev_table
->get ());
6617 /* Read in the die, but leave space to copy over the attributes
6618 from the stub. This has the benefit of simplifying the rest of
6619 the code - all the work to maintain the illusion of a single
6620 DW_TAG_{compile,type}_unit DIE is done here. */
6621 num_extra_attrs
= ((stmt_list
!= NULL
)
6625 + (comp_dir
!= NULL
));
6626 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6629 /* Copy over the attributes from the stub to the DIE we just read in. */
6630 comp_unit_die
= *result_comp_unit_die
;
6631 i
= comp_unit_die
->num_attrs
;
6632 if (stmt_list
!= NULL
)
6633 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6635 comp_unit_die
->attrs
[i
++] = *low_pc
;
6636 if (high_pc
!= NULL
)
6637 comp_unit_die
->attrs
[i
++] = *high_pc
;
6639 comp_unit_die
->attrs
[i
++] = *ranges
;
6640 if (comp_dir
!= NULL
)
6641 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6642 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6644 if (dwarf_die_debug
)
6646 fprintf_unfiltered (gdb_stdlog
,
6647 "Read die from %s@0x%x of %s:\n",
6648 section
->get_name (),
6649 (unsigned) (begin_info_ptr
- section
->buffer
),
6650 bfd_get_filename (abfd
));
6651 dump_die (comp_unit_die
, dwarf_die_debug
);
6654 /* Skip dummy compilation units. */
6655 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6656 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6659 *result_info_ptr
= info_ptr
;
6663 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6664 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6665 signature is part of the header. */
6666 static gdb::optional
<ULONGEST
>
6667 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6669 if (cu
->header
.version
>= 5)
6670 return cu
->header
.signature
;
6671 struct attribute
*attr
;
6672 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6673 if (attr
== nullptr)
6674 return gdb::optional
<ULONGEST
> ();
6675 return DW_UNSND (attr
);
6678 /* Subroutine of cutu_reader to simplify it.
6679 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6680 Returns NULL if the specified DWO unit cannot be found. */
6682 static struct dwo_unit
*
6683 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6684 struct die_info
*comp_unit_die
,
6685 const char *dwo_name
)
6687 struct dwarf2_cu
*cu
= this_cu
->cu
;
6688 struct dwo_unit
*dwo_unit
;
6689 const char *comp_dir
;
6691 gdb_assert (cu
!= NULL
);
6693 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6694 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6695 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6697 if (this_cu
->is_debug_types
)
6699 struct signatured_type
*sig_type
;
6701 /* Since this_cu is the first member of struct signatured_type,
6702 we can go from a pointer to one to a pointer to the other. */
6703 sig_type
= (struct signatured_type
*) this_cu
;
6704 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6708 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6709 if (!signature
.has_value ())
6710 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6712 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6713 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6720 /* Subroutine of cutu_reader to simplify it.
6721 See it for a description of the parameters.
6722 Read a TU directly from a DWO file, bypassing the stub. */
6725 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6726 int use_existing_cu
, int keep
)
6728 struct signatured_type
*sig_type
;
6729 struct die_reader_specs reader
;
6731 /* Verify we can do the following downcast, and that we have the
6733 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6734 sig_type
= (struct signatured_type
*) this_cu
;
6735 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6737 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6739 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6740 /* There's no need to do the rereading_dwo_cu handling that
6741 cutu_reader does since we don't read the stub. */
6745 /* If !use_existing_cu, this_cu->cu must be NULL. */
6746 gdb_assert (this_cu
->cu
== NULL
);
6747 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6750 /* A future optimization, if needed, would be to use an existing
6751 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6752 could share abbrev tables. */
6754 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6755 NULL
/* stub_comp_unit_die */,
6756 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6759 &m_dwo_abbrev_table
) == 0)
6766 /* Initialize a CU (or TU) and read its DIEs.
6767 If the CU defers to a DWO file, read the DWO file as well.
6769 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6770 Otherwise the table specified in the comp unit header is read in and used.
6771 This is an optimization for when we already have the abbrev table.
6773 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6774 Otherwise, a new CU is allocated with xmalloc.
6776 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
6777 read_in_chain. Otherwise the dwarf2_cu data is freed at the
6780 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6781 struct abbrev_table
*abbrev_table
,
6782 int use_existing_cu
, int keep
,
6784 : die_reader_specs
{},
6785 m_this_cu (this_cu
),
6788 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6789 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6790 struct dwarf2_section_info
*section
= this_cu
->section
;
6791 bfd
*abfd
= section
->get_bfd_owner ();
6792 struct dwarf2_cu
*cu
;
6793 const gdb_byte
*begin_info_ptr
;
6794 struct signatured_type
*sig_type
= NULL
;
6795 struct dwarf2_section_info
*abbrev_section
;
6796 /* Non-zero if CU currently points to a DWO file and we need to
6797 reread it. When this happens we need to reread the skeleton die
6798 before we can reread the DWO file (this only applies to CUs, not TUs). */
6799 int rereading_dwo_cu
= 0;
6801 if (dwarf_die_debug
)
6802 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6803 this_cu
->is_debug_types
? "type" : "comp",
6804 sect_offset_str (this_cu
->sect_off
));
6806 if (use_existing_cu
)
6809 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6810 file (instead of going through the stub), short-circuit all of this. */
6811 if (this_cu
->reading_dwo_directly
)
6813 /* Narrow down the scope of possibilities to have to understand. */
6814 gdb_assert (this_cu
->is_debug_types
);
6815 gdb_assert (abbrev_table
== NULL
);
6816 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
);
6820 /* This is cheap if the section is already read in. */
6821 section
->read (objfile
);
6823 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6825 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6827 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6830 /* If this CU is from a DWO file we need to start over, we need to
6831 refetch the attributes from the skeleton CU.
6832 This could be optimized by retrieving those attributes from when we
6833 were here the first time: the previous comp_unit_die was stored in
6834 comp_unit_obstack. But there's no data yet that we need this
6836 if (cu
->dwo_unit
!= NULL
)
6837 rereading_dwo_cu
= 1;
6841 /* If !use_existing_cu, this_cu->cu must be NULL. */
6842 gdb_assert (this_cu
->cu
== NULL
);
6843 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6844 cu
= m_new_cu
.get ();
6847 /* Get the header. */
6848 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6850 /* We already have the header, there's no need to read it in again. */
6851 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6855 if (this_cu
->is_debug_types
)
6857 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6858 &cu
->header
, section
,
6859 abbrev_section
, info_ptr
,
6862 /* Since per_cu is the first member of struct signatured_type,
6863 we can go from a pointer to one to a pointer to the other. */
6864 sig_type
= (struct signatured_type
*) this_cu
;
6865 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6866 gdb_assert (sig_type
->type_offset_in_tu
6867 == cu
->header
.type_cu_offset_in_tu
);
6868 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6870 /* LENGTH has not been set yet for type units if we're
6871 using .gdb_index. */
6872 this_cu
->length
= cu
->header
.get_length ();
6874 /* Establish the type offset that can be used to lookup the type. */
6875 sig_type
->type_offset_in_section
=
6876 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6878 this_cu
->dwarf_version
= cu
->header
.version
;
6882 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6883 &cu
->header
, section
,
6886 rcuh_kind::COMPILE
);
6888 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6889 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6890 this_cu
->dwarf_version
= cu
->header
.version
;
6894 /* Skip dummy compilation units. */
6895 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6896 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6902 /* If we don't have them yet, read the abbrevs for this compilation unit.
6903 And if we need to read them now, make sure they're freed when we're
6905 if (abbrev_table
!= NULL
)
6906 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6909 m_abbrev_table_holder
6910 = abbrev_table::read (objfile
, abbrev_section
,
6911 cu
->header
.abbrev_sect_off
);
6912 abbrev_table
= m_abbrev_table_holder
.get ();
6915 /* Read the top level CU/TU die. */
6916 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6917 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6919 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6925 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6926 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6927 table from the DWO file and pass the ownership over to us. It will be
6928 referenced from READER, so we must make sure to free it after we're done
6931 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6932 DWO CU, that this test will fail (the attribute will not be present). */
6933 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6934 if (dwo_name
!= nullptr)
6936 struct dwo_unit
*dwo_unit
;
6937 struct die_info
*dwo_comp_unit_die
;
6939 if (comp_unit_die
->has_children
)
6941 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6942 " has children (offset %s) [in module %s]"),
6943 sect_offset_str (this_cu
->sect_off
),
6944 bfd_get_filename (abfd
));
6946 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6947 if (dwo_unit
!= NULL
)
6949 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6950 comp_unit_die
, NULL
,
6953 &m_dwo_abbrev_table
) == 0)
6959 comp_unit_die
= dwo_comp_unit_die
;
6963 /* Yikes, we couldn't find the rest of the DIE, we only have
6964 the stub. A complaint has already been logged. There's
6965 not much more we can do except pass on the stub DIE to
6966 die_reader_func. We don't want to throw an error on bad
6972 cutu_reader::~cutu_reader ()
6974 /* Done, clean up. */
6975 if (m_new_cu
!= NULL
&& m_keep
&& !dummy_p
)
6977 struct dwarf2_per_objfile
*dwarf2_per_objfile
6978 = m_this_cu
->dwarf2_per_objfile
;
6979 /* Link this CU into read_in_chain. */
6980 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6981 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6982 /* The chain owns it now. */
6983 m_new_cu
.release ();
6987 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6988 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6989 assumed to have already done the lookup to find the DWO file).
6991 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6992 THIS_CU->is_debug_types, but nothing else.
6994 We fill in THIS_CU->length.
6996 THIS_CU->cu is always freed when done.
6997 This is done in order to not leave THIS_CU->cu in a state where we have
6998 to care whether it refers to the "main" CU or the DWO CU.
7000 When parent_cu is passed, it is used to provide a default value for
7001 str_offsets_base and addr_base from the parent. */
7003 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7004 struct dwarf2_cu
*parent_cu
,
7005 struct dwo_file
*dwo_file
)
7006 : die_reader_specs
{},
7009 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7010 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7011 struct dwarf2_section_info
*section
= this_cu
->section
;
7012 bfd
*abfd
= section
->get_bfd_owner ();
7013 struct dwarf2_section_info
*abbrev_section
;
7014 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7016 if (dwarf_die_debug
)
7017 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7018 this_cu
->is_debug_types
? "type" : "comp",
7019 sect_offset_str (this_cu
->sect_off
));
7021 gdb_assert (this_cu
->cu
== NULL
);
7023 abbrev_section
= (dwo_file
!= NULL
7024 ? &dwo_file
->sections
.abbrev
7025 : get_abbrev_section_for_cu (this_cu
));
7027 /* This is cheap if the section is already read in. */
7028 section
->read (objfile
);
7030 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7032 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7033 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7034 &m_new_cu
->header
, section
,
7035 abbrev_section
, info_ptr
,
7036 (this_cu
->is_debug_types
7038 : rcuh_kind::COMPILE
));
7040 if (parent_cu
!= nullptr)
7042 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7043 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7045 this_cu
->length
= m_new_cu
->header
.get_length ();
7047 /* Skip dummy compilation units. */
7048 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7049 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7055 m_abbrev_table_holder
7056 = abbrev_table::read (objfile
, abbrev_section
,
7057 m_new_cu
->header
.abbrev_sect_off
);
7059 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7060 m_abbrev_table_holder
.get ());
7061 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7065 /* Type Unit Groups.
7067 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7068 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7069 so that all types coming from the same compilation (.o file) are grouped
7070 together. A future step could be to put the types in the same symtab as
7071 the CU the types ultimately came from. */
7074 hash_type_unit_group (const void *item
)
7076 const struct type_unit_group
*tu_group
7077 = (const struct type_unit_group
*) item
;
7079 return hash_stmt_list_entry (&tu_group
->hash
);
7083 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7085 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7086 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7088 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7091 /* Allocate a hash table for type unit groups. */
7094 allocate_type_unit_groups_table (struct objfile
*objfile
)
7096 return htab_up (htab_create_alloc (3,
7097 hash_type_unit_group
,
7099 NULL
, xcalloc
, xfree
));
7102 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7103 partial symtabs. We combine several TUs per psymtab to not let the size
7104 of any one psymtab grow too big. */
7105 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7106 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7108 /* Helper routine for get_type_unit_group.
7109 Create the type_unit_group object used to hold one or more TUs. */
7111 static struct type_unit_group
*
7112 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7114 struct dwarf2_per_objfile
*dwarf2_per_objfile
7115 = cu
->per_cu
->dwarf2_per_objfile
;
7116 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7117 struct dwarf2_per_cu_data
*per_cu
;
7118 struct type_unit_group
*tu_group
;
7120 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7121 struct type_unit_group
);
7122 per_cu
= &tu_group
->per_cu
;
7123 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7125 if (dwarf2_per_objfile
->using_index
)
7127 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7128 struct dwarf2_per_cu_quick_data
);
7132 unsigned int line_offset
= to_underlying (line_offset_struct
);
7133 dwarf2_psymtab
*pst
;
7136 /* Give the symtab a useful name for debug purposes. */
7137 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7138 name
= string_printf ("<type_units_%d>",
7139 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7141 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7143 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7144 pst
->anonymous
= true;
7147 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7148 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7153 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7154 STMT_LIST is a DW_AT_stmt_list attribute. */
7156 static struct type_unit_group
*
7157 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7159 struct dwarf2_per_objfile
*dwarf2_per_objfile
7160 = cu
->per_cu
->dwarf2_per_objfile
;
7161 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7162 struct type_unit_group
*tu_group
;
7164 unsigned int line_offset
;
7165 struct type_unit_group type_unit_group_for_lookup
;
7167 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7169 dwarf2_per_objfile
->type_unit_groups
=
7170 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7173 /* Do we need to create a new group, or can we use an existing one? */
7177 line_offset
= DW_UNSND (stmt_list
);
7178 ++tu_stats
->nr_symtab_sharers
;
7182 /* Ugh, no stmt_list. Rare, but we have to handle it.
7183 We can do various things here like create one group per TU or
7184 spread them over multiple groups to split up the expansion work.
7185 To avoid worst case scenarios (too many groups or too large groups)
7186 we, umm, group them in bunches. */
7187 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7188 | (tu_stats
->nr_stmt_less_type_units
7189 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7190 ++tu_stats
->nr_stmt_less_type_units
;
7193 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7194 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7195 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7196 &type_unit_group_for_lookup
, INSERT
);
7199 tu_group
= (struct type_unit_group
*) *slot
;
7200 gdb_assert (tu_group
!= NULL
);
7204 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7205 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7207 ++tu_stats
->nr_symtabs
;
7213 /* Partial symbol tables. */
7215 /* Create a psymtab named NAME and assign it to PER_CU.
7217 The caller must fill in the following details:
7218 dirname, textlow, texthigh. */
7220 static dwarf2_psymtab
*
7221 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7223 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7224 dwarf2_psymtab
*pst
;
7226 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7228 pst
->psymtabs_addrmap_supported
= true;
7230 /* This is the glue that links PST into GDB's symbol API. */
7231 pst
->per_cu_data
= per_cu
;
7232 per_cu
->v
.psymtab
= pst
;
7237 /* DIE reader function for process_psymtab_comp_unit. */
7240 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7241 const gdb_byte
*info_ptr
,
7242 struct die_info
*comp_unit_die
,
7243 int want_partial_unit
,
7244 enum language pretend_language
)
7246 struct dwarf2_cu
*cu
= reader
->cu
;
7247 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7248 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7249 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7251 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7252 dwarf2_psymtab
*pst
;
7253 enum pc_bounds_kind cu_bounds_kind
;
7254 const char *filename
;
7256 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !want_partial_unit
)
7259 gdb_assert (! per_cu
->is_debug_types
);
7261 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7263 /* Allocate a new partial symbol table structure. */
7264 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7265 if (filename
== NULL
)
7268 pst
= create_partial_symtab (per_cu
, filename
);
7270 /* This must be done before calling dwarf2_build_include_psymtabs. */
7271 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7273 baseaddr
= objfile
->text_section_offset ();
7275 dwarf2_find_base_address (comp_unit_die
, cu
);
7277 /* Possibly set the default values of LOWPC and HIGHPC from
7279 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7280 &best_highpc
, cu
, pst
);
7281 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7284 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7287 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7289 /* Store the contiguous range if it is not empty; it can be
7290 empty for CUs with no code. */
7291 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7295 /* Check if comp unit has_children.
7296 If so, read the rest of the partial symbols from this comp unit.
7297 If not, there's no more debug_info for this comp unit. */
7298 if (comp_unit_die
->has_children
)
7300 struct partial_die_info
*first_die
;
7301 CORE_ADDR lowpc
, highpc
;
7303 lowpc
= ((CORE_ADDR
) -1);
7304 highpc
= ((CORE_ADDR
) 0);
7306 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7308 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7309 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7311 /* If we didn't find a lowpc, set it to highpc to avoid
7312 complaints from `maint check'. */
7313 if (lowpc
== ((CORE_ADDR
) -1))
7316 /* If the compilation unit didn't have an explicit address range,
7317 then use the information extracted from its child dies. */
7318 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7321 best_highpc
= highpc
;
7324 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7325 best_lowpc
+ baseaddr
)
7327 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7328 best_highpc
+ baseaddr
)
7331 end_psymtab_common (objfile
, pst
);
7333 if (!cu
->per_cu
->imported_symtabs_empty ())
7336 int len
= cu
->per_cu
->imported_symtabs_size ();
7338 /* Fill in 'dependencies' here; we fill in 'users' in a
7340 pst
->number_of_dependencies
= len
;
7342 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7343 for (i
= 0; i
< len
; ++i
)
7345 pst
->dependencies
[i
]
7346 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7349 cu
->per_cu
->imported_symtabs_free ();
7352 /* Get the list of files included in the current compilation unit,
7353 and build a psymtab for each of them. */
7354 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7356 if (dwarf_read_debug
)
7357 fprintf_unfiltered (gdb_stdlog
,
7358 "Psymtab for %s unit @%s: %s - %s"
7359 ", %d global, %d static syms\n",
7360 per_cu
->is_debug_types
? "type" : "comp",
7361 sect_offset_str (per_cu
->sect_off
),
7362 paddress (gdbarch
, pst
->text_low (objfile
)),
7363 paddress (gdbarch
, pst
->text_high (objfile
)),
7364 pst
->n_global_syms
, pst
->n_static_syms
);
7367 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7368 Process compilation unit THIS_CU for a psymtab. */
7371 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7372 int want_partial_unit
,
7373 enum language pretend_language
)
7375 /* If this compilation unit was already read in, free the
7376 cached copy in order to read it in again. This is
7377 necessary because we skipped some symbols when we first
7378 read in the compilation unit (see load_partial_dies).
7379 This problem could be avoided, but the benefit is unclear. */
7380 if (this_cu
->cu
!= NULL
)
7381 free_one_cached_comp_unit (this_cu
);
7383 cutu_reader
reader (this_cu
, NULL
, 0, 0, false);
7389 else if (this_cu
->is_debug_types
)
7390 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7391 reader
.comp_unit_die
);
7393 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7394 reader
.comp_unit_die
,
7398 /* Age out any secondary CUs. */
7399 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7402 /* Reader function for build_type_psymtabs. */
7405 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7406 const gdb_byte
*info_ptr
,
7407 struct die_info
*type_unit_die
)
7409 struct dwarf2_per_objfile
*dwarf2_per_objfile
7410 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7411 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7412 struct dwarf2_cu
*cu
= reader
->cu
;
7413 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7414 struct signatured_type
*sig_type
;
7415 struct type_unit_group
*tu_group
;
7416 struct attribute
*attr
;
7417 struct partial_die_info
*first_die
;
7418 CORE_ADDR lowpc
, highpc
;
7419 dwarf2_psymtab
*pst
;
7421 gdb_assert (per_cu
->is_debug_types
);
7422 sig_type
= (struct signatured_type
*) per_cu
;
7424 if (! type_unit_die
->has_children
)
7427 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
7428 tu_group
= get_type_unit_group (cu
, attr
);
7430 if (tu_group
->tus
== nullptr)
7431 tu_group
->tus
= new std::vector
<signatured_type
*>;
7432 tu_group
->tus
->push_back (sig_type
);
7434 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7435 pst
= create_partial_symtab (per_cu
, "");
7436 pst
->anonymous
= true;
7438 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7440 lowpc
= (CORE_ADDR
) -1;
7441 highpc
= (CORE_ADDR
) 0;
7442 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7444 end_psymtab_common (objfile
, pst
);
7447 /* Struct used to sort TUs by their abbreviation table offset. */
7449 struct tu_abbrev_offset
7451 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7452 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7455 signatured_type
*sig_type
;
7456 sect_offset abbrev_offset
;
7459 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7462 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7463 const struct tu_abbrev_offset
&b
)
7465 return a
.abbrev_offset
< b
.abbrev_offset
;
7468 /* Efficiently read all the type units.
7469 This does the bulk of the work for build_type_psymtabs.
7471 The efficiency is because we sort TUs by the abbrev table they use and
7472 only read each abbrev table once. In one program there are 200K TUs
7473 sharing 8K abbrev tables.
7475 The main purpose of this function is to support building the
7476 dwarf2_per_objfile->type_unit_groups table.
7477 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7478 can collapse the search space by grouping them by stmt_list.
7479 The savings can be significant, in the same program from above the 200K TUs
7480 share 8K stmt_list tables.
7482 FUNC is expected to call get_type_unit_group, which will create the
7483 struct type_unit_group if necessary and add it to
7484 dwarf2_per_objfile->type_unit_groups. */
7487 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7489 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7490 abbrev_table_up abbrev_table
;
7491 sect_offset abbrev_offset
;
7493 /* It's up to the caller to not call us multiple times. */
7494 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7496 if (dwarf2_per_objfile
->all_type_units
.empty ())
7499 /* TUs typically share abbrev tables, and there can be way more TUs than
7500 abbrev tables. Sort by abbrev table to reduce the number of times we
7501 read each abbrev table in.
7502 Alternatives are to punt or to maintain a cache of abbrev tables.
7503 This is simpler and efficient enough for now.
7505 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7506 symtab to use). Typically TUs with the same abbrev offset have the same
7507 stmt_list value too so in practice this should work well.
7509 The basic algorithm here is:
7511 sort TUs by abbrev table
7512 for each TU with same abbrev table:
7513 read abbrev table if first user
7514 read TU top level DIE
7515 [IWBN if DWO skeletons had DW_AT_stmt_list]
7518 if (dwarf_read_debug
)
7519 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7521 /* Sort in a separate table to maintain the order of all_type_units
7522 for .gdb_index: TU indices directly index all_type_units. */
7523 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7524 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7526 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7527 sorted_by_abbrev
.emplace_back
7528 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7529 sig_type
->per_cu
.section
,
7530 sig_type
->per_cu
.sect_off
));
7532 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7533 sort_tu_by_abbrev_offset
);
7535 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7537 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7539 /* Switch to the next abbrev table if necessary. */
7540 if (abbrev_table
== NULL
7541 || tu
.abbrev_offset
!= abbrev_offset
)
7543 abbrev_offset
= tu
.abbrev_offset
;
7545 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7546 &dwarf2_per_objfile
->abbrev
,
7548 ++tu_stats
->nr_uniq_abbrev_tables
;
7551 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7553 if (!reader
.dummy_p
)
7554 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7555 reader
.comp_unit_die
);
7559 /* Print collected type unit statistics. */
7562 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7564 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7566 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7567 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7568 dwarf2_per_objfile
->all_type_units
.size ());
7569 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7570 tu_stats
->nr_uniq_abbrev_tables
);
7571 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7572 tu_stats
->nr_symtabs
);
7573 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7574 tu_stats
->nr_symtab_sharers
);
7575 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7576 tu_stats
->nr_stmt_less_type_units
);
7577 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7578 tu_stats
->nr_all_type_units_reallocs
);
7581 /* Traversal function for build_type_psymtabs. */
7584 build_type_psymtab_dependencies (void **slot
, void *info
)
7586 struct dwarf2_per_objfile
*dwarf2_per_objfile
7587 = (struct dwarf2_per_objfile
*) info
;
7588 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7589 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7590 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7591 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7592 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7595 gdb_assert (len
> 0);
7596 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
7598 pst
->number_of_dependencies
= len
;
7599 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7600 for (i
= 0; i
< len
; ++i
)
7602 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7603 gdb_assert (iter
->per_cu
.is_debug_types
);
7604 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7605 iter
->type_unit_group
= tu_group
;
7608 delete tu_group
->tus
;
7609 tu_group
->tus
= nullptr;
7614 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7615 Build partial symbol tables for the .debug_types comp-units. */
7618 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7620 if (! create_all_type_units (dwarf2_per_objfile
))
7623 build_type_psymtabs_1 (dwarf2_per_objfile
);
7626 /* Traversal function for process_skeletonless_type_unit.
7627 Read a TU in a DWO file and build partial symbols for it. */
7630 process_skeletonless_type_unit (void **slot
, void *info
)
7632 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7633 struct dwarf2_per_objfile
*dwarf2_per_objfile
7634 = (struct dwarf2_per_objfile
*) info
;
7635 struct signatured_type find_entry
, *entry
;
7637 /* If this TU doesn't exist in the global table, add it and read it in. */
7639 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7641 dwarf2_per_objfile
->signatured_types
7642 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
7645 find_entry
.signature
= dwo_unit
->signature
;
7646 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7647 &find_entry
, INSERT
);
7648 /* If we've already seen this type there's nothing to do. What's happening
7649 is we're doing our own version of comdat-folding here. */
7653 /* This does the job that create_all_type_units would have done for
7655 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7656 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7659 /* This does the job that build_type_psymtabs_1 would have done. */
7660 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, 0, false);
7661 if (!reader
.dummy_p
)
7662 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7663 reader
.comp_unit_die
);
7668 /* Traversal function for process_skeletonless_type_units. */
7671 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7673 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7675 if (dwo_file
->tus
!= NULL
)
7676 htab_traverse_noresize (dwo_file
->tus
.get (),
7677 process_skeletonless_type_unit
, info
);
7682 /* Scan all TUs of DWO files, verifying we've processed them.
7683 This is needed in case a TU was emitted without its skeleton.
7684 Note: This can't be done until we know what all the DWO files are. */
7687 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7689 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7690 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7691 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7693 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7694 process_dwo_file_for_skeletonless_type_units
,
7695 dwarf2_per_objfile
);
7699 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7702 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7704 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7706 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7711 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7713 /* Set the 'user' field only if it is not already set. */
7714 if (pst
->dependencies
[j
]->user
== NULL
)
7715 pst
->dependencies
[j
]->user
= pst
;
7720 /* Build the partial symbol table by doing a quick pass through the
7721 .debug_info and .debug_abbrev sections. */
7724 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7726 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7728 if (dwarf_read_debug
)
7730 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7731 objfile_name (objfile
));
7734 dwarf2_per_objfile
->reading_partial_symbols
= 1;
7736 dwarf2_per_objfile
->info
.read (objfile
);
7738 /* Any cached compilation units will be linked by the per-objfile
7739 read_in_chain. Make sure to free them when we're done. */
7740 free_cached_comp_units
freer (dwarf2_per_objfile
);
7742 build_type_psymtabs (dwarf2_per_objfile
);
7744 create_all_comp_units (dwarf2_per_objfile
);
7746 /* Create a temporary address map on a temporary obstack. We later
7747 copy this to the final obstack. */
7748 auto_obstack temp_obstack
;
7750 scoped_restore save_psymtabs_addrmap
7751 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7752 addrmap_create_mutable (&temp_obstack
));
7754 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7755 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
7757 /* This has to wait until we read the CUs, we need the list of DWOs. */
7758 process_skeletonless_type_units (dwarf2_per_objfile
);
7760 /* Now that all TUs have been processed we can fill in the dependencies. */
7761 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7763 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7764 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7767 if (dwarf_read_debug
)
7768 print_tu_stats (dwarf2_per_objfile
);
7770 set_partial_user (dwarf2_per_objfile
);
7772 objfile
->partial_symtabs
->psymtabs_addrmap
7773 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7774 objfile
->partial_symtabs
->obstack ());
7775 /* At this point we want to keep the address map. */
7776 save_psymtabs_addrmap
.release ();
7778 if (dwarf_read_debug
)
7779 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7780 objfile_name (objfile
));
7783 /* Load the partial DIEs for a secondary CU into memory.
7784 This is also used when rereading a primary CU with load_all_dies. */
7787 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7789 cutu_reader
reader (this_cu
, NULL
, 1, 1, false);
7791 if (!reader
.dummy_p
)
7793 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7796 /* Check if comp unit has_children.
7797 If so, read the rest of the partial symbols from this comp unit.
7798 If not, there's no more debug_info for this comp unit. */
7799 if (reader
.comp_unit_die
->has_children
)
7800 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7805 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7806 struct dwarf2_section_info
*section
,
7807 struct dwarf2_section_info
*abbrev_section
,
7808 unsigned int is_dwz
)
7810 const gdb_byte
*info_ptr
;
7811 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7813 if (dwarf_read_debug
)
7814 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7815 section
->get_name (),
7816 section
->get_file_name ());
7818 section
->read (objfile
);
7820 info_ptr
= section
->buffer
;
7822 while (info_ptr
< section
->buffer
+ section
->size
)
7824 struct dwarf2_per_cu_data
*this_cu
;
7826 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7828 comp_unit_head cu_header
;
7829 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7830 abbrev_section
, info_ptr
,
7831 rcuh_kind::COMPILE
);
7833 /* Save the compilation unit for later lookup. */
7834 if (cu_header
.unit_type
!= DW_UT_type
)
7836 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7837 struct dwarf2_per_cu_data
);
7838 memset (this_cu
, 0, sizeof (*this_cu
));
7842 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7843 struct signatured_type
);
7844 memset (sig_type
, 0, sizeof (*sig_type
));
7845 sig_type
->signature
= cu_header
.signature
;
7846 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7847 this_cu
= &sig_type
->per_cu
;
7849 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7850 this_cu
->sect_off
= sect_off
;
7851 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7852 this_cu
->is_dwz
= is_dwz
;
7853 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7854 this_cu
->section
= section
;
7856 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7858 info_ptr
= info_ptr
+ this_cu
->length
;
7862 /* Create a list of all compilation units in OBJFILE.
7863 This is only done for -readnow and building partial symtabs. */
7866 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7868 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7869 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7870 &dwarf2_per_objfile
->abbrev
, 0);
7872 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7874 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7878 /* Process all loaded DIEs for compilation unit CU, starting at
7879 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7880 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7881 DW_AT_ranges). See the comments of add_partial_subprogram on how
7882 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7885 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7886 CORE_ADDR
*highpc
, int set_addrmap
,
7887 struct dwarf2_cu
*cu
)
7889 struct partial_die_info
*pdi
;
7891 /* Now, march along the PDI's, descending into ones which have
7892 interesting children but skipping the children of the other ones,
7893 until we reach the end of the compilation unit. */
7901 /* Anonymous namespaces or modules have no name but have interesting
7902 children, so we need to look at them. Ditto for anonymous
7905 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7906 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7907 || pdi
->tag
== DW_TAG_imported_unit
7908 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7912 case DW_TAG_subprogram
:
7913 case DW_TAG_inlined_subroutine
:
7914 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7916 case DW_TAG_constant
:
7917 case DW_TAG_variable
:
7918 case DW_TAG_typedef
:
7919 case DW_TAG_union_type
:
7920 if (!pdi
->is_declaration
)
7922 add_partial_symbol (pdi
, cu
);
7925 case DW_TAG_class_type
:
7926 case DW_TAG_interface_type
:
7927 case DW_TAG_structure_type
:
7928 if (!pdi
->is_declaration
)
7930 add_partial_symbol (pdi
, cu
);
7932 if ((cu
->language
== language_rust
7933 || cu
->language
== language_cplus
) && pdi
->has_children
)
7934 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7937 case DW_TAG_enumeration_type
:
7938 if (!pdi
->is_declaration
)
7939 add_partial_enumeration (pdi
, cu
);
7941 case DW_TAG_base_type
:
7942 case DW_TAG_subrange_type
:
7943 /* File scope base type definitions are added to the partial
7945 add_partial_symbol (pdi
, cu
);
7947 case DW_TAG_namespace
:
7948 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7951 if (!pdi
->is_declaration
)
7952 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7954 case DW_TAG_imported_unit
:
7956 struct dwarf2_per_cu_data
*per_cu
;
7958 /* For now we don't handle imported units in type units. */
7959 if (cu
->per_cu
->is_debug_types
)
7961 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7962 " supported in type units [in module %s]"),
7963 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7966 per_cu
= dwarf2_find_containing_comp_unit
7967 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7968 cu
->per_cu
->dwarf2_per_objfile
);
7970 /* Go read the partial unit, if needed. */
7971 if (per_cu
->v
.psymtab
== NULL
)
7972 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
7974 cu
->per_cu
->imported_symtabs_push (per_cu
);
7977 case DW_TAG_imported_declaration
:
7978 add_partial_symbol (pdi
, cu
);
7985 /* If the die has a sibling, skip to the sibling. */
7987 pdi
= pdi
->die_sibling
;
7991 /* Functions used to compute the fully scoped name of a partial DIE.
7993 Normally, this is simple. For C++, the parent DIE's fully scoped
7994 name is concatenated with "::" and the partial DIE's name.
7995 Enumerators are an exception; they use the scope of their parent
7996 enumeration type, i.e. the name of the enumeration type is not
7997 prepended to the enumerator.
7999 There are two complexities. One is DW_AT_specification; in this
8000 case "parent" means the parent of the target of the specification,
8001 instead of the direct parent of the DIE. The other is compilers
8002 which do not emit DW_TAG_namespace; in this case we try to guess
8003 the fully qualified name of structure types from their members'
8004 linkage names. This must be done using the DIE's children rather
8005 than the children of any DW_AT_specification target. We only need
8006 to do this for structures at the top level, i.e. if the target of
8007 any DW_AT_specification (if any; otherwise the DIE itself) does not
8010 /* Compute the scope prefix associated with PDI's parent, in
8011 compilation unit CU. The result will be allocated on CU's
8012 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8013 field. NULL is returned if no prefix is necessary. */
8015 partial_die_parent_scope (struct partial_die_info
*pdi
,
8016 struct dwarf2_cu
*cu
)
8018 const char *grandparent_scope
;
8019 struct partial_die_info
*parent
, *real_pdi
;
8021 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8022 then this means the parent of the specification DIE. */
8025 while (real_pdi
->has_specification
)
8027 auto res
= find_partial_die (real_pdi
->spec_offset
,
8028 real_pdi
->spec_is_dwz
, cu
);
8033 parent
= real_pdi
->die_parent
;
8037 if (parent
->scope_set
)
8038 return parent
->scope
;
8042 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8044 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8045 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8046 Work around this problem here. */
8047 if (cu
->language
== language_cplus
8048 && parent
->tag
== DW_TAG_namespace
8049 && strcmp (parent
->name
, "::") == 0
8050 && grandparent_scope
== NULL
)
8052 parent
->scope
= NULL
;
8053 parent
->scope_set
= 1;
8057 /* Nested subroutines in Fortran get a prefix. */
8058 if (pdi
->tag
== DW_TAG_enumerator
)
8059 /* Enumerators should not get the name of the enumeration as a prefix. */
8060 parent
->scope
= grandparent_scope
;
8061 else if (parent
->tag
== DW_TAG_namespace
8062 || parent
->tag
== DW_TAG_module
8063 || parent
->tag
== DW_TAG_structure_type
8064 || parent
->tag
== DW_TAG_class_type
8065 || parent
->tag
== DW_TAG_interface_type
8066 || parent
->tag
== DW_TAG_union_type
8067 || parent
->tag
== DW_TAG_enumeration_type
8068 || (cu
->language
== language_fortran
8069 && parent
->tag
== DW_TAG_subprogram
8070 && pdi
->tag
== DW_TAG_subprogram
))
8072 if (grandparent_scope
== NULL
)
8073 parent
->scope
= parent
->name
;
8075 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8077 parent
->name
, 0, cu
);
8081 /* FIXME drow/2004-04-01: What should we be doing with
8082 function-local names? For partial symbols, we should probably be
8084 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8085 dwarf_tag_name (parent
->tag
),
8086 sect_offset_str (pdi
->sect_off
));
8087 parent
->scope
= grandparent_scope
;
8090 parent
->scope_set
= 1;
8091 return parent
->scope
;
8094 /* Return the fully scoped name associated with PDI, from compilation unit
8095 CU. The result will be allocated with malloc. */
8097 static gdb::unique_xmalloc_ptr
<char>
8098 partial_die_full_name (struct partial_die_info
*pdi
,
8099 struct dwarf2_cu
*cu
)
8101 const char *parent_scope
;
8103 /* If this is a template instantiation, we can not work out the
8104 template arguments from partial DIEs. So, unfortunately, we have
8105 to go through the full DIEs. At least any work we do building
8106 types here will be reused if full symbols are loaded later. */
8107 if (pdi
->has_template_arguments
)
8111 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8113 struct die_info
*die
;
8114 struct attribute attr
;
8115 struct dwarf2_cu
*ref_cu
= cu
;
8117 /* DW_FORM_ref_addr is using section offset. */
8118 attr
.name
= (enum dwarf_attribute
) 0;
8119 attr
.form
= DW_FORM_ref_addr
;
8120 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8121 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8123 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8127 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8128 if (parent_scope
== NULL
)
8131 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8136 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8138 struct dwarf2_per_objfile
*dwarf2_per_objfile
8139 = cu
->per_cu
->dwarf2_per_objfile
;
8140 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8141 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8143 const char *actual_name
= NULL
;
8146 baseaddr
= objfile
->text_section_offset ();
8148 gdb::unique_xmalloc_ptr
<char> built_actual_name
8149 = partial_die_full_name (pdi
, cu
);
8150 if (built_actual_name
!= NULL
)
8151 actual_name
= built_actual_name
.get ();
8153 if (actual_name
== NULL
)
8154 actual_name
= pdi
->name
;
8158 case DW_TAG_inlined_subroutine
:
8159 case DW_TAG_subprogram
:
8160 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8162 if (pdi
->is_external
8163 || cu
->language
== language_ada
8164 || (cu
->language
== language_fortran
8165 && pdi
->die_parent
!= NULL
8166 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8168 /* Normally, only "external" DIEs are part of the global scope.
8169 But in Ada and Fortran, we want to be able to access nested
8170 procedures globally. So all Ada and Fortran subprograms are
8171 stored in the global scope. */
8172 add_psymbol_to_list (actual_name
,
8173 built_actual_name
!= NULL
,
8174 VAR_DOMAIN
, LOC_BLOCK
,
8175 SECT_OFF_TEXT (objfile
),
8176 psymbol_placement::GLOBAL
,
8178 cu
->language
, objfile
);
8182 add_psymbol_to_list (actual_name
,
8183 built_actual_name
!= NULL
,
8184 VAR_DOMAIN
, LOC_BLOCK
,
8185 SECT_OFF_TEXT (objfile
),
8186 psymbol_placement::STATIC
,
8187 addr
, cu
->language
, objfile
);
8190 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8191 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8193 case DW_TAG_constant
:
8194 add_psymbol_to_list (actual_name
,
8195 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8196 -1, (pdi
->is_external
8197 ? psymbol_placement::GLOBAL
8198 : psymbol_placement::STATIC
),
8199 0, cu
->language
, objfile
);
8201 case DW_TAG_variable
:
8203 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8207 && !dwarf2_per_objfile
->has_section_at_zero
)
8209 /* A global or static variable may also have been stripped
8210 out by the linker if unused, in which case its address
8211 will be nullified; do not add such variables into partial
8212 symbol table then. */
8214 else if (pdi
->is_external
)
8217 Don't enter into the minimal symbol tables as there is
8218 a minimal symbol table entry from the ELF symbols already.
8219 Enter into partial symbol table if it has a location
8220 descriptor or a type.
8221 If the location descriptor is missing, new_symbol will create
8222 a LOC_UNRESOLVED symbol, the address of the variable will then
8223 be determined from the minimal symbol table whenever the variable
8225 The address for the partial symbol table entry is not
8226 used by GDB, but it comes in handy for debugging partial symbol
8229 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8230 add_psymbol_to_list (actual_name
,
8231 built_actual_name
!= NULL
,
8232 VAR_DOMAIN
, LOC_STATIC
,
8233 SECT_OFF_TEXT (objfile
),
8234 psymbol_placement::GLOBAL
,
8235 addr
, cu
->language
, objfile
);
8239 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8241 /* Static Variable. Skip symbols whose value we cannot know (those
8242 without location descriptors or constant values). */
8243 if (!has_loc
&& !pdi
->has_const_value
)
8246 add_psymbol_to_list (actual_name
,
8247 built_actual_name
!= NULL
,
8248 VAR_DOMAIN
, LOC_STATIC
,
8249 SECT_OFF_TEXT (objfile
),
8250 psymbol_placement::STATIC
,
8252 cu
->language
, objfile
);
8255 case DW_TAG_typedef
:
8256 case DW_TAG_base_type
:
8257 case DW_TAG_subrange_type
:
8258 add_psymbol_to_list (actual_name
,
8259 built_actual_name
!= NULL
,
8260 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8261 psymbol_placement::STATIC
,
8262 0, cu
->language
, objfile
);
8264 case DW_TAG_imported_declaration
:
8265 case DW_TAG_namespace
:
8266 add_psymbol_to_list (actual_name
,
8267 built_actual_name
!= NULL
,
8268 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8269 psymbol_placement::GLOBAL
,
8270 0, cu
->language
, objfile
);
8273 /* With Fortran 77 there might be a "BLOCK DATA" module
8274 available without any name. If so, we skip the module as it
8275 doesn't bring any value. */
8276 if (actual_name
!= nullptr)
8277 add_psymbol_to_list (actual_name
,
8278 built_actual_name
!= NULL
,
8279 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8280 psymbol_placement::GLOBAL
,
8281 0, cu
->language
, objfile
);
8283 case DW_TAG_class_type
:
8284 case DW_TAG_interface_type
:
8285 case DW_TAG_structure_type
:
8286 case DW_TAG_union_type
:
8287 case DW_TAG_enumeration_type
:
8288 /* Skip external references. The DWARF standard says in the section
8289 about "Structure, Union, and Class Type Entries": "An incomplete
8290 structure, union or class type is represented by a structure,
8291 union or class entry that does not have a byte size attribute
8292 and that has a DW_AT_declaration attribute." */
8293 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8296 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8297 static vs. global. */
8298 add_psymbol_to_list (actual_name
,
8299 built_actual_name
!= NULL
,
8300 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8301 cu
->language
== language_cplus
8302 ? psymbol_placement::GLOBAL
8303 : psymbol_placement::STATIC
,
8304 0, cu
->language
, objfile
);
8307 case DW_TAG_enumerator
:
8308 add_psymbol_to_list (actual_name
,
8309 built_actual_name
!= NULL
,
8310 VAR_DOMAIN
, LOC_CONST
, -1,
8311 cu
->language
== language_cplus
8312 ? psymbol_placement::GLOBAL
8313 : psymbol_placement::STATIC
,
8314 0, cu
->language
, objfile
);
8321 /* Read a partial die corresponding to a namespace; also, add a symbol
8322 corresponding to that namespace to the symbol table. NAMESPACE is
8323 the name of the enclosing namespace. */
8326 add_partial_namespace (struct partial_die_info
*pdi
,
8327 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8328 int set_addrmap
, struct dwarf2_cu
*cu
)
8330 /* Add a symbol for the namespace. */
8332 add_partial_symbol (pdi
, cu
);
8334 /* Now scan partial symbols in that namespace. */
8336 if (pdi
->has_children
)
8337 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8340 /* Read a partial die corresponding to a Fortran module. */
8343 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8344 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8346 /* Add a symbol for the namespace. */
8348 add_partial_symbol (pdi
, cu
);
8350 /* Now scan partial symbols in that module. */
8352 if (pdi
->has_children
)
8353 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8356 /* Read a partial die corresponding to a subprogram or an inlined
8357 subprogram and create a partial symbol for that subprogram.
8358 When the CU language allows it, this routine also defines a partial
8359 symbol for each nested subprogram that this subprogram contains.
8360 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8361 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8363 PDI may also be a lexical block, in which case we simply search
8364 recursively for subprograms defined inside that lexical block.
8365 Again, this is only performed when the CU language allows this
8366 type of definitions. */
8369 add_partial_subprogram (struct partial_die_info
*pdi
,
8370 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8371 int set_addrmap
, struct dwarf2_cu
*cu
)
8373 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8375 if (pdi
->has_pc_info
)
8377 if (pdi
->lowpc
< *lowpc
)
8378 *lowpc
= pdi
->lowpc
;
8379 if (pdi
->highpc
> *highpc
)
8380 *highpc
= pdi
->highpc
;
8383 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8384 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8386 CORE_ADDR this_highpc
;
8387 CORE_ADDR this_lowpc
;
8389 baseaddr
= objfile
->text_section_offset ();
8391 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8392 pdi
->lowpc
+ baseaddr
)
8395 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8396 pdi
->highpc
+ baseaddr
)
8398 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8399 this_lowpc
, this_highpc
- 1,
8400 cu
->per_cu
->v
.psymtab
);
8404 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8406 if (!pdi
->is_declaration
)
8407 /* Ignore subprogram DIEs that do not have a name, they are
8408 illegal. Do not emit a complaint at this point, we will
8409 do so when we convert this psymtab into a symtab. */
8411 add_partial_symbol (pdi
, cu
);
8415 if (! pdi
->has_children
)
8418 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8420 pdi
= pdi
->die_child
;
8424 if (pdi
->tag
== DW_TAG_subprogram
8425 || pdi
->tag
== DW_TAG_inlined_subroutine
8426 || pdi
->tag
== DW_TAG_lexical_block
)
8427 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8428 pdi
= pdi
->die_sibling
;
8433 /* Read a partial die corresponding to an enumeration type. */
8436 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8437 struct dwarf2_cu
*cu
)
8439 struct partial_die_info
*pdi
;
8441 if (enum_pdi
->name
!= NULL
)
8442 add_partial_symbol (enum_pdi
, cu
);
8444 pdi
= enum_pdi
->die_child
;
8447 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8448 complaint (_("malformed enumerator DIE ignored"));
8450 add_partial_symbol (pdi
, cu
);
8451 pdi
= pdi
->die_sibling
;
8455 /* Return the initial uleb128 in the die at INFO_PTR. */
8458 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8460 unsigned int bytes_read
;
8462 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8465 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8466 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8468 Return the corresponding abbrev, or NULL if the number is zero (indicating
8469 an empty DIE). In either case *BYTES_READ will be set to the length of
8470 the initial number. */
8472 static struct abbrev_info
*
8473 peek_die_abbrev (const die_reader_specs
&reader
,
8474 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8476 dwarf2_cu
*cu
= reader
.cu
;
8477 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8478 unsigned int abbrev_number
8479 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8481 if (abbrev_number
== 0)
8484 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8487 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8488 " at offset %s [in module %s]"),
8489 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8490 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8496 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8497 Returns a pointer to the end of a series of DIEs, terminated by an empty
8498 DIE. Any children of the skipped DIEs will also be skipped. */
8500 static const gdb_byte
*
8501 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8505 unsigned int bytes_read
;
8506 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8509 return info_ptr
+ bytes_read
;
8511 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8515 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8516 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8517 abbrev corresponding to that skipped uleb128 should be passed in
8518 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8521 static const gdb_byte
*
8522 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8523 struct abbrev_info
*abbrev
)
8525 unsigned int bytes_read
;
8526 struct attribute attr
;
8527 bfd
*abfd
= reader
->abfd
;
8528 struct dwarf2_cu
*cu
= reader
->cu
;
8529 const gdb_byte
*buffer
= reader
->buffer
;
8530 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8531 unsigned int form
, i
;
8533 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8535 /* The only abbrev we care about is DW_AT_sibling. */
8536 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8539 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8541 if (attr
.form
== DW_FORM_ref_addr
)
8542 complaint (_("ignoring absolute DW_AT_sibling"));
8545 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8546 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8548 if (sibling_ptr
< info_ptr
)
8549 complaint (_("DW_AT_sibling points backwards"));
8550 else if (sibling_ptr
> reader
->buffer_end
)
8551 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
8557 /* If it isn't DW_AT_sibling, skip this attribute. */
8558 form
= abbrev
->attrs
[i
].form
;
8562 case DW_FORM_ref_addr
:
8563 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8564 and later it is offset sized. */
8565 if (cu
->header
.version
== 2)
8566 info_ptr
+= cu
->header
.addr_size
;
8568 info_ptr
+= cu
->header
.offset_size
;
8570 case DW_FORM_GNU_ref_alt
:
8571 info_ptr
+= cu
->header
.offset_size
;
8574 info_ptr
+= cu
->header
.addr_size
;
8582 case DW_FORM_flag_present
:
8583 case DW_FORM_implicit_const
:
8600 case DW_FORM_ref_sig8
:
8603 case DW_FORM_data16
:
8606 case DW_FORM_string
:
8607 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8608 info_ptr
+= bytes_read
;
8610 case DW_FORM_sec_offset
:
8612 case DW_FORM_GNU_strp_alt
:
8613 info_ptr
+= cu
->header
.offset_size
;
8615 case DW_FORM_exprloc
:
8617 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8618 info_ptr
+= bytes_read
;
8620 case DW_FORM_block1
:
8621 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8623 case DW_FORM_block2
:
8624 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8626 case DW_FORM_block4
:
8627 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8633 case DW_FORM_ref_udata
:
8634 case DW_FORM_GNU_addr_index
:
8635 case DW_FORM_GNU_str_index
:
8636 case DW_FORM_rnglistx
:
8637 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8639 case DW_FORM_indirect
:
8640 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8641 info_ptr
+= bytes_read
;
8642 /* We need to continue parsing from here, so just go back to
8644 goto skip_attribute
;
8647 error (_("Dwarf Error: Cannot handle %s "
8648 "in DWARF reader [in module %s]"),
8649 dwarf_form_name (form
),
8650 bfd_get_filename (abfd
));
8654 if (abbrev
->has_children
)
8655 return skip_children (reader
, info_ptr
);
8660 /* Locate ORIG_PDI's sibling.
8661 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8663 static const gdb_byte
*
8664 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8665 struct partial_die_info
*orig_pdi
,
8666 const gdb_byte
*info_ptr
)
8668 /* Do we know the sibling already? */
8670 if (orig_pdi
->sibling
)
8671 return orig_pdi
->sibling
;
8673 /* Are there any children to deal with? */
8675 if (!orig_pdi
->has_children
)
8678 /* Skip the children the long way. */
8680 return skip_children (reader
, info_ptr
);
8683 /* Expand this partial symbol table into a full symbol table. SELF is
8687 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8689 struct dwarf2_per_objfile
*dwarf2_per_objfile
8690 = get_dwarf2_per_objfile (objfile
);
8692 gdb_assert (!readin
);
8693 /* If this psymtab is constructed from a debug-only objfile, the
8694 has_section_at_zero flag will not necessarily be correct. We
8695 can get the correct value for this flag by looking at the data
8696 associated with the (presumably stripped) associated objfile. */
8697 if (objfile
->separate_debug_objfile_backlink
)
8699 struct dwarf2_per_objfile
*dpo_backlink
8700 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8702 dwarf2_per_objfile
->has_section_at_zero
8703 = dpo_backlink
->has_section_at_zero
;
8706 dwarf2_per_objfile
->reading_partial_symbols
= 0;
8708 expand_psymtab (objfile
);
8710 process_cu_includes (dwarf2_per_objfile
);
8713 /* Reading in full CUs. */
8715 /* Add PER_CU to the queue. */
8718 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8719 enum language pretend_language
)
8722 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8725 /* If PER_CU is not yet queued, add it to the queue.
8726 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8728 The result is non-zero if PER_CU was queued, otherwise the result is zero
8729 meaning either PER_CU is already queued or it is already loaded.
8731 N.B. There is an invariant here that if a CU is queued then it is loaded.
8732 The caller is required to load PER_CU if we return non-zero. */
8735 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8736 struct dwarf2_per_cu_data
*per_cu
,
8737 enum language pretend_language
)
8739 /* We may arrive here during partial symbol reading, if we need full
8740 DIEs to process an unusual case (e.g. template arguments). Do
8741 not queue PER_CU, just tell our caller to load its DIEs. */
8742 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8744 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8749 /* Mark the dependence relation so that we don't flush PER_CU
8751 if (dependent_cu
!= NULL
)
8752 dwarf2_add_dependence (dependent_cu
, per_cu
);
8754 /* If it's already on the queue, we have nothing to do. */
8758 /* If the compilation unit is already loaded, just mark it as
8760 if (per_cu
->cu
!= NULL
)
8762 per_cu
->cu
->last_used
= 0;
8766 /* Add it to the queue. */
8767 queue_comp_unit (per_cu
, pretend_language
);
8772 /* Process the queue. */
8775 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8777 if (dwarf_read_debug
)
8779 fprintf_unfiltered (gdb_stdlog
,
8780 "Expanding one or more symtabs of objfile %s ...\n",
8781 objfile_name (dwarf2_per_objfile
->objfile
));
8784 /* The queue starts out with one item, but following a DIE reference
8785 may load a new CU, adding it to the end of the queue. */
8786 while (!dwarf2_per_objfile
->queue
.empty ())
8788 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8790 if ((dwarf2_per_objfile
->using_index
8791 ? !item
.per_cu
->v
.quick
->compunit_symtab
8792 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8793 /* Skip dummy CUs. */
8794 && item
.per_cu
->cu
!= NULL
)
8796 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8797 unsigned int debug_print_threshold
;
8800 if (per_cu
->is_debug_types
)
8802 struct signatured_type
*sig_type
=
8803 (struct signatured_type
*) per_cu
;
8805 sprintf (buf
, "TU %s at offset %s",
8806 hex_string (sig_type
->signature
),
8807 sect_offset_str (per_cu
->sect_off
));
8808 /* There can be 100s of TUs.
8809 Only print them in verbose mode. */
8810 debug_print_threshold
= 2;
8814 sprintf (buf
, "CU at offset %s",
8815 sect_offset_str (per_cu
->sect_off
));
8816 debug_print_threshold
= 1;
8819 if (dwarf_read_debug
>= debug_print_threshold
)
8820 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8822 if (per_cu
->is_debug_types
)
8823 process_full_type_unit (per_cu
, item
.pretend_language
);
8825 process_full_comp_unit (per_cu
, item
.pretend_language
);
8827 if (dwarf_read_debug
>= debug_print_threshold
)
8828 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8831 item
.per_cu
->queued
= 0;
8832 dwarf2_per_objfile
->queue
.pop ();
8835 if (dwarf_read_debug
)
8837 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8838 objfile_name (dwarf2_per_objfile
->objfile
));
8842 /* Read in full symbols for PST, and anything it depends on. */
8845 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8847 struct dwarf2_per_cu_data
*per_cu
;
8852 read_dependencies (objfile
);
8854 per_cu
= per_cu_data
;
8858 /* It's an include file, no symbols to read for it.
8859 Everything is in the parent symtab. */
8864 dw2_do_instantiate_symtab (per_cu
, false);
8867 /* Trivial hash function for die_info: the hash value of a DIE
8868 is its offset in .debug_info for this objfile. */
8871 die_hash (const void *item
)
8873 const struct die_info
*die
= (const struct die_info
*) item
;
8875 return to_underlying (die
->sect_off
);
8878 /* Trivial comparison function for die_info structures: two DIEs
8879 are equal if they have the same offset. */
8882 die_eq (const void *item_lhs
, const void *item_rhs
)
8884 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8885 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8887 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8890 /* Load the DIEs associated with PER_CU into memory. */
8893 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8895 enum language pretend_language
)
8897 gdb_assert (! this_cu
->is_debug_types
);
8899 cutu_reader
reader (this_cu
, NULL
, 1, 1, skip_partial
);
8903 struct dwarf2_cu
*cu
= reader
.cu
;
8904 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8906 gdb_assert (cu
->die_hash
== NULL
);
8908 htab_create_alloc_ex (cu
->header
.length
/ 12,
8912 &cu
->comp_unit_obstack
,
8913 hashtab_obstack_allocate
,
8914 dummy_obstack_deallocate
);
8916 if (reader
.comp_unit_die
->has_children
)
8917 reader
.comp_unit_die
->child
8918 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8919 &info_ptr
, reader
.comp_unit_die
);
8920 cu
->dies
= reader
.comp_unit_die
;
8921 /* comp_unit_die is not stored in die_hash, no need. */
8923 /* We try not to read any attributes in this function, because not
8924 all CUs needed for references have been loaded yet, and symbol
8925 table processing isn't initialized. But we have to set the CU language,
8926 or we won't be able to build types correctly.
8927 Similarly, if we do not read the producer, we can not apply
8928 producer-specific interpretation. */
8929 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8932 /* Add a DIE to the delayed physname list. */
8935 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8936 const char *name
, struct die_info
*die
,
8937 struct dwarf2_cu
*cu
)
8939 struct delayed_method_info mi
;
8941 mi
.fnfield_index
= fnfield_index
;
8945 cu
->method_list
.push_back (mi
);
8948 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8949 "const" / "volatile". If so, decrements LEN by the length of the
8950 modifier and return true. Otherwise return false. */
8954 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8956 size_t mod_len
= sizeof (mod
) - 1;
8957 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8965 /* Compute the physnames of any methods on the CU's method list.
8967 The computation of method physnames is delayed in order to avoid the
8968 (bad) condition that one of the method's formal parameters is of an as yet
8972 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8974 /* Only C++ delays computing physnames. */
8975 if (cu
->method_list
.empty ())
8977 gdb_assert (cu
->language
== language_cplus
);
8979 for (const delayed_method_info
&mi
: cu
->method_list
)
8981 const char *physname
;
8982 struct fn_fieldlist
*fn_flp
8983 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8984 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8985 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8986 = physname
? physname
: "";
8988 /* Since there's no tag to indicate whether a method is a
8989 const/volatile overload, extract that information out of the
8991 if (physname
!= NULL
)
8993 size_t len
= strlen (physname
);
8997 if (physname
[len
] == ')') /* shortcut */
8999 else if (check_modifier (physname
, len
, " const"))
9000 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9001 else if (check_modifier (physname
, len
, " volatile"))
9002 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9009 /* The list is no longer needed. */
9010 cu
->method_list
.clear ();
9013 /* Go objects should be embedded in a DW_TAG_module DIE,
9014 and it's not clear if/how imported objects will appear.
9015 To keep Go support simple until that's worked out,
9016 go back through what we've read and create something usable.
9017 We could do this while processing each DIE, and feels kinda cleaner,
9018 but that way is more invasive.
9019 This is to, for example, allow the user to type "p var" or "b main"
9020 without having to specify the package name, and allow lookups
9021 of module.object to work in contexts that use the expression
9025 fixup_go_packaging (struct dwarf2_cu
*cu
)
9027 gdb::unique_xmalloc_ptr
<char> package_name
;
9028 struct pending
*list
;
9031 for (list
= *cu
->get_builder ()->get_global_symbols ();
9035 for (i
= 0; i
< list
->nsyms
; ++i
)
9037 struct symbol
*sym
= list
->symbol
[i
];
9039 if (sym
->language () == language_go
9040 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9042 gdb::unique_xmalloc_ptr
<char> this_package_name
9043 (go_symbol_package_name (sym
));
9045 if (this_package_name
== NULL
)
9047 if (package_name
== NULL
)
9048 package_name
= std::move (this_package_name
);
9051 struct objfile
*objfile
9052 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9053 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9054 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9055 (symbol_symtab (sym
) != NULL
9056 ? symtab_to_filename_for_display
9057 (symbol_symtab (sym
))
9058 : objfile_name (objfile
)),
9059 this_package_name
.get (), package_name
.get ());
9065 if (package_name
!= NULL
)
9067 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9068 const char *saved_package_name
9069 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9070 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9071 saved_package_name
);
9074 sym
= allocate_symbol (objfile
);
9075 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9076 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9077 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9078 e.g., "main" finds the "main" module and not C's main(). */
9079 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9080 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9081 SYMBOL_TYPE (sym
) = type
;
9083 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9087 /* Allocate a fully-qualified name consisting of the two parts on the
9091 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9093 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9096 /* A helper that allocates a struct discriminant_info to attach to a
9099 static struct discriminant_info
*
9100 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9103 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9104 gdb_assert (discriminant_index
== -1
9105 || (discriminant_index
>= 0
9106 && discriminant_index
< TYPE_NFIELDS (type
)));
9107 gdb_assert (default_index
== -1
9108 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9110 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9112 struct discriminant_info
*disc
9113 = ((struct discriminant_info
*)
9115 offsetof (struct discriminant_info
, discriminants
)
9116 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9117 disc
->default_index
= default_index
;
9118 disc
->discriminant_index
= discriminant_index
;
9120 struct dynamic_prop prop
;
9121 prop
.kind
= PROP_UNDEFINED
;
9122 prop
.data
.baton
= disc
;
9124 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9129 /* Some versions of rustc emitted enums in an unusual way.
9131 Ordinary enums were emitted as unions. The first element of each
9132 structure in the union was named "RUST$ENUM$DISR". This element
9133 held the discriminant.
9135 These versions of Rust also implemented the "non-zero"
9136 optimization. When the enum had two values, and one is empty and
9137 the other holds a pointer that cannot be zero, the pointer is used
9138 as the discriminant, with a zero value meaning the empty variant.
9139 Here, the union's first member is of the form
9140 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9141 where the fieldnos are the indices of the fields that should be
9142 traversed in order to find the field (which may be several fields deep)
9143 and the variantname is the name of the variant of the case when the
9146 This function recognizes whether TYPE is of one of these forms,
9147 and, if so, smashes it to be a variant type. */
9150 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9152 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9154 /* We don't need to deal with empty enums. */
9155 if (TYPE_NFIELDS (type
) == 0)
9158 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9159 if (TYPE_NFIELDS (type
) == 1
9160 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9162 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9164 /* Decode the field name to find the offset of the
9166 ULONGEST bit_offset
= 0;
9167 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9168 while (name
[0] >= '0' && name
[0] <= '9')
9171 unsigned long index
= strtoul (name
, &tail
, 10);
9174 || index
>= TYPE_NFIELDS (field_type
)
9175 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9176 != FIELD_LOC_KIND_BITPOS
))
9178 complaint (_("Could not parse Rust enum encoding string \"%s\""
9180 TYPE_FIELD_NAME (type
, 0),
9181 objfile_name (objfile
));
9186 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9187 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9190 /* Make a union to hold the variants. */
9191 struct type
*union_type
= alloc_type (objfile
);
9192 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9193 TYPE_NFIELDS (union_type
) = 3;
9194 TYPE_FIELDS (union_type
)
9195 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9196 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9197 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9199 /* Put the discriminant must at index 0. */
9200 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9201 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9202 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9203 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9205 /* The order of fields doesn't really matter, so put the real
9206 field at index 1 and the data-less field at index 2. */
9207 struct discriminant_info
*disc
9208 = alloc_discriminant_info (union_type
, 0, 1);
9209 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9210 TYPE_FIELD_NAME (union_type
, 1)
9211 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9212 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9213 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9214 TYPE_FIELD_NAME (union_type
, 1));
9216 const char *dataless_name
9217 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9219 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9221 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9222 /* NAME points into the original discriminant name, which
9223 already has the correct lifetime. */
9224 TYPE_FIELD_NAME (union_type
, 2) = name
;
9225 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9226 disc
->discriminants
[2] = 0;
9228 /* Smash this type to be a structure type. We have to do this
9229 because the type has already been recorded. */
9230 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9231 TYPE_NFIELDS (type
) = 1;
9233 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9235 /* Install the variant part. */
9236 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9237 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9238 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9240 /* A union with a single anonymous field is probably an old-style
9242 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9244 /* Smash this type to be a structure type. We have to do this
9245 because the type has already been recorded. */
9246 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9248 /* Make a union to hold the variants. */
9249 struct type
*union_type
= alloc_type (objfile
);
9250 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9251 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9252 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9253 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9254 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9256 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9257 const char *variant_name
9258 = rust_last_path_segment (TYPE_NAME (field_type
));
9259 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9260 TYPE_NAME (field_type
)
9261 = rust_fully_qualify (&objfile
->objfile_obstack
,
9262 TYPE_NAME (type
), variant_name
);
9264 /* Install the union in the outer struct type. */
9265 TYPE_NFIELDS (type
) = 1;
9267 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9268 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9269 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9270 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9272 alloc_discriminant_info (union_type
, -1, 0);
9276 struct type
*disr_type
= nullptr;
9277 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9279 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9281 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9283 /* All fields of a true enum will be structs. */
9286 else if (TYPE_NFIELDS (disr_type
) == 0)
9288 /* Could be data-less variant, so keep going. */
9289 disr_type
= nullptr;
9291 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9292 "RUST$ENUM$DISR") != 0)
9294 /* Not a Rust enum. */
9304 /* If we got here without a discriminant, then it's probably
9306 if (disr_type
== nullptr)
9309 /* Smash this type to be a structure type. We have to do this
9310 because the type has already been recorded. */
9311 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9313 /* Make a union to hold the variants. */
9314 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9315 struct type
*union_type
= alloc_type (objfile
);
9316 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9317 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9318 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9319 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9320 TYPE_FIELDS (union_type
)
9321 = (struct field
*) TYPE_ZALLOC (union_type
,
9322 (TYPE_NFIELDS (union_type
)
9323 * sizeof (struct field
)));
9325 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9326 TYPE_NFIELDS (type
) * sizeof (struct field
));
9328 /* Install the discriminant at index 0 in the union. */
9329 TYPE_FIELD (union_type
, 0) = *disr_field
;
9330 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9331 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9333 /* Install the union in the outer struct type. */
9334 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9335 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9336 TYPE_NFIELDS (type
) = 1;
9338 /* Set the size and offset of the union type. */
9339 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9341 /* We need a way to find the correct discriminant given a
9342 variant name. For convenience we build a map here. */
9343 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9344 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9345 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9347 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9350 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9351 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9355 int n_fields
= TYPE_NFIELDS (union_type
);
9356 struct discriminant_info
*disc
9357 = alloc_discriminant_info (union_type
, 0, -1);
9358 /* Skip the discriminant here. */
9359 for (int i
= 1; i
< n_fields
; ++i
)
9361 /* Find the final word in the name of this variant's type.
9362 That name can be used to look up the correct
9364 const char *variant_name
9365 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9368 auto iter
= discriminant_map
.find (variant_name
);
9369 if (iter
!= discriminant_map
.end ())
9370 disc
->discriminants
[i
] = iter
->second
;
9372 /* Remove the discriminant field, if it exists. */
9373 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9374 if (TYPE_NFIELDS (sub_type
) > 0)
9376 --TYPE_NFIELDS (sub_type
);
9377 ++TYPE_FIELDS (sub_type
);
9379 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9380 TYPE_NAME (sub_type
)
9381 = rust_fully_qualify (&objfile
->objfile_obstack
,
9382 TYPE_NAME (type
), variant_name
);
9387 /* Rewrite some Rust unions to be structures with variants parts. */
9390 rust_union_quirks (struct dwarf2_cu
*cu
)
9392 gdb_assert (cu
->language
== language_rust
);
9393 for (type
*type_
: cu
->rust_unions
)
9394 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9395 /* We don't need this any more. */
9396 cu
->rust_unions
.clear ();
9399 /* Return the symtab for PER_CU. This works properly regardless of
9400 whether we're using the index or psymtabs. */
9402 static struct compunit_symtab
*
9403 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9405 return (per_cu
->dwarf2_per_objfile
->using_index
9406 ? per_cu
->v
.quick
->compunit_symtab
9407 : per_cu
->v
.psymtab
->compunit_symtab
);
9410 /* A helper function for computing the list of all symbol tables
9411 included by PER_CU. */
9414 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9415 htab_t all_children
, htab_t all_type_symtabs
,
9416 struct dwarf2_per_cu_data
*per_cu
,
9417 struct compunit_symtab
*immediate_parent
)
9420 struct compunit_symtab
*cust
;
9422 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9425 /* This inclusion and its children have been processed. */
9430 /* Only add a CU if it has a symbol table. */
9431 cust
= get_compunit_symtab (per_cu
);
9434 /* If this is a type unit only add its symbol table if we haven't
9435 seen it yet (type unit per_cu's can share symtabs). */
9436 if (per_cu
->is_debug_types
)
9438 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9442 result
->push_back (cust
);
9443 if (cust
->user
== NULL
)
9444 cust
->user
= immediate_parent
;
9449 result
->push_back (cust
);
9450 if (cust
->user
== NULL
)
9451 cust
->user
= immediate_parent
;
9455 if (!per_cu
->imported_symtabs_empty ())
9456 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9458 recursively_compute_inclusions (result
, all_children
,
9459 all_type_symtabs
, ptr
, cust
);
9463 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9467 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9469 gdb_assert (! per_cu
->is_debug_types
);
9471 if (!per_cu
->imported_symtabs_empty ())
9474 std::vector
<compunit_symtab
*> result_symtabs
;
9475 htab_t all_children
, all_type_symtabs
;
9476 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9478 /* If we don't have a symtab, we can just skip this case. */
9482 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9483 NULL
, xcalloc
, xfree
);
9484 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9485 NULL
, xcalloc
, xfree
);
9487 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9489 recursively_compute_inclusions (&result_symtabs
, all_children
,
9490 all_type_symtabs
, ptr
, cust
);
9493 /* Now we have a transitive closure of all the included symtabs. */
9494 len
= result_symtabs
.size ();
9496 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9497 struct compunit_symtab
*, len
+ 1);
9498 memcpy (cust
->includes
, result_symtabs
.data (),
9499 len
* sizeof (compunit_symtab
*));
9500 cust
->includes
[len
] = NULL
;
9502 htab_delete (all_children
);
9503 htab_delete (all_type_symtabs
);
9507 /* Compute the 'includes' field for the symtabs of all the CUs we just
9511 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9513 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9515 if (! iter
->is_debug_types
)
9516 compute_compunit_symtab_includes (iter
);
9519 dwarf2_per_objfile
->just_read_cus
.clear ();
9522 /* Generate full symbol information for PER_CU, whose DIEs have
9523 already been loaded into memory. */
9526 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9527 enum language pretend_language
)
9529 struct dwarf2_cu
*cu
= per_cu
->cu
;
9530 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9531 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9532 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9533 CORE_ADDR lowpc
, highpc
;
9534 struct compunit_symtab
*cust
;
9536 struct block
*static_block
;
9539 baseaddr
= objfile
->text_section_offset ();
9541 /* Clear the list here in case something was left over. */
9542 cu
->method_list
.clear ();
9544 cu
->language
= pretend_language
;
9545 cu
->language_defn
= language_def (cu
->language
);
9547 /* Do line number decoding in read_file_scope () */
9548 process_die (cu
->dies
, cu
);
9550 /* For now fudge the Go package. */
9551 if (cu
->language
== language_go
)
9552 fixup_go_packaging (cu
);
9554 /* Now that we have processed all the DIEs in the CU, all the types
9555 should be complete, and it should now be safe to compute all of the
9557 compute_delayed_physnames (cu
);
9559 if (cu
->language
== language_rust
)
9560 rust_union_quirks (cu
);
9562 /* Some compilers don't define a DW_AT_high_pc attribute for the
9563 compilation unit. If the DW_AT_high_pc is missing, synthesize
9564 it, by scanning the DIE's below the compilation unit. */
9565 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9567 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9568 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9570 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9571 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9572 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9573 addrmap to help ensure it has an accurate map of pc values belonging to
9575 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9577 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9578 SECT_OFF_TEXT (objfile
),
9583 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9585 /* Set symtab language to language from DW_AT_language. If the
9586 compilation is from a C file generated by language preprocessors, do
9587 not set the language if it was already deduced by start_subfile. */
9588 if (!(cu
->language
== language_c
9589 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9590 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9592 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9593 produce DW_AT_location with location lists but it can be possibly
9594 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9595 there were bugs in prologue debug info, fixed later in GCC-4.5
9596 by "unwind info for epilogues" patch (which is not directly related).
9598 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9599 needed, it would be wrong due to missing DW_AT_producer there.
9601 Still one can confuse GDB by using non-standard GCC compilation
9602 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9604 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9605 cust
->locations_valid
= 1;
9607 if (gcc_4_minor
>= 5)
9608 cust
->epilogue_unwind_valid
= 1;
9610 cust
->call_site_htab
= cu
->call_site_htab
;
9613 if (dwarf2_per_objfile
->using_index
)
9614 per_cu
->v
.quick
->compunit_symtab
= cust
;
9617 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9618 pst
->compunit_symtab
= cust
;
9622 /* Push it for inclusion processing later. */
9623 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9625 /* Not needed any more. */
9626 cu
->reset_builder ();
9629 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9630 already been loaded into memory. */
9633 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9634 enum language pretend_language
)
9636 struct dwarf2_cu
*cu
= per_cu
->cu
;
9637 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9638 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9639 struct compunit_symtab
*cust
;
9640 struct signatured_type
*sig_type
;
9642 gdb_assert (per_cu
->is_debug_types
);
9643 sig_type
= (struct signatured_type
*) per_cu
;
9645 /* Clear the list here in case something was left over. */
9646 cu
->method_list
.clear ();
9648 cu
->language
= pretend_language
;
9649 cu
->language_defn
= language_def (cu
->language
);
9651 /* The symbol tables are set up in read_type_unit_scope. */
9652 process_die (cu
->dies
, cu
);
9654 /* For now fudge the Go package. */
9655 if (cu
->language
== language_go
)
9656 fixup_go_packaging (cu
);
9658 /* Now that we have processed all the DIEs in the CU, all the types
9659 should be complete, and it should now be safe to compute all of the
9661 compute_delayed_physnames (cu
);
9663 if (cu
->language
== language_rust
)
9664 rust_union_quirks (cu
);
9666 /* TUs share symbol tables.
9667 If this is the first TU to use this symtab, complete the construction
9668 of it with end_expandable_symtab. Otherwise, complete the addition of
9669 this TU's symbols to the existing symtab. */
9670 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9672 buildsym_compunit
*builder
= cu
->get_builder ();
9673 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9674 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9678 /* Set symtab language to language from DW_AT_language. If the
9679 compilation is from a C file generated by language preprocessors,
9680 do not set the language if it was already deduced by
9682 if (!(cu
->language
== language_c
9683 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9684 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9689 cu
->get_builder ()->augment_type_symtab ();
9690 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9693 if (dwarf2_per_objfile
->using_index
)
9694 per_cu
->v
.quick
->compunit_symtab
= cust
;
9697 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9698 pst
->compunit_symtab
= cust
;
9702 /* Not needed any more. */
9703 cu
->reset_builder ();
9706 /* Process an imported unit DIE. */
9709 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9711 struct attribute
*attr
;
9713 /* For now we don't handle imported units in type units. */
9714 if (cu
->per_cu
->is_debug_types
)
9716 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9717 " supported in type units [in module %s]"),
9718 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9721 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9724 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9725 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9726 dwarf2_per_cu_data
*per_cu
9727 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9728 cu
->per_cu
->dwarf2_per_objfile
);
9730 /* If necessary, add it to the queue and load its DIEs. */
9731 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9732 load_full_comp_unit (per_cu
, false, cu
->language
);
9734 cu
->per_cu
->imported_symtabs_push (per_cu
);
9738 /* RAII object that represents a process_die scope: i.e.,
9739 starts/finishes processing a DIE. */
9740 class process_die_scope
9743 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9744 : m_die (die
), m_cu (cu
)
9746 /* We should only be processing DIEs not already in process. */
9747 gdb_assert (!m_die
->in_process
);
9748 m_die
->in_process
= true;
9751 ~process_die_scope ()
9753 m_die
->in_process
= false;
9755 /* If we're done processing the DIE for the CU that owns the line
9756 header, we don't need the line header anymore. */
9757 if (m_cu
->line_header_die_owner
== m_die
)
9759 delete m_cu
->line_header
;
9760 m_cu
->line_header
= NULL
;
9761 m_cu
->line_header_die_owner
= NULL
;
9770 /* Process a die and its children. */
9773 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9775 process_die_scope
scope (die
, cu
);
9779 case DW_TAG_padding
:
9781 case DW_TAG_compile_unit
:
9782 case DW_TAG_partial_unit
:
9783 read_file_scope (die
, cu
);
9785 case DW_TAG_type_unit
:
9786 read_type_unit_scope (die
, cu
);
9788 case DW_TAG_subprogram
:
9789 /* Nested subprograms in Fortran get a prefix. */
9790 if (cu
->language
== language_fortran
9791 && die
->parent
!= NULL
9792 && die
->parent
->tag
== DW_TAG_subprogram
)
9793 cu
->processing_has_namespace_info
= true;
9795 case DW_TAG_inlined_subroutine
:
9796 read_func_scope (die
, cu
);
9798 case DW_TAG_lexical_block
:
9799 case DW_TAG_try_block
:
9800 case DW_TAG_catch_block
:
9801 read_lexical_block_scope (die
, cu
);
9803 case DW_TAG_call_site
:
9804 case DW_TAG_GNU_call_site
:
9805 read_call_site_scope (die
, cu
);
9807 case DW_TAG_class_type
:
9808 case DW_TAG_interface_type
:
9809 case DW_TAG_structure_type
:
9810 case DW_TAG_union_type
:
9811 process_structure_scope (die
, cu
);
9813 case DW_TAG_enumeration_type
:
9814 process_enumeration_scope (die
, cu
);
9817 /* These dies have a type, but processing them does not create
9818 a symbol or recurse to process the children. Therefore we can
9819 read them on-demand through read_type_die. */
9820 case DW_TAG_subroutine_type
:
9821 case DW_TAG_set_type
:
9822 case DW_TAG_array_type
:
9823 case DW_TAG_pointer_type
:
9824 case DW_TAG_ptr_to_member_type
:
9825 case DW_TAG_reference_type
:
9826 case DW_TAG_rvalue_reference_type
:
9827 case DW_TAG_string_type
:
9830 case DW_TAG_base_type
:
9831 case DW_TAG_subrange_type
:
9832 case DW_TAG_typedef
:
9833 /* Add a typedef symbol for the type definition, if it has a
9835 new_symbol (die
, read_type_die (die
, cu
), cu
);
9837 case DW_TAG_common_block
:
9838 read_common_block (die
, cu
);
9840 case DW_TAG_common_inclusion
:
9842 case DW_TAG_namespace
:
9843 cu
->processing_has_namespace_info
= true;
9844 read_namespace (die
, cu
);
9847 cu
->processing_has_namespace_info
= true;
9848 read_module (die
, cu
);
9850 case DW_TAG_imported_declaration
:
9851 cu
->processing_has_namespace_info
= true;
9852 if (read_namespace_alias (die
, cu
))
9854 /* The declaration is not a global namespace alias. */
9856 case DW_TAG_imported_module
:
9857 cu
->processing_has_namespace_info
= true;
9858 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9859 || cu
->language
!= language_fortran
))
9860 complaint (_("Tag '%s' has unexpected children"),
9861 dwarf_tag_name (die
->tag
));
9862 read_import_statement (die
, cu
);
9865 case DW_TAG_imported_unit
:
9866 process_imported_unit_die (die
, cu
);
9869 case DW_TAG_variable
:
9870 read_variable (die
, cu
);
9874 new_symbol (die
, NULL
, cu
);
9879 /* DWARF name computation. */
9881 /* A helper function for dwarf2_compute_name which determines whether DIE
9882 needs to have the name of the scope prepended to the name listed in the
9886 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9888 struct attribute
*attr
;
9892 case DW_TAG_namespace
:
9893 case DW_TAG_typedef
:
9894 case DW_TAG_class_type
:
9895 case DW_TAG_interface_type
:
9896 case DW_TAG_structure_type
:
9897 case DW_TAG_union_type
:
9898 case DW_TAG_enumeration_type
:
9899 case DW_TAG_enumerator
:
9900 case DW_TAG_subprogram
:
9901 case DW_TAG_inlined_subroutine
:
9903 case DW_TAG_imported_declaration
:
9906 case DW_TAG_variable
:
9907 case DW_TAG_constant
:
9908 /* We only need to prefix "globally" visible variables. These include
9909 any variable marked with DW_AT_external or any variable that
9910 lives in a namespace. [Variables in anonymous namespaces
9911 require prefixing, but they are not DW_AT_external.] */
9913 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9915 struct dwarf2_cu
*spec_cu
= cu
;
9917 return die_needs_namespace (die_specification (die
, &spec_cu
),
9921 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9922 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9923 && die
->parent
->tag
!= DW_TAG_module
)
9925 /* A variable in a lexical block of some kind does not need a
9926 namespace, even though in C++ such variables may be external
9927 and have a mangled name. */
9928 if (die
->parent
->tag
== DW_TAG_lexical_block
9929 || die
->parent
->tag
== DW_TAG_try_block
9930 || die
->parent
->tag
== DW_TAG_catch_block
9931 || die
->parent
->tag
== DW_TAG_subprogram
)
9940 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9941 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9942 defined for the given DIE. */
9944 static struct attribute
*
9945 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9947 struct attribute
*attr
;
9949 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9951 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9956 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9957 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9958 defined for the given DIE. */
9961 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9963 const char *linkage_name
;
9965 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9966 if (linkage_name
== NULL
)
9967 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9969 return linkage_name
;
9972 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9973 compute the physname for the object, which include a method's:
9974 - formal parameters (C++),
9975 - receiver type (Go),
9977 The term "physname" is a bit confusing.
9978 For C++, for example, it is the demangled name.
9979 For Go, for example, it's the mangled name.
9981 For Ada, return the DIE's linkage name rather than the fully qualified
9982 name. PHYSNAME is ignored..
9984 The result is allocated on the objfile_obstack and canonicalized. */
9987 dwarf2_compute_name (const char *name
,
9988 struct die_info
*die
, struct dwarf2_cu
*cu
,
9991 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9994 name
= dwarf2_name (die
, cu
);
9996 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9997 but otherwise compute it by typename_concat inside GDB.
9998 FIXME: Actually this is not really true, or at least not always true.
9999 It's all very confusing. compute_and_set_names doesn't try to demangle
10000 Fortran names because there is no mangling standard. So new_symbol
10001 will set the demangled name to the result of dwarf2_full_name, and it is
10002 the demangled name that GDB uses if it exists. */
10003 if (cu
->language
== language_ada
10004 || (cu
->language
== language_fortran
&& physname
))
10006 /* For Ada unit, we prefer the linkage name over the name, as
10007 the former contains the exported name, which the user expects
10008 to be able to reference. Ideally, we want the user to be able
10009 to reference this entity using either natural or linkage name,
10010 but we haven't started looking at this enhancement yet. */
10011 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10013 if (linkage_name
!= NULL
)
10014 return linkage_name
;
10017 /* These are the only languages we know how to qualify names in. */
10019 && (cu
->language
== language_cplus
10020 || cu
->language
== language_fortran
|| cu
->language
== language_d
10021 || cu
->language
== language_rust
))
10023 if (die_needs_namespace (die
, cu
))
10025 const char *prefix
;
10026 const char *canonical_name
= NULL
;
10030 prefix
= determine_prefix (die
, cu
);
10031 if (*prefix
!= '\0')
10033 gdb::unique_xmalloc_ptr
<char> prefixed_name
10034 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10036 buf
.puts (prefixed_name
.get ());
10041 /* Template parameters may be specified in the DIE's DW_AT_name, or
10042 as children with DW_TAG_template_type_param or
10043 DW_TAG_value_type_param. If the latter, add them to the name
10044 here. If the name already has template parameters, then
10045 skip this step; some versions of GCC emit both, and
10046 it is more efficient to use the pre-computed name.
10048 Something to keep in mind about this process: it is very
10049 unlikely, or in some cases downright impossible, to produce
10050 something that will match the mangled name of a function.
10051 If the definition of the function has the same debug info,
10052 we should be able to match up with it anyway. But fallbacks
10053 using the minimal symbol, for instance to find a method
10054 implemented in a stripped copy of libstdc++, will not work.
10055 If we do not have debug info for the definition, we will have to
10056 match them up some other way.
10058 When we do name matching there is a related problem with function
10059 templates; two instantiated function templates are allowed to
10060 differ only by their return types, which we do not add here. */
10062 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10064 struct attribute
*attr
;
10065 struct die_info
*child
;
10068 die
->building_fullname
= 1;
10070 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10074 const gdb_byte
*bytes
;
10075 struct dwarf2_locexpr_baton
*baton
;
10078 if (child
->tag
!= DW_TAG_template_type_param
10079 && child
->tag
!= DW_TAG_template_value_param
)
10090 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10093 complaint (_("template parameter missing DW_AT_type"));
10094 buf
.puts ("UNKNOWN_TYPE");
10097 type
= die_type (child
, cu
);
10099 if (child
->tag
== DW_TAG_template_type_param
)
10101 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10102 &type_print_raw_options
);
10106 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10109 complaint (_("template parameter missing "
10110 "DW_AT_const_value"));
10111 buf
.puts ("UNKNOWN_VALUE");
10115 dwarf2_const_value_attr (attr
, type
, name
,
10116 &cu
->comp_unit_obstack
, cu
,
10117 &value
, &bytes
, &baton
);
10119 if (TYPE_NOSIGN (type
))
10120 /* GDB prints characters as NUMBER 'CHAR'. If that's
10121 changed, this can use value_print instead. */
10122 c_printchar (value
, type
, &buf
);
10125 struct value_print_options opts
;
10128 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10132 else if (bytes
!= NULL
)
10134 v
= allocate_value (type
);
10135 memcpy (value_contents_writeable (v
), bytes
,
10136 TYPE_LENGTH (type
));
10139 v
= value_from_longest (type
, value
);
10141 /* Specify decimal so that we do not depend on
10143 get_formatted_print_options (&opts
, 'd');
10145 value_print (v
, &buf
, &opts
);
10150 die
->building_fullname
= 0;
10154 /* Close the argument list, with a space if necessary
10155 (nested templates). */
10156 if (!buf
.empty () && buf
.string ().back () == '>')
10163 /* For C++ methods, append formal parameter type
10164 information, if PHYSNAME. */
10166 if (physname
&& die
->tag
== DW_TAG_subprogram
10167 && cu
->language
== language_cplus
)
10169 struct type
*type
= read_type_die (die
, cu
);
10171 c_type_print_args (type
, &buf
, 1, cu
->language
,
10172 &type_print_raw_options
);
10174 if (cu
->language
== language_cplus
)
10176 /* Assume that an artificial first parameter is
10177 "this", but do not crash if it is not. RealView
10178 marks unnamed (and thus unused) parameters as
10179 artificial; there is no way to differentiate
10181 if (TYPE_NFIELDS (type
) > 0
10182 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10183 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10184 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10186 buf
.puts (" const");
10190 const std::string
&intermediate_name
= buf
.string ();
10192 if (cu
->language
== language_cplus
)
10194 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10195 &objfile
->per_bfd
->storage_obstack
);
10197 /* If we only computed INTERMEDIATE_NAME, or if
10198 INTERMEDIATE_NAME is already canonical, then we need to
10199 copy it to the appropriate obstack. */
10200 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10201 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
10202 intermediate_name
);
10204 name
= canonical_name
;
10211 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10212 If scope qualifiers are appropriate they will be added. The result
10213 will be allocated on the storage_obstack, or NULL if the DIE does
10214 not have a name. NAME may either be from a previous call to
10215 dwarf2_name or NULL.
10217 The output string will be canonicalized (if C++). */
10219 static const char *
10220 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10222 return dwarf2_compute_name (name
, die
, cu
, 0);
10225 /* Construct a physname for the given DIE in CU. NAME may either be
10226 from a previous call to dwarf2_name or NULL. The result will be
10227 allocated on the objfile_objstack or NULL if the DIE does not have a
10230 The output string will be canonicalized (if C++). */
10232 static const char *
10233 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10235 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10236 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10239 /* In this case dwarf2_compute_name is just a shortcut not building anything
10241 if (!die_needs_namespace (die
, cu
))
10242 return dwarf2_compute_name (name
, die
, cu
, 1);
10244 mangled
= dw2_linkage_name (die
, cu
);
10246 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10247 See https://github.com/rust-lang/rust/issues/32925. */
10248 if (cu
->language
== language_rust
&& mangled
!= NULL
10249 && strchr (mangled
, '{') != NULL
)
10252 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10254 gdb::unique_xmalloc_ptr
<char> demangled
;
10255 if (mangled
!= NULL
)
10258 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10260 /* Do nothing (do not demangle the symbol name). */
10262 else if (cu
->language
== language_go
)
10264 /* This is a lie, but we already lie to the caller new_symbol.
10265 new_symbol assumes we return the mangled name.
10266 This just undoes that lie until things are cleaned up. */
10270 /* Use DMGL_RET_DROP for C++ template functions to suppress
10271 their return type. It is easier for GDB users to search
10272 for such functions as `name(params)' than `long name(params)'.
10273 In such case the minimal symbol names do not match the full
10274 symbol names but for template functions there is never a need
10275 to look up their definition from their declaration so
10276 the only disadvantage remains the minimal symbol variant
10277 `long name(params)' does not have the proper inferior type. */
10278 demangled
.reset (gdb_demangle (mangled
,
10279 (DMGL_PARAMS
| DMGL_ANSI
10280 | DMGL_RET_DROP
)));
10283 canon
= demangled
.get ();
10291 if (canon
== NULL
|| check_physname
)
10293 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10295 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10297 /* It may not mean a bug in GDB. The compiler could also
10298 compute DW_AT_linkage_name incorrectly. But in such case
10299 GDB would need to be bug-to-bug compatible. */
10301 complaint (_("Computed physname <%s> does not match demangled <%s> "
10302 "(from linkage <%s>) - DIE at %s [in module %s]"),
10303 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10304 objfile_name (objfile
));
10306 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10307 is available here - over computed PHYSNAME. It is safer
10308 against both buggy GDB and buggy compilers. */
10322 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
10327 /* Inspect DIE in CU for a namespace alias. If one exists, record
10328 a new symbol for it.
10330 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10333 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10335 struct attribute
*attr
;
10337 /* If the die does not have a name, this is not a namespace
10339 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10343 struct die_info
*d
= die
;
10344 struct dwarf2_cu
*imported_cu
= cu
;
10346 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10347 keep inspecting DIEs until we hit the underlying import. */
10348 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10349 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10351 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10355 d
= follow_die_ref (d
, attr
, &imported_cu
);
10356 if (d
->tag
!= DW_TAG_imported_declaration
)
10360 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10362 complaint (_("DIE at %s has too many recursively imported "
10363 "declarations"), sect_offset_str (d
->sect_off
));
10370 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10372 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10373 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10375 /* This declaration is a global namespace alias. Add
10376 a symbol for it whose type is the aliased namespace. */
10377 new_symbol (die
, type
, cu
);
10386 /* Return the using directives repository (global or local?) to use in the
10387 current context for CU.
10389 For Ada, imported declarations can materialize renamings, which *may* be
10390 global. However it is impossible (for now?) in DWARF to distinguish
10391 "external" imported declarations and "static" ones. As all imported
10392 declarations seem to be static in all other languages, make them all CU-wide
10393 global only in Ada. */
10395 static struct using_direct
**
10396 using_directives (struct dwarf2_cu
*cu
)
10398 if (cu
->language
== language_ada
10399 && cu
->get_builder ()->outermost_context_p ())
10400 return cu
->get_builder ()->get_global_using_directives ();
10402 return cu
->get_builder ()->get_local_using_directives ();
10405 /* Read the import statement specified by the given die and record it. */
10408 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10410 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10411 struct attribute
*import_attr
;
10412 struct die_info
*imported_die
, *child_die
;
10413 struct dwarf2_cu
*imported_cu
;
10414 const char *imported_name
;
10415 const char *imported_name_prefix
;
10416 const char *canonical_name
;
10417 const char *import_alias
;
10418 const char *imported_declaration
= NULL
;
10419 const char *import_prefix
;
10420 std::vector
<const char *> excludes
;
10422 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10423 if (import_attr
== NULL
)
10425 complaint (_("Tag '%s' has no DW_AT_import"),
10426 dwarf_tag_name (die
->tag
));
10431 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10432 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10433 if (imported_name
== NULL
)
10435 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10437 The import in the following code:
10451 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10452 <52> DW_AT_decl_file : 1
10453 <53> DW_AT_decl_line : 6
10454 <54> DW_AT_import : <0x75>
10455 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10456 <59> DW_AT_name : B
10457 <5b> DW_AT_decl_file : 1
10458 <5c> DW_AT_decl_line : 2
10459 <5d> DW_AT_type : <0x6e>
10461 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10462 <76> DW_AT_byte_size : 4
10463 <77> DW_AT_encoding : 5 (signed)
10465 imports the wrong die ( 0x75 instead of 0x58 ).
10466 This case will be ignored until the gcc bug is fixed. */
10470 /* Figure out the local name after import. */
10471 import_alias
= dwarf2_name (die
, cu
);
10473 /* Figure out where the statement is being imported to. */
10474 import_prefix
= determine_prefix (die
, cu
);
10476 /* Figure out what the scope of the imported die is and prepend it
10477 to the name of the imported die. */
10478 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10480 if (imported_die
->tag
!= DW_TAG_namespace
10481 && imported_die
->tag
!= DW_TAG_module
)
10483 imported_declaration
= imported_name
;
10484 canonical_name
= imported_name_prefix
;
10486 else if (strlen (imported_name_prefix
) > 0)
10487 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10488 imported_name_prefix
,
10489 (cu
->language
== language_d
? "." : "::"),
10490 imported_name
, (char *) NULL
);
10492 canonical_name
= imported_name
;
10494 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10495 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10496 child_die
= sibling_die (child_die
))
10498 /* DWARF-4: A Fortran use statement with a “rename list” may be
10499 represented by an imported module entry with an import attribute
10500 referring to the module and owned entries corresponding to those
10501 entities that are renamed as part of being imported. */
10503 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10505 complaint (_("child DW_TAG_imported_declaration expected "
10506 "- DIE at %s [in module %s]"),
10507 sect_offset_str (child_die
->sect_off
),
10508 objfile_name (objfile
));
10512 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10513 if (import_attr
== NULL
)
10515 complaint (_("Tag '%s' has no DW_AT_import"),
10516 dwarf_tag_name (child_die
->tag
));
10521 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10523 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10524 if (imported_name
== NULL
)
10526 complaint (_("child DW_TAG_imported_declaration has unknown "
10527 "imported name - DIE at %s [in module %s]"),
10528 sect_offset_str (child_die
->sect_off
),
10529 objfile_name (objfile
));
10533 excludes
.push_back (imported_name
);
10535 process_die (child_die
, cu
);
10538 add_using_directive (using_directives (cu
),
10542 imported_declaration
,
10545 &objfile
->objfile_obstack
);
10548 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10549 types, but gives them a size of zero. Starting with version 14,
10550 ICC is compatible with GCC. */
10553 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10555 if (!cu
->checked_producer
)
10556 check_producer (cu
);
10558 return cu
->producer_is_icc_lt_14
;
10561 /* ICC generates a DW_AT_type for C void functions. This was observed on
10562 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10563 which says that void functions should not have a DW_AT_type. */
10566 producer_is_icc (struct dwarf2_cu
*cu
)
10568 if (!cu
->checked_producer
)
10569 check_producer (cu
);
10571 return cu
->producer_is_icc
;
10574 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10575 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10576 this, it was first present in GCC release 4.3.0. */
10579 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10581 if (!cu
->checked_producer
)
10582 check_producer (cu
);
10584 return cu
->producer_is_gcc_lt_4_3
;
10587 static file_and_directory
10588 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10590 file_and_directory res
;
10592 /* Find the filename. Do not use dwarf2_name here, since the filename
10593 is not a source language identifier. */
10594 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10595 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10597 if (res
.comp_dir
== NULL
10598 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10599 && IS_ABSOLUTE_PATH (res
.name
))
10601 res
.comp_dir_storage
= ldirname (res
.name
);
10602 if (!res
.comp_dir_storage
.empty ())
10603 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10605 if (res
.comp_dir
!= NULL
)
10607 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10608 directory, get rid of it. */
10609 const char *cp
= strchr (res
.comp_dir
, ':');
10611 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10612 res
.comp_dir
= cp
+ 1;
10615 if (res
.name
== NULL
)
10616 res
.name
= "<unknown>";
10621 /* Handle DW_AT_stmt_list for a compilation unit.
10622 DIE is the DW_TAG_compile_unit die for CU.
10623 COMP_DIR is the compilation directory. LOWPC is passed to
10624 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10627 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10628 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10630 struct dwarf2_per_objfile
*dwarf2_per_objfile
10631 = cu
->per_cu
->dwarf2_per_objfile
;
10632 struct attribute
*attr
;
10633 struct line_header line_header_local
;
10634 hashval_t line_header_local_hash
;
10636 int decode_mapping
;
10638 gdb_assert (! cu
->per_cu
->is_debug_types
);
10640 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10644 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10646 /* The line header hash table is only created if needed (it exists to
10647 prevent redundant reading of the line table for partial_units).
10648 If we're given a partial_unit, we'll need it. If we're given a
10649 compile_unit, then use the line header hash table if it's already
10650 created, but don't create one just yet. */
10652 if (dwarf2_per_objfile
->line_header_hash
== NULL
10653 && die
->tag
== DW_TAG_partial_unit
)
10655 dwarf2_per_objfile
->line_header_hash
10656 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10657 line_header_eq_voidp
,
10658 free_line_header_voidp
,
10662 line_header_local
.sect_off
= line_offset
;
10663 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10664 line_header_local_hash
= line_header_hash (&line_header_local
);
10665 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10667 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10668 &line_header_local
,
10669 line_header_local_hash
, NO_INSERT
);
10671 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10672 is not present in *SLOT (since if there is something in *SLOT then
10673 it will be for a partial_unit). */
10674 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10676 gdb_assert (*slot
!= NULL
);
10677 cu
->line_header
= (struct line_header
*) *slot
;
10682 /* dwarf_decode_line_header does not yet provide sufficient information.
10683 We always have to call also dwarf_decode_lines for it. */
10684 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10688 cu
->line_header
= lh
.release ();
10689 cu
->line_header_die_owner
= die
;
10691 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10695 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10696 &line_header_local
,
10697 line_header_local_hash
, INSERT
);
10698 gdb_assert (slot
!= NULL
);
10700 if (slot
!= NULL
&& *slot
== NULL
)
10702 /* This newly decoded line number information unit will be owned
10703 by line_header_hash hash table. */
10704 *slot
= cu
->line_header
;
10705 cu
->line_header_die_owner
= NULL
;
10709 /* We cannot free any current entry in (*slot) as that struct line_header
10710 may be already used by multiple CUs. Create only temporary decoded
10711 line_header for this CU - it may happen at most once for each line
10712 number information unit. And if we're not using line_header_hash
10713 then this is what we want as well. */
10714 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10716 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10717 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10722 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10725 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10727 struct dwarf2_per_objfile
*dwarf2_per_objfile
10728 = cu
->per_cu
->dwarf2_per_objfile
;
10729 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10730 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10731 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10732 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10733 struct attribute
*attr
;
10734 struct die_info
*child_die
;
10735 CORE_ADDR baseaddr
;
10737 prepare_one_comp_unit (cu
, die
, cu
->language
);
10738 baseaddr
= objfile
->text_section_offset ();
10740 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10742 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10743 from finish_block. */
10744 if (lowpc
== ((CORE_ADDR
) -1))
10746 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10748 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10750 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10751 standardised yet. As a workaround for the language detection we fall
10752 back to the DW_AT_producer string. */
10753 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10754 cu
->language
= language_opencl
;
10756 /* Similar hack for Go. */
10757 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10758 set_cu_language (DW_LANG_Go
, cu
);
10760 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10762 /* Decode line number information if present. We do this before
10763 processing child DIEs, so that the line header table is available
10764 for DW_AT_decl_file. */
10765 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10767 /* Process all dies in compilation unit. */
10768 if (die
->child
!= NULL
)
10770 child_die
= die
->child
;
10771 while (child_die
&& child_die
->tag
)
10773 process_die (child_die
, cu
);
10774 child_die
= sibling_die (child_die
);
10778 /* Decode macro information, if present. Dwarf 2 macro information
10779 refers to information in the line number info statement program
10780 header, so we can only read it if we've read the header
10782 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10784 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10785 if (attr
&& cu
->line_header
)
10787 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10788 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10790 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10794 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10795 if (attr
&& cu
->line_header
)
10797 unsigned int macro_offset
= DW_UNSND (attr
);
10799 dwarf_decode_macros (cu
, macro_offset
, 0);
10805 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10807 struct type_unit_group
*tu_group
;
10809 struct attribute
*attr
;
10811 struct signatured_type
*sig_type
;
10813 gdb_assert (per_cu
->is_debug_types
);
10814 sig_type
= (struct signatured_type
*) per_cu
;
10816 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10818 /* If we're using .gdb_index (includes -readnow) then
10819 per_cu->type_unit_group may not have been set up yet. */
10820 if (sig_type
->type_unit_group
== NULL
)
10821 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10822 tu_group
= sig_type
->type_unit_group
;
10824 /* If we've already processed this stmt_list there's no real need to
10825 do it again, we could fake it and just recreate the part we need
10826 (file name,index -> symtab mapping). If data shows this optimization
10827 is useful we can do it then. */
10828 first_time
= tu_group
->compunit_symtab
== NULL
;
10830 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10835 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10836 lh
= dwarf_decode_line_header (line_offset
, this);
10841 start_symtab ("", NULL
, 0);
10844 gdb_assert (tu_group
->symtabs
== NULL
);
10845 gdb_assert (m_builder
== nullptr);
10846 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10847 m_builder
.reset (new struct buildsym_compunit
10848 (COMPUNIT_OBJFILE (cust
), "",
10849 COMPUNIT_DIRNAME (cust
),
10850 compunit_language (cust
),
10856 line_header
= lh
.release ();
10857 line_header_die_owner
= die
;
10861 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10863 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10864 still initializing it, and our caller (a few levels up)
10865 process_full_type_unit still needs to know if this is the first
10868 tu_group
->num_symtabs
= line_header
->file_names_size ();
10869 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
10870 line_header
->file_names_size ());
10872 auto &file_names
= line_header
->file_names ();
10873 for (i
= 0; i
< file_names
.size (); ++i
)
10875 file_entry
&fe
= file_names
[i
];
10876 dwarf2_start_subfile (this, fe
.name
,
10877 fe
.include_dir (line_header
));
10878 buildsym_compunit
*b
= get_builder ();
10879 if (b
->get_current_subfile ()->symtab
== NULL
)
10881 /* NOTE: start_subfile will recognize when it's been
10882 passed a file it has already seen. So we can't
10883 assume there's a simple mapping from
10884 cu->line_header->file_names to subfiles, plus
10885 cu->line_header->file_names may contain dups. */
10886 b
->get_current_subfile ()->symtab
10887 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10890 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10891 tu_group
->symtabs
[i
] = fe
.symtab
;
10896 gdb_assert (m_builder
== nullptr);
10897 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10898 m_builder
.reset (new struct buildsym_compunit
10899 (COMPUNIT_OBJFILE (cust
), "",
10900 COMPUNIT_DIRNAME (cust
),
10901 compunit_language (cust
),
10904 auto &file_names
= line_header
->file_names ();
10905 for (i
= 0; i
< file_names
.size (); ++i
)
10907 file_entry
&fe
= file_names
[i
];
10908 fe
.symtab
= tu_group
->symtabs
[i
];
10912 /* The main symtab is allocated last. Type units don't have DW_AT_name
10913 so they don't have a "real" (so to speak) symtab anyway.
10914 There is later code that will assign the main symtab to all symbols
10915 that don't have one. We need to handle the case of a symbol with a
10916 missing symtab (DW_AT_decl_file) anyway. */
10919 /* Process DW_TAG_type_unit.
10920 For TUs we want to skip the first top level sibling if it's not the
10921 actual type being defined by this TU. In this case the first top
10922 level sibling is there to provide context only. */
10925 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10927 struct die_info
*child_die
;
10929 prepare_one_comp_unit (cu
, die
, language_minimal
);
10931 /* Initialize (or reinitialize) the machinery for building symtabs.
10932 We do this before processing child DIEs, so that the line header table
10933 is available for DW_AT_decl_file. */
10934 cu
->setup_type_unit_groups (die
);
10936 if (die
->child
!= NULL
)
10938 child_die
= die
->child
;
10939 while (child_die
&& child_die
->tag
)
10941 process_die (child_die
, cu
);
10942 child_die
= sibling_die (child_die
);
10949 http://gcc.gnu.org/wiki/DebugFission
10950 http://gcc.gnu.org/wiki/DebugFissionDWP
10952 To simplify handling of both DWO files ("object" files with the DWARF info)
10953 and DWP files (a file with the DWOs packaged up into one file), we treat
10954 DWP files as having a collection of virtual DWO files. */
10957 hash_dwo_file (const void *item
)
10959 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10962 hash
= htab_hash_string (dwo_file
->dwo_name
);
10963 if (dwo_file
->comp_dir
!= NULL
)
10964 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10969 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10971 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10972 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10974 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10976 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10977 return lhs
->comp_dir
== rhs
->comp_dir
;
10978 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10981 /* Allocate a hash table for DWO files. */
10984 allocate_dwo_file_hash_table (struct objfile
*objfile
)
10986 auto delete_dwo_file
= [] (void *item
)
10988 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
10993 return htab_up (htab_create_alloc (41,
11000 /* Lookup DWO file DWO_NAME. */
11003 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11004 const char *dwo_name
,
11005 const char *comp_dir
)
11007 struct dwo_file find_entry
;
11010 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11011 dwarf2_per_objfile
->dwo_files
11012 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11014 find_entry
.dwo_name
= dwo_name
;
11015 find_entry
.comp_dir
= comp_dir
;
11016 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11023 hash_dwo_unit (const void *item
)
11025 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11027 /* This drops the top 32 bits of the id, but is ok for a hash. */
11028 return dwo_unit
->signature
;
11032 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11034 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11035 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11037 /* The signature is assumed to be unique within the DWO file.
11038 So while object file CU dwo_id's always have the value zero,
11039 that's OK, assuming each object file DWO file has only one CU,
11040 and that's the rule for now. */
11041 return lhs
->signature
== rhs
->signature
;
11044 /* Allocate a hash table for DWO CUs,TUs.
11045 There is one of these tables for each of CUs,TUs for each DWO file. */
11048 allocate_dwo_unit_table (struct objfile
*objfile
)
11050 /* Start out with a pretty small number.
11051 Generally DWO files contain only one CU and maybe some TUs. */
11052 return htab_up (htab_create_alloc (3,
11055 NULL
, xcalloc
, xfree
));
11058 /* die_reader_func for create_dwo_cu. */
11061 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11062 const gdb_byte
*info_ptr
,
11063 struct die_info
*comp_unit_die
,
11064 struct dwo_file
*dwo_file
,
11065 struct dwo_unit
*dwo_unit
)
11067 struct dwarf2_cu
*cu
= reader
->cu
;
11068 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11069 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11071 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11072 if (!signature
.has_value ())
11074 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11075 " its dwo_id [in module %s]"),
11076 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11080 dwo_unit
->dwo_file
= dwo_file
;
11081 dwo_unit
->signature
= *signature
;
11082 dwo_unit
->section
= section
;
11083 dwo_unit
->sect_off
= sect_off
;
11084 dwo_unit
->length
= cu
->per_cu
->length
;
11086 if (dwarf_read_debug
)
11087 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11088 sect_offset_str (sect_off
),
11089 hex_string (dwo_unit
->signature
));
11092 /* Create the dwo_units for the CUs in a DWO_FILE.
11093 Note: This function processes DWO files only, not DWP files. */
11096 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11097 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11098 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11100 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11101 const gdb_byte
*info_ptr
, *end_ptr
;
11103 section
.read (objfile
);
11104 info_ptr
= section
.buffer
;
11106 if (info_ptr
== NULL
)
11109 if (dwarf_read_debug
)
11111 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11112 section
.get_name (),
11113 section
.get_file_name ());
11116 end_ptr
= info_ptr
+ section
.size
;
11117 while (info_ptr
< end_ptr
)
11119 struct dwarf2_per_cu_data per_cu
;
11120 struct dwo_unit read_unit
{};
11121 struct dwo_unit
*dwo_unit
;
11123 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11125 memset (&per_cu
, 0, sizeof (per_cu
));
11126 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11127 per_cu
.is_debug_types
= 0;
11128 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11129 per_cu
.section
= §ion
;
11131 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11132 if (!reader
.dummy_p
)
11133 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11134 &dwo_file
, &read_unit
);
11135 info_ptr
+= per_cu
.length
;
11137 // If the unit could not be parsed, skip it.
11138 if (read_unit
.dwo_file
== NULL
)
11141 if (cus_htab
== NULL
)
11142 cus_htab
= allocate_dwo_unit_table (objfile
);
11144 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11145 *dwo_unit
= read_unit
;
11146 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11147 gdb_assert (slot
!= NULL
);
11150 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11151 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11153 complaint (_("debug cu entry at offset %s is duplicate to"
11154 " the entry at offset %s, signature %s"),
11155 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11156 hex_string (dwo_unit
->signature
));
11158 *slot
= (void *)dwo_unit
;
11162 /* DWP file .debug_{cu,tu}_index section format:
11163 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11167 Both index sections have the same format, and serve to map a 64-bit
11168 signature to a set of section numbers. Each section begins with a header,
11169 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11170 indexes, and a pool of 32-bit section numbers. The index sections will be
11171 aligned at 8-byte boundaries in the file.
11173 The index section header consists of:
11175 V, 32 bit version number
11177 N, 32 bit number of compilation units or type units in the index
11178 M, 32 bit number of slots in the hash table
11180 Numbers are recorded using the byte order of the application binary.
11182 The hash table begins at offset 16 in the section, and consists of an array
11183 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11184 order of the application binary). Unused slots in the hash table are 0.
11185 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11187 The parallel table begins immediately after the hash table
11188 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11189 array of 32-bit indexes (using the byte order of the application binary),
11190 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11191 table contains a 32-bit index into the pool of section numbers. For unused
11192 hash table slots, the corresponding entry in the parallel table will be 0.
11194 The pool of section numbers begins immediately following the hash table
11195 (at offset 16 + 12 * M from the beginning of the section). The pool of
11196 section numbers consists of an array of 32-bit words (using the byte order
11197 of the application binary). Each item in the array is indexed starting
11198 from 0. The hash table entry provides the index of the first section
11199 number in the set. Additional section numbers in the set follow, and the
11200 set is terminated by a 0 entry (section number 0 is not used in ELF).
11202 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11203 section must be the first entry in the set, and the .debug_abbrev.dwo must
11204 be the second entry. Other members of the set may follow in any order.
11210 DWP Version 2 combines all the .debug_info, etc. sections into one,
11211 and the entries in the index tables are now offsets into these sections.
11212 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11215 Index Section Contents:
11217 Hash Table of Signatures dwp_hash_table.hash_table
11218 Parallel Table of Indices dwp_hash_table.unit_table
11219 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11220 Table of Section Sizes dwp_hash_table.v2.sizes
11222 The index section header consists of:
11224 V, 32 bit version number
11225 L, 32 bit number of columns in the table of section offsets
11226 N, 32 bit number of compilation units or type units in the index
11227 M, 32 bit number of slots in the hash table
11229 Numbers are recorded using the byte order of the application binary.
11231 The hash table has the same format as version 1.
11232 The parallel table of indices has the same format as version 1,
11233 except that the entries are origin-1 indices into the table of sections
11234 offsets and the table of section sizes.
11236 The table of offsets begins immediately following the parallel table
11237 (at offset 16 + 12 * M from the beginning of the section). The table is
11238 a two-dimensional array of 32-bit words (using the byte order of the
11239 application binary), with L columns and N+1 rows, in row-major order.
11240 Each row in the array is indexed starting from 0. The first row provides
11241 a key to the remaining rows: each column in this row provides an identifier
11242 for a debug section, and the offsets in the same column of subsequent rows
11243 refer to that section. The section identifiers are:
11245 DW_SECT_INFO 1 .debug_info.dwo
11246 DW_SECT_TYPES 2 .debug_types.dwo
11247 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11248 DW_SECT_LINE 4 .debug_line.dwo
11249 DW_SECT_LOC 5 .debug_loc.dwo
11250 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11251 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11252 DW_SECT_MACRO 8 .debug_macro.dwo
11254 The offsets provided by the CU and TU index sections are the base offsets
11255 for the contributions made by each CU or TU to the corresponding section
11256 in the package file. Each CU and TU header contains an abbrev_offset
11257 field, used to find the abbreviations table for that CU or TU within the
11258 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11259 be interpreted as relative to the base offset given in the index section.
11260 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11261 should be interpreted as relative to the base offset for .debug_line.dwo,
11262 and offsets into other debug sections obtained from DWARF attributes should
11263 also be interpreted as relative to the corresponding base offset.
11265 The table of sizes begins immediately following the table of offsets.
11266 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11267 with L columns and N rows, in row-major order. Each row in the array is
11268 indexed starting from 1 (row 0 is shared by the two tables).
11272 Hash table lookup is handled the same in version 1 and 2:
11274 We assume that N and M will not exceed 2^32 - 1.
11275 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11277 Given a 64-bit compilation unit signature or a type signature S, an entry
11278 in the hash table is located as follows:
11280 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11281 the low-order k bits all set to 1.
11283 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11285 3) If the hash table entry at index H matches the signature, use that
11286 entry. If the hash table entry at index H is unused (all zeroes),
11287 terminate the search: the signature is not present in the table.
11289 4) Let H = (H + H') modulo M. Repeat at Step 3.
11291 Because M > N and H' and M are relatively prime, the search is guaranteed
11292 to stop at an unused slot or find the match. */
11294 /* Create a hash table to map DWO IDs to their CU/TU entry in
11295 .debug_{info,types}.dwo in DWP_FILE.
11296 Returns NULL if there isn't one.
11297 Note: This function processes DWP files only, not DWO files. */
11299 static struct dwp_hash_table
*
11300 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11301 struct dwp_file
*dwp_file
, int is_debug_types
)
11303 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11304 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11305 const gdb_byte
*index_ptr
, *index_end
;
11306 struct dwarf2_section_info
*index
;
11307 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11308 struct dwp_hash_table
*htab
;
11310 if (is_debug_types
)
11311 index
= &dwp_file
->sections
.tu_index
;
11313 index
= &dwp_file
->sections
.cu_index
;
11315 if (index
->empty ())
11317 index
->read (objfile
);
11319 index_ptr
= index
->buffer
;
11320 index_end
= index_ptr
+ index
->size
;
11322 version
= read_4_bytes (dbfd
, index_ptr
);
11325 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11329 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11331 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11334 if (version
!= 1 && version
!= 2)
11336 error (_("Dwarf Error: unsupported DWP file version (%s)"
11337 " [in module %s]"),
11338 pulongest (version
), dwp_file
->name
);
11340 if (nr_slots
!= (nr_slots
& -nr_slots
))
11342 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11343 " is not power of 2 [in module %s]"),
11344 pulongest (nr_slots
), dwp_file
->name
);
11347 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11348 htab
->version
= version
;
11349 htab
->nr_columns
= nr_columns
;
11350 htab
->nr_units
= nr_units
;
11351 htab
->nr_slots
= nr_slots
;
11352 htab
->hash_table
= index_ptr
;
11353 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11355 /* Exit early if the table is empty. */
11356 if (nr_slots
== 0 || nr_units
== 0
11357 || (version
== 2 && nr_columns
== 0))
11359 /* All must be zero. */
11360 if (nr_slots
!= 0 || nr_units
!= 0
11361 || (version
== 2 && nr_columns
!= 0))
11363 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11364 " all zero [in modules %s]"),
11372 htab
->section_pool
.v1
.indices
=
11373 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11374 /* It's harder to decide whether the section is too small in v1.
11375 V1 is deprecated anyway so we punt. */
11379 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11380 int *ids
= htab
->section_pool
.v2
.section_ids
;
11381 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11382 /* Reverse map for error checking. */
11383 int ids_seen
[DW_SECT_MAX
+ 1];
11386 if (nr_columns
< 2)
11388 error (_("Dwarf Error: bad DWP hash table, too few columns"
11389 " in section table [in module %s]"),
11392 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11394 error (_("Dwarf Error: bad DWP hash table, too many columns"
11395 " in section table [in module %s]"),
11398 memset (ids
, 255, sizeof_ids
);
11399 memset (ids_seen
, 255, sizeof (ids_seen
));
11400 for (i
= 0; i
< nr_columns
; ++i
)
11402 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11404 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11406 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11407 " in section table [in module %s]"),
11408 id
, dwp_file
->name
);
11410 if (ids_seen
[id
] != -1)
11412 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11413 " id %d in section table [in module %s]"),
11414 id
, dwp_file
->name
);
11419 /* Must have exactly one info or types section. */
11420 if (((ids_seen
[DW_SECT_INFO
] != -1)
11421 + (ids_seen
[DW_SECT_TYPES
] != -1))
11424 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11425 " DWO info/types section [in module %s]"),
11428 /* Must have an abbrev section. */
11429 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11431 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11432 " section [in module %s]"),
11435 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11436 htab
->section_pool
.v2
.sizes
=
11437 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11438 * nr_units
* nr_columns
);
11439 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11440 * nr_units
* nr_columns
))
11443 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11444 " [in module %s]"),
11452 /* Update SECTIONS with the data from SECTP.
11454 This function is like the other "locate" section routines that are
11455 passed to bfd_map_over_sections, but in this context the sections to
11456 read comes from the DWP V1 hash table, not the full ELF section table.
11458 The result is non-zero for success, or zero if an error was found. */
11461 locate_v1_virtual_dwo_sections (asection
*sectp
,
11462 struct virtual_v1_dwo_sections
*sections
)
11464 const struct dwop_section_names
*names
= &dwop_section_names
;
11466 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11468 /* There can be only one. */
11469 if (sections
->abbrev
.s
.section
!= NULL
)
11471 sections
->abbrev
.s
.section
= sectp
;
11472 sections
->abbrev
.size
= bfd_section_size (sectp
);
11474 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11475 || section_is_p (sectp
->name
, &names
->types_dwo
))
11477 /* There can be only one. */
11478 if (sections
->info_or_types
.s
.section
!= NULL
)
11480 sections
->info_or_types
.s
.section
= sectp
;
11481 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11483 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11485 /* There can be only one. */
11486 if (sections
->line
.s
.section
!= NULL
)
11488 sections
->line
.s
.section
= sectp
;
11489 sections
->line
.size
= bfd_section_size (sectp
);
11491 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11493 /* There can be only one. */
11494 if (sections
->loc
.s
.section
!= NULL
)
11496 sections
->loc
.s
.section
= sectp
;
11497 sections
->loc
.size
= bfd_section_size (sectp
);
11499 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11501 /* There can be only one. */
11502 if (sections
->macinfo
.s
.section
!= NULL
)
11504 sections
->macinfo
.s
.section
= sectp
;
11505 sections
->macinfo
.size
= bfd_section_size (sectp
);
11507 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11509 /* There can be only one. */
11510 if (sections
->macro
.s
.section
!= NULL
)
11512 sections
->macro
.s
.section
= sectp
;
11513 sections
->macro
.size
= bfd_section_size (sectp
);
11515 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11517 /* There can be only one. */
11518 if (sections
->str_offsets
.s
.section
!= NULL
)
11520 sections
->str_offsets
.s
.section
= sectp
;
11521 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11525 /* No other kind of section is valid. */
11532 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11533 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11534 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11535 This is for DWP version 1 files. */
11537 static struct dwo_unit
*
11538 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11539 struct dwp_file
*dwp_file
,
11540 uint32_t unit_index
,
11541 const char *comp_dir
,
11542 ULONGEST signature
, int is_debug_types
)
11544 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11545 const struct dwp_hash_table
*dwp_htab
=
11546 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11547 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11548 const char *kind
= is_debug_types
? "TU" : "CU";
11549 struct dwo_file
*dwo_file
;
11550 struct dwo_unit
*dwo_unit
;
11551 struct virtual_v1_dwo_sections sections
;
11552 void **dwo_file_slot
;
11555 gdb_assert (dwp_file
->version
== 1);
11557 if (dwarf_read_debug
)
11559 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11561 pulongest (unit_index
), hex_string (signature
),
11565 /* Fetch the sections of this DWO unit.
11566 Put a limit on the number of sections we look for so that bad data
11567 doesn't cause us to loop forever. */
11569 #define MAX_NR_V1_DWO_SECTIONS \
11570 (1 /* .debug_info or .debug_types */ \
11571 + 1 /* .debug_abbrev */ \
11572 + 1 /* .debug_line */ \
11573 + 1 /* .debug_loc */ \
11574 + 1 /* .debug_str_offsets */ \
11575 + 1 /* .debug_macro or .debug_macinfo */ \
11576 + 1 /* trailing zero */)
11578 memset (§ions
, 0, sizeof (sections
));
11580 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11583 uint32_t section_nr
=
11584 read_4_bytes (dbfd
,
11585 dwp_htab
->section_pool
.v1
.indices
11586 + (unit_index
+ i
) * sizeof (uint32_t));
11588 if (section_nr
== 0)
11590 if (section_nr
>= dwp_file
->num_sections
)
11592 error (_("Dwarf Error: bad DWP hash table, section number too large"
11593 " [in module %s]"),
11597 sectp
= dwp_file
->elf_sections
[section_nr
];
11598 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11600 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11601 " [in module %s]"),
11607 || sections
.info_or_types
.empty ()
11608 || sections
.abbrev
.empty ())
11610 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11611 " [in module %s]"),
11614 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11616 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11617 " [in module %s]"),
11621 /* It's easier for the rest of the code if we fake a struct dwo_file and
11622 have dwo_unit "live" in that. At least for now.
11624 The DWP file can be made up of a random collection of CUs and TUs.
11625 However, for each CU + set of TUs that came from the same original DWO
11626 file, we can combine them back into a virtual DWO file to save space
11627 (fewer struct dwo_file objects to allocate). Remember that for really
11628 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11630 std::string virtual_dwo_name
=
11631 string_printf ("virtual-dwo/%d-%d-%d-%d",
11632 sections
.abbrev
.get_id (),
11633 sections
.line
.get_id (),
11634 sections
.loc
.get_id (),
11635 sections
.str_offsets
.get_id ());
11636 /* Can we use an existing virtual DWO file? */
11637 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11638 virtual_dwo_name
.c_str (),
11640 /* Create one if necessary. */
11641 if (*dwo_file_slot
== NULL
)
11643 if (dwarf_read_debug
)
11645 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11646 virtual_dwo_name
.c_str ());
11648 dwo_file
= new struct dwo_file
;
11649 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
11651 dwo_file
->comp_dir
= comp_dir
;
11652 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11653 dwo_file
->sections
.line
= sections
.line
;
11654 dwo_file
->sections
.loc
= sections
.loc
;
11655 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11656 dwo_file
->sections
.macro
= sections
.macro
;
11657 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11658 /* The "str" section is global to the entire DWP file. */
11659 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11660 /* The info or types section is assigned below to dwo_unit,
11661 there's no need to record it in dwo_file.
11662 Also, we can't simply record type sections in dwo_file because
11663 we record a pointer into the vector in dwo_unit. As we collect more
11664 types we'll grow the vector and eventually have to reallocate space
11665 for it, invalidating all copies of pointers into the previous
11667 *dwo_file_slot
= dwo_file
;
11671 if (dwarf_read_debug
)
11673 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11674 virtual_dwo_name
.c_str ());
11676 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11679 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11680 dwo_unit
->dwo_file
= dwo_file
;
11681 dwo_unit
->signature
= signature
;
11682 dwo_unit
->section
=
11683 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11684 *dwo_unit
->section
= sections
.info_or_types
;
11685 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11690 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11691 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11692 piece within that section used by a TU/CU, return a virtual section
11693 of just that piece. */
11695 static struct dwarf2_section_info
11696 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11697 struct dwarf2_section_info
*section
,
11698 bfd_size_type offset
, bfd_size_type size
)
11700 struct dwarf2_section_info result
;
11703 gdb_assert (section
!= NULL
);
11704 gdb_assert (!section
->is_virtual
);
11706 memset (&result
, 0, sizeof (result
));
11707 result
.s
.containing_section
= section
;
11708 result
.is_virtual
= true;
11713 sectp
= section
->get_bfd_section ();
11715 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11716 bounds of the real section. This is a pretty-rare event, so just
11717 flag an error (easier) instead of a warning and trying to cope. */
11719 || offset
+ size
> bfd_section_size (sectp
))
11721 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11722 " in section %s [in module %s]"),
11723 sectp
? bfd_section_name (sectp
) : "<unknown>",
11724 objfile_name (dwarf2_per_objfile
->objfile
));
11727 result
.virtual_offset
= offset
;
11728 result
.size
= size
;
11732 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11733 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11734 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11735 This is for DWP version 2 files. */
11737 static struct dwo_unit
*
11738 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11739 struct dwp_file
*dwp_file
,
11740 uint32_t unit_index
,
11741 const char *comp_dir
,
11742 ULONGEST signature
, int is_debug_types
)
11744 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11745 const struct dwp_hash_table
*dwp_htab
=
11746 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11747 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11748 const char *kind
= is_debug_types
? "TU" : "CU";
11749 struct dwo_file
*dwo_file
;
11750 struct dwo_unit
*dwo_unit
;
11751 struct virtual_v2_dwo_sections sections
;
11752 void **dwo_file_slot
;
11755 gdb_assert (dwp_file
->version
== 2);
11757 if (dwarf_read_debug
)
11759 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11761 pulongest (unit_index
), hex_string (signature
),
11765 /* Fetch the section offsets of this DWO unit. */
11767 memset (§ions
, 0, sizeof (sections
));
11769 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11771 uint32_t offset
= read_4_bytes (dbfd
,
11772 dwp_htab
->section_pool
.v2
.offsets
11773 + (((unit_index
- 1) * dwp_htab
->nr_columns
11775 * sizeof (uint32_t)));
11776 uint32_t size
= read_4_bytes (dbfd
,
11777 dwp_htab
->section_pool
.v2
.sizes
11778 + (((unit_index
- 1) * dwp_htab
->nr_columns
11780 * sizeof (uint32_t)));
11782 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11785 case DW_SECT_TYPES
:
11786 sections
.info_or_types_offset
= offset
;
11787 sections
.info_or_types_size
= size
;
11789 case DW_SECT_ABBREV
:
11790 sections
.abbrev_offset
= offset
;
11791 sections
.abbrev_size
= size
;
11794 sections
.line_offset
= offset
;
11795 sections
.line_size
= size
;
11798 sections
.loc_offset
= offset
;
11799 sections
.loc_size
= size
;
11801 case DW_SECT_STR_OFFSETS
:
11802 sections
.str_offsets_offset
= offset
;
11803 sections
.str_offsets_size
= size
;
11805 case DW_SECT_MACINFO
:
11806 sections
.macinfo_offset
= offset
;
11807 sections
.macinfo_size
= size
;
11809 case DW_SECT_MACRO
:
11810 sections
.macro_offset
= offset
;
11811 sections
.macro_size
= size
;
11816 /* It's easier for the rest of the code if we fake a struct dwo_file and
11817 have dwo_unit "live" in that. At least for now.
11819 The DWP file can be made up of a random collection of CUs and TUs.
11820 However, for each CU + set of TUs that came from the same original DWO
11821 file, we can combine them back into a virtual DWO file to save space
11822 (fewer struct dwo_file objects to allocate). Remember that for really
11823 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11825 std::string virtual_dwo_name
=
11826 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11827 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11828 (long) (sections
.line_size
? sections
.line_offset
: 0),
11829 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11830 (long) (sections
.str_offsets_size
11831 ? sections
.str_offsets_offset
: 0));
11832 /* Can we use an existing virtual DWO file? */
11833 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11834 virtual_dwo_name
.c_str (),
11836 /* Create one if necessary. */
11837 if (*dwo_file_slot
== NULL
)
11839 if (dwarf_read_debug
)
11841 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11842 virtual_dwo_name
.c_str ());
11844 dwo_file
= new struct dwo_file
;
11845 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
11847 dwo_file
->comp_dir
= comp_dir
;
11848 dwo_file
->sections
.abbrev
=
11849 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11850 sections
.abbrev_offset
, sections
.abbrev_size
);
11851 dwo_file
->sections
.line
=
11852 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11853 sections
.line_offset
, sections
.line_size
);
11854 dwo_file
->sections
.loc
=
11855 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11856 sections
.loc_offset
, sections
.loc_size
);
11857 dwo_file
->sections
.macinfo
=
11858 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11859 sections
.macinfo_offset
, sections
.macinfo_size
);
11860 dwo_file
->sections
.macro
=
11861 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11862 sections
.macro_offset
, sections
.macro_size
);
11863 dwo_file
->sections
.str_offsets
=
11864 create_dwp_v2_section (dwarf2_per_objfile
,
11865 &dwp_file
->sections
.str_offsets
,
11866 sections
.str_offsets_offset
,
11867 sections
.str_offsets_size
);
11868 /* The "str" section is global to the entire DWP file. */
11869 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11870 /* The info or types section is assigned below to dwo_unit,
11871 there's no need to record it in dwo_file.
11872 Also, we can't simply record type sections in dwo_file because
11873 we record a pointer into the vector in dwo_unit. As we collect more
11874 types we'll grow the vector and eventually have to reallocate space
11875 for it, invalidating all copies of pointers into the previous
11877 *dwo_file_slot
= dwo_file
;
11881 if (dwarf_read_debug
)
11883 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11884 virtual_dwo_name
.c_str ());
11886 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11889 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11890 dwo_unit
->dwo_file
= dwo_file
;
11891 dwo_unit
->signature
= signature
;
11892 dwo_unit
->section
=
11893 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11894 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11896 ? &dwp_file
->sections
.types
11897 : &dwp_file
->sections
.info
,
11898 sections
.info_or_types_offset
,
11899 sections
.info_or_types_size
);
11900 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11905 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11906 Returns NULL if the signature isn't found. */
11908 static struct dwo_unit
*
11909 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11910 struct dwp_file
*dwp_file
, const char *comp_dir
,
11911 ULONGEST signature
, int is_debug_types
)
11913 const struct dwp_hash_table
*dwp_htab
=
11914 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11915 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11916 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11917 uint32_t hash
= signature
& mask
;
11918 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11921 struct dwo_unit find_dwo_cu
;
11923 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11924 find_dwo_cu
.signature
= signature
;
11925 slot
= htab_find_slot (is_debug_types
11926 ? dwp_file
->loaded_tus
.get ()
11927 : dwp_file
->loaded_cus
.get (),
11928 &find_dwo_cu
, INSERT
);
11931 return (struct dwo_unit
*) *slot
;
11933 /* Use a for loop so that we don't loop forever on bad debug info. */
11934 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11936 ULONGEST signature_in_table
;
11938 signature_in_table
=
11939 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11940 if (signature_in_table
== signature
)
11942 uint32_t unit_index
=
11943 read_4_bytes (dbfd
,
11944 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11946 if (dwp_file
->version
== 1)
11948 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11949 dwp_file
, unit_index
,
11950 comp_dir
, signature
,
11955 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11956 dwp_file
, unit_index
,
11957 comp_dir
, signature
,
11960 return (struct dwo_unit
*) *slot
;
11962 if (signature_in_table
== 0)
11964 hash
= (hash
+ hash2
) & mask
;
11967 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11968 " [in module %s]"),
11972 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11973 Open the file specified by FILE_NAME and hand it off to BFD for
11974 preliminary analysis. Return a newly initialized bfd *, which
11975 includes a canonicalized copy of FILE_NAME.
11976 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11977 SEARCH_CWD is true if the current directory is to be searched.
11978 It will be searched before debug-file-directory.
11979 If successful, the file is added to the bfd include table of the
11980 objfile's bfd (see gdb_bfd_record_inclusion).
11981 If unable to find/open the file, return NULL.
11982 NOTE: This function is derived from symfile_bfd_open. */
11984 static gdb_bfd_ref_ptr
11985 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11986 const char *file_name
, int is_dwp
, int search_cwd
)
11989 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11990 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11991 to debug_file_directory. */
11992 const char *search_path
;
11993 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11995 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
11998 if (*debug_file_directory
!= '\0')
12000 search_path_holder
.reset (concat (".", dirname_separator_string
,
12001 debug_file_directory
,
12003 search_path
= search_path_holder
.get ();
12009 search_path
= debug_file_directory
;
12011 openp_flags flags
= OPF_RETURN_REALPATH
;
12013 flags
|= OPF_SEARCH_IN_PATH
;
12015 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12016 desc
= openp (search_path
, flags
, file_name
,
12017 O_RDONLY
| O_BINARY
, &absolute_name
);
12021 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12023 if (sym_bfd
== NULL
)
12025 bfd_set_cacheable (sym_bfd
.get (), 1);
12027 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12030 /* Success. Record the bfd as having been included by the objfile's bfd.
12031 This is important because things like demangled_names_hash lives in the
12032 objfile's per_bfd space and may have references to things like symbol
12033 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12034 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12039 /* Try to open DWO file FILE_NAME.
12040 COMP_DIR is the DW_AT_comp_dir attribute.
12041 The result is the bfd handle of the file.
12042 If there is a problem finding or opening the file, return NULL.
12043 Upon success, the canonicalized path of the file is stored in the bfd,
12044 same as symfile_bfd_open. */
12046 static gdb_bfd_ref_ptr
12047 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12048 const char *file_name
, const char *comp_dir
)
12050 if (IS_ABSOLUTE_PATH (file_name
))
12051 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12052 0 /*is_dwp*/, 0 /*search_cwd*/);
12054 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12056 if (comp_dir
!= NULL
)
12058 gdb::unique_xmalloc_ptr
<char> path_to_try
12059 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12061 /* NOTE: If comp_dir is a relative path, this will also try the
12062 search path, which seems useful. */
12063 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12064 path_to_try
.get (),
12066 1 /*search_cwd*/));
12071 /* That didn't work, try debug-file-directory, which, despite its name,
12072 is a list of paths. */
12074 if (*debug_file_directory
== '\0')
12077 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12078 0 /*is_dwp*/, 1 /*search_cwd*/);
12081 /* This function is mapped across the sections and remembers the offset and
12082 size of each of the DWO debugging sections we are interested in. */
12085 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12087 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12088 const struct dwop_section_names
*names
= &dwop_section_names
;
12090 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12092 dwo_sections
->abbrev
.s
.section
= sectp
;
12093 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12095 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12097 dwo_sections
->info
.s
.section
= sectp
;
12098 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12100 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12102 dwo_sections
->line
.s
.section
= sectp
;
12103 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12105 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12107 dwo_sections
->loc
.s
.section
= sectp
;
12108 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12110 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12112 dwo_sections
->macinfo
.s
.section
= sectp
;
12113 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12115 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12117 dwo_sections
->macro
.s
.section
= sectp
;
12118 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12120 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12122 dwo_sections
->str
.s
.section
= sectp
;
12123 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12125 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12127 dwo_sections
->str_offsets
.s
.section
= sectp
;
12128 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12130 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12132 struct dwarf2_section_info type_section
;
12134 memset (&type_section
, 0, sizeof (type_section
));
12135 type_section
.s
.section
= sectp
;
12136 type_section
.size
= bfd_section_size (sectp
);
12137 dwo_sections
->types
.push_back (type_section
);
12141 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12142 by PER_CU. This is for the non-DWP case.
12143 The result is NULL if DWO_NAME can't be found. */
12145 static struct dwo_file
*
12146 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12147 const char *dwo_name
, const char *comp_dir
)
12149 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12151 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12154 if (dwarf_read_debug
)
12155 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12159 dwo_file_up
dwo_file (new struct dwo_file
);
12160 dwo_file
->dwo_name
= dwo_name
;
12161 dwo_file
->comp_dir
= comp_dir
;
12162 dwo_file
->dbfd
= std::move (dbfd
);
12164 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12165 &dwo_file
->sections
);
12167 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12168 dwo_file
->sections
.info
, dwo_file
->cus
);
12170 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12171 dwo_file
->sections
.types
, dwo_file
->tus
);
12173 if (dwarf_read_debug
)
12174 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12176 return dwo_file
.release ();
12179 /* This function is mapped across the sections and remembers the offset and
12180 size of each of the DWP debugging sections common to version 1 and 2 that
12181 we are interested in. */
12184 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12185 void *dwp_file_ptr
)
12187 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12188 const struct dwop_section_names
*names
= &dwop_section_names
;
12189 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12191 /* Record the ELF section number for later lookup: this is what the
12192 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12193 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12194 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12196 /* Look for specific sections that we need. */
12197 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12199 dwp_file
->sections
.str
.s
.section
= sectp
;
12200 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12202 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12204 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12205 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12207 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12209 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12210 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12214 /* This function is mapped across the sections and remembers the offset and
12215 size of each of the DWP version 2 debugging sections that we are interested
12216 in. This is split into a separate function because we don't know if we
12217 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12220 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12222 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12223 const struct dwop_section_names
*names
= &dwop_section_names
;
12224 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12226 /* Record the ELF section number for later lookup: this is what the
12227 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12228 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12229 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12231 /* Look for specific sections that we need. */
12232 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12234 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12235 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12237 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12239 dwp_file
->sections
.info
.s
.section
= sectp
;
12240 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12242 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12244 dwp_file
->sections
.line
.s
.section
= sectp
;
12245 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12247 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12249 dwp_file
->sections
.loc
.s
.section
= sectp
;
12250 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12252 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12254 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12255 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12257 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12259 dwp_file
->sections
.macro
.s
.section
= sectp
;
12260 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12262 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12264 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12265 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12267 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12269 dwp_file
->sections
.types
.s
.section
= sectp
;
12270 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12274 /* Hash function for dwp_file loaded CUs/TUs. */
12277 hash_dwp_loaded_cutus (const void *item
)
12279 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12281 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12282 return dwo_unit
->signature
;
12285 /* Equality function for dwp_file loaded CUs/TUs. */
12288 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12290 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12291 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12293 return dua
->signature
== dub
->signature
;
12296 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12299 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
12301 return htab_up (htab_create_alloc (3,
12302 hash_dwp_loaded_cutus
,
12303 eq_dwp_loaded_cutus
,
12304 NULL
, xcalloc
, xfree
));
12307 /* Try to open DWP file FILE_NAME.
12308 The result is the bfd handle of the file.
12309 If there is a problem finding or opening the file, return NULL.
12310 Upon success, the canonicalized path of the file is stored in the bfd,
12311 same as symfile_bfd_open. */
12313 static gdb_bfd_ref_ptr
12314 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12315 const char *file_name
)
12317 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12319 1 /*search_cwd*/));
12323 /* Work around upstream bug 15652.
12324 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12325 [Whether that's a "bug" is debatable, but it is getting in our way.]
12326 We have no real idea where the dwp file is, because gdb's realpath-ing
12327 of the executable's path may have discarded the needed info.
12328 [IWBN if the dwp file name was recorded in the executable, akin to
12329 .gnu_debuglink, but that doesn't exist yet.]
12330 Strip the directory from FILE_NAME and search again. */
12331 if (*debug_file_directory
!= '\0')
12333 /* Don't implicitly search the current directory here.
12334 If the user wants to search "." to handle this case,
12335 it must be added to debug-file-directory. */
12336 return try_open_dwop_file (dwarf2_per_objfile
,
12337 lbasename (file_name
), 1 /*is_dwp*/,
12344 /* Initialize the use of the DWP file for the current objfile.
12345 By convention the name of the DWP file is ${objfile}.dwp.
12346 The result is NULL if it can't be found. */
12348 static std::unique_ptr
<struct dwp_file
>
12349 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12351 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12353 /* Try to find first .dwp for the binary file before any symbolic links
12356 /* If the objfile is a debug file, find the name of the real binary
12357 file and get the name of dwp file from there. */
12358 std::string dwp_name
;
12359 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12361 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12362 const char *backlink_basename
= lbasename (backlink
->original_name
);
12364 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12367 dwp_name
= objfile
->original_name
;
12369 dwp_name
+= ".dwp";
12371 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12373 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12375 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12376 dwp_name
= objfile_name (objfile
);
12377 dwp_name
+= ".dwp";
12378 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12383 if (dwarf_read_debug
)
12384 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12385 return std::unique_ptr
<dwp_file
> ();
12388 const char *name
= bfd_get_filename (dbfd
.get ());
12389 std::unique_ptr
<struct dwp_file
> dwp_file
12390 (new struct dwp_file (name
, std::move (dbfd
)));
12392 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12393 dwp_file
->elf_sections
=
12394 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12395 dwp_file
->num_sections
, asection
*);
12397 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12398 dwarf2_locate_common_dwp_sections
,
12401 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12404 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12407 /* The DWP file version is stored in the hash table. Oh well. */
12408 if (dwp_file
->cus
&& dwp_file
->tus
12409 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12411 /* Technically speaking, we should try to limp along, but this is
12412 pretty bizarre. We use pulongest here because that's the established
12413 portability solution (e.g, we cannot use %u for uint32_t). */
12414 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12415 " TU version %s [in DWP file %s]"),
12416 pulongest (dwp_file
->cus
->version
),
12417 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12421 dwp_file
->version
= dwp_file
->cus
->version
;
12422 else if (dwp_file
->tus
)
12423 dwp_file
->version
= dwp_file
->tus
->version
;
12425 dwp_file
->version
= 2;
12427 if (dwp_file
->version
== 2)
12428 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12429 dwarf2_locate_v2_dwp_sections
,
12432 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
12433 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
12435 if (dwarf_read_debug
)
12437 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12438 fprintf_unfiltered (gdb_stdlog
,
12439 " %s CUs, %s TUs\n",
12440 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12441 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12447 /* Wrapper around open_and_init_dwp_file, only open it once. */
12449 static struct dwp_file
*
12450 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12452 if (! dwarf2_per_objfile
->dwp_checked
)
12454 dwarf2_per_objfile
->dwp_file
12455 = open_and_init_dwp_file (dwarf2_per_objfile
);
12456 dwarf2_per_objfile
->dwp_checked
= 1;
12458 return dwarf2_per_objfile
->dwp_file
.get ();
12461 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12462 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12463 or in the DWP file for the objfile, referenced by THIS_UNIT.
12464 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12465 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12467 This is called, for example, when wanting to read a variable with a
12468 complex location. Therefore we don't want to do file i/o for every call.
12469 Therefore we don't want to look for a DWO file on every call.
12470 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12471 then we check if we've already seen DWO_NAME, and only THEN do we check
12474 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12475 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12477 static struct dwo_unit
*
12478 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12479 const char *dwo_name
, const char *comp_dir
,
12480 ULONGEST signature
, int is_debug_types
)
12482 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12483 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12484 const char *kind
= is_debug_types
? "TU" : "CU";
12485 void **dwo_file_slot
;
12486 struct dwo_file
*dwo_file
;
12487 struct dwp_file
*dwp_file
;
12489 /* First see if there's a DWP file.
12490 If we have a DWP file but didn't find the DWO inside it, don't
12491 look for the original DWO file. It makes gdb behave differently
12492 depending on whether one is debugging in the build tree. */
12494 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12495 if (dwp_file
!= NULL
)
12497 const struct dwp_hash_table
*dwp_htab
=
12498 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12500 if (dwp_htab
!= NULL
)
12502 struct dwo_unit
*dwo_cutu
=
12503 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12504 signature
, is_debug_types
);
12506 if (dwo_cutu
!= NULL
)
12508 if (dwarf_read_debug
)
12510 fprintf_unfiltered (gdb_stdlog
,
12511 "Virtual DWO %s %s found: @%s\n",
12512 kind
, hex_string (signature
),
12513 host_address_to_string (dwo_cutu
));
12521 /* No DWP file, look for the DWO file. */
12523 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12524 dwo_name
, comp_dir
);
12525 if (*dwo_file_slot
== NULL
)
12527 /* Read in the file and build a table of the CUs/TUs it contains. */
12528 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12530 /* NOTE: This will be NULL if unable to open the file. */
12531 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12533 if (dwo_file
!= NULL
)
12535 struct dwo_unit
*dwo_cutu
= NULL
;
12537 if (is_debug_types
&& dwo_file
->tus
)
12539 struct dwo_unit find_dwo_cutu
;
12541 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12542 find_dwo_cutu
.signature
= signature
;
12544 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12547 else if (!is_debug_types
&& dwo_file
->cus
)
12549 struct dwo_unit find_dwo_cutu
;
12551 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12552 find_dwo_cutu
.signature
= signature
;
12553 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12557 if (dwo_cutu
!= NULL
)
12559 if (dwarf_read_debug
)
12561 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12562 kind
, dwo_name
, hex_string (signature
),
12563 host_address_to_string (dwo_cutu
));
12570 /* We didn't find it. This could mean a dwo_id mismatch, or
12571 someone deleted the DWO/DWP file, or the search path isn't set up
12572 correctly to find the file. */
12574 if (dwarf_read_debug
)
12576 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12577 kind
, dwo_name
, hex_string (signature
));
12580 /* This is a warning and not a complaint because it can be caused by
12581 pilot error (e.g., user accidentally deleting the DWO). */
12583 /* Print the name of the DWP file if we looked there, helps the user
12584 better diagnose the problem. */
12585 std::string dwp_text
;
12587 if (dwp_file
!= NULL
)
12588 dwp_text
= string_printf (" [in DWP file %s]",
12589 lbasename (dwp_file
->name
));
12591 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12592 " [in module %s]"),
12593 kind
, dwo_name
, hex_string (signature
),
12595 this_unit
->is_debug_types
? "TU" : "CU",
12596 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12601 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12602 See lookup_dwo_cutu_unit for details. */
12604 static struct dwo_unit
*
12605 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12606 const char *dwo_name
, const char *comp_dir
,
12607 ULONGEST signature
)
12609 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12612 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12613 See lookup_dwo_cutu_unit for details. */
12615 static struct dwo_unit
*
12616 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12617 const char *dwo_name
, const char *comp_dir
)
12619 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12622 /* Traversal function for queue_and_load_all_dwo_tus. */
12625 queue_and_load_dwo_tu (void **slot
, void *info
)
12627 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12628 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12629 ULONGEST signature
= dwo_unit
->signature
;
12630 struct signatured_type
*sig_type
=
12631 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12633 if (sig_type
!= NULL
)
12635 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12637 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12638 a real dependency of PER_CU on SIG_TYPE. That is detected later
12639 while processing PER_CU. */
12640 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12641 load_full_type_unit (sig_cu
);
12642 per_cu
->imported_symtabs_push (sig_cu
);
12648 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12649 The DWO may have the only definition of the type, though it may not be
12650 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12651 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12654 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12656 struct dwo_unit
*dwo_unit
;
12657 struct dwo_file
*dwo_file
;
12659 gdb_assert (!per_cu
->is_debug_types
);
12660 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12661 gdb_assert (per_cu
->cu
!= NULL
);
12663 dwo_unit
= per_cu
->cu
->dwo_unit
;
12664 gdb_assert (dwo_unit
!= NULL
);
12666 dwo_file
= dwo_unit
->dwo_file
;
12667 if (dwo_file
->tus
!= NULL
)
12668 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12672 /* Read in various DIEs. */
12674 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12675 Inherit only the children of the DW_AT_abstract_origin DIE not being
12676 already referenced by DW_AT_abstract_origin from the children of the
12680 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12682 struct die_info
*child_die
;
12683 sect_offset
*offsetp
;
12684 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12685 struct die_info
*origin_die
;
12686 /* Iterator of the ORIGIN_DIE children. */
12687 struct die_info
*origin_child_die
;
12688 struct attribute
*attr
;
12689 struct dwarf2_cu
*origin_cu
;
12690 struct pending
**origin_previous_list_in_scope
;
12692 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12696 /* Note that following die references may follow to a die in a
12700 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12702 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12704 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12705 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12707 if (die
->tag
!= origin_die
->tag
12708 && !(die
->tag
== DW_TAG_inlined_subroutine
12709 && origin_die
->tag
== DW_TAG_subprogram
))
12710 complaint (_("DIE %s and its abstract origin %s have different tags"),
12711 sect_offset_str (die
->sect_off
),
12712 sect_offset_str (origin_die
->sect_off
));
12714 std::vector
<sect_offset
> offsets
;
12716 for (child_die
= die
->child
;
12717 child_die
&& child_die
->tag
;
12718 child_die
= sibling_die (child_die
))
12720 struct die_info
*child_origin_die
;
12721 struct dwarf2_cu
*child_origin_cu
;
12723 /* We are trying to process concrete instance entries:
12724 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12725 it's not relevant to our analysis here. i.e. detecting DIEs that are
12726 present in the abstract instance but not referenced in the concrete
12728 if (child_die
->tag
== DW_TAG_call_site
12729 || child_die
->tag
== DW_TAG_GNU_call_site
)
12732 /* For each CHILD_DIE, find the corresponding child of
12733 ORIGIN_DIE. If there is more than one layer of
12734 DW_AT_abstract_origin, follow them all; there shouldn't be,
12735 but GCC versions at least through 4.4 generate this (GCC PR
12737 child_origin_die
= child_die
;
12738 child_origin_cu
= cu
;
12741 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12745 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12749 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12750 counterpart may exist. */
12751 if (child_origin_die
!= child_die
)
12753 if (child_die
->tag
!= child_origin_die
->tag
12754 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12755 && child_origin_die
->tag
== DW_TAG_subprogram
))
12756 complaint (_("Child DIE %s and its abstract origin %s have "
12758 sect_offset_str (child_die
->sect_off
),
12759 sect_offset_str (child_origin_die
->sect_off
));
12760 if (child_origin_die
->parent
!= origin_die
)
12761 complaint (_("Child DIE %s and its abstract origin %s have "
12762 "different parents"),
12763 sect_offset_str (child_die
->sect_off
),
12764 sect_offset_str (child_origin_die
->sect_off
));
12766 offsets
.push_back (child_origin_die
->sect_off
);
12769 std::sort (offsets
.begin (), offsets
.end ());
12770 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12771 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12772 if (offsetp
[-1] == *offsetp
)
12773 complaint (_("Multiple children of DIE %s refer "
12774 "to DIE %s as their abstract origin"),
12775 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12777 offsetp
= offsets
.data ();
12778 origin_child_die
= origin_die
->child
;
12779 while (origin_child_die
&& origin_child_die
->tag
)
12781 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12782 while (offsetp
< offsets_end
12783 && *offsetp
< origin_child_die
->sect_off
)
12785 if (offsetp
>= offsets_end
12786 || *offsetp
> origin_child_die
->sect_off
)
12788 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12789 Check whether we're already processing ORIGIN_CHILD_DIE.
12790 This can happen with mutually referenced abstract_origins.
12792 if (!origin_child_die
->in_process
)
12793 process_die (origin_child_die
, origin_cu
);
12795 origin_child_die
= sibling_die (origin_child_die
);
12797 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12799 if (cu
!= origin_cu
)
12800 compute_delayed_physnames (origin_cu
);
12804 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12806 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12807 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12808 struct context_stack
*newobj
;
12811 struct die_info
*child_die
;
12812 struct attribute
*attr
, *call_line
, *call_file
;
12814 CORE_ADDR baseaddr
;
12815 struct block
*block
;
12816 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12817 std::vector
<struct symbol
*> template_args
;
12818 struct template_symbol
*templ_func
= NULL
;
12822 /* If we do not have call site information, we can't show the
12823 caller of this inlined function. That's too confusing, so
12824 only use the scope for local variables. */
12825 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12826 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12827 if (call_line
== NULL
|| call_file
== NULL
)
12829 read_lexical_block_scope (die
, cu
);
12834 baseaddr
= objfile
->text_section_offset ();
12836 name
= dwarf2_name (die
, cu
);
12838 /* Ignore functions with missing or empty names. These are actually
12839 illegal according to the DWARF standard. */
12842 complaint (_("missing name for subprogram DIE at %s"),
12843 sect_offset_str (die
->sect_off
));
12847 /* Ignore functions with missing or invalid low and high pc attributes. */
12848 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12849 <= PC_BOUNDS_INVALID
)
12851 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12852 if (!attr
|| !DW_UNSND (attr
))
12853 complaint (_("cannot get low and high bounds "
12854 "for subprogram DIE at %s"),
12855 sect_offset_str (die
->sect_off
));
12859 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12860 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12862 /* If we have any template arguments, then we must allocate a
12863 different sort of symbol. */
12864 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
12866 if (child_die
->tag
== DW_TAG_template_type_param
12867 || child_die
->tag
== DW_TAG_template_value_param
)
12869 templ_func
= allocate_template_symbol (objfile
);
12870 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12875 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12876 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12877 (struct symbol
*) templ_func
);
12879 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12880 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12883 /* If there is a location expression for DW_AT_frame_base, record
12885 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12886 if (attr
!= nullptr)
12887 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12889 /* If there is a location for the static link, record it. */
12890 newobj
->static_link
= NULL
;
12891 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12892 if (attr
!= nullptr)
12894 newobj
->static_link
12895 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12896 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12897 cu
->per_cu
->addr_type ());
12900 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12902 if (die
->child
!= NULL
)
12904 child_die
= die
->child
;
12905 while (child_die
&& child_die
->tag
)
12907 if (child_die
->tag
== DW_TAG_template_type_param
12908 || child_die
->tag
== DW_TAG_template_value_param
)
12910 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12913 template_args
.push_back (arg
);
12916 process_die (child_die
, cu
);
12917 child_die
= sibling_die (child_die
);
12921 inherit_abstract_dies (die
, cu
);
12923 /* If we have a DW_AT_specification, we might need to import using
12924 directives from the context of the specification DIE. See the
12925 comment in determine_prefix. */
12926 if (cu
->language
== language_cplus
12927 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12929 struct dwarf2_cu
*spec_cu
= cu
;
12930 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12934 child_die
= spec_die
->child
;
12935 while (child_die
&& child_die
->tag
)
12937 if (child_die
->tag
== DW_TAG_imported_module
)
12938 process_die (child_die
, spec_cu
);
12939 child_die
= sibling_die (child_die
);
12942 /* In some cases, GCC generates specification DIEs that
12943 themselves contain DW_AT_specification attributes. */
12944 spec_die
= die_specification (spec_die
, &spec_cu
);
12948 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12949 /* Make a block for the local symbols within. */
12950 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12951 cstk
.static_link
, lowpc
, highpc
);
12953 /* For C++, set the block's scope. */
12954 if ((cu
->language
== language_cplus
12955 || cu
->language
== language_fortran
12956 || cu
->language
== language_d
12957 || cu
->language
== language_rust
)
12958 && cu
->processing_has_namespace_info
)
12959 block_set_scope (block
, determine_prefix (die
, cu
),
12960 &objfile
->objfile_obstack
);
12962 /* If we have address ranges, record them. */
12963 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12965 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12967 /* Attach template arguments to function. */
12968 if (!template_args
.empty ())
12970 gdb_assert (templ_func
!= NULL
);
12972 templ_func
->n_template_arguments
= template_args
.size ();
12973 templ_func
->template_arguments
12974 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12975 templ_func
->n_template_arguments
);
12976 memcpy (templ_func
->template_arguments
,
12977 template_args
.data (),
12978 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12980 /* Make sure that the symtab is set on the new symbols. Even
12981 though they don't appear in this symtab directly, other parts
12982 of gdb assume that symbols do, and this is reasonably
12984 for (symbol
*sym
: template_args
)
12985 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
12988 /* In C++, we can have functions nested inside functions (e.g., when
12989 a function declares a class that has methods). This means that
12990 when we finish processing a function scope, we may need to go
12991 back to building a containing block's symbol lists. */
12992 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12993 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12995 /* If we've finished processing a top-level function, subsequent
12996 symbols go in the file symbol list. */
12997 if (cu
->get_builder ()->outermost_context_p ())
12998 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13001 /* Process all the DIES contained within a lexical block scope. Start
13002 a new scope, process the dies, and then close the scope. */
13005 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13007 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13008 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13009 CORE_ADDR lowpc
, highpc
;
13010 struct die_info
*child_die
;
13011 CORE_ADDR baseaddr
;
13013 baseaddr
= objfile
->text_section_offset ();
13015 /* Ignore blocks with missing or invalid low and high pc attributes. */
13016 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13017 as multiple lexical blocks? Handling children in a sane way would
13018 be nasty. Might be easier to properly extend generic blocks to
13019 describe ranges. */
13020 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13022 case PC_BOUNDS_NOT_PRESENT
:
13023 /* DW_TAG_lexical_block has no attributes, process its children as if
13024 there was no wrapping by that DW_TAG_lexical_block.
13025 GCC does no longer produces such DWARF since GCC r224161. */
13026 for (child_die
= die
->child
;
13027 child_die
!= NULL
&& child_die
->tag
;
13028 child_die
= sibling_die (child_die
))
13029 process_die (child_die
, cu
);
13031 case PC_BOUNDS_INVALID
:
13034 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13035 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13037 cu
->get_builder ()->push_context (0, lowpc
);
13038 if (die
->child
!= NULL
)
13040 child_die
= die
->child
;
13041 while (child_die
&& child_die
->tag
)
13043 process_die (child_die
, cu
);
13044 child_die
= sibling_die (child_die
);
13047 inherit_abstract_dies (die
, cu
);
13048 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13050 if (*cu
->get_builder ()->get_local_symbols () != NULL
13051 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13053 struct block
*block
13054 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13055 cstk
.start_addr
, highpc
);
13057 /* Note that recording ranges after traversing children, as we
13058 do here, means that recording a parent's ranges entails
13059 walking across all its children's ranges as they appear in
13060 the address map, which is quadratic behavior.
13062 It would be nicer to record the parent's ranges before
13063 traversing its children, simply overriding whatever you find
13064 there. But since we don't even decide whether to create a
13065 block until after we've traversed its children, that's hard
13067 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13069 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13070 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13073 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13076 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13078 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13079 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13080 CORE_ADDR pc
, baseaddr
;
13081 struct attribute
*attr
;
13082 struct call_site
*call_site
, call_site_local
;
13085 struct die_info
*child_die
;
13087 baseaddr
= objfile
->text_section_offset ();
13089 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13092 /* This was a pre-DWARF-5 GNU extension alias
13093 for DW_AT_call_return_pc. */
13094 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13098 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13099 "DIE %s [in module %s]"),
13100 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13103 pc
= attr
->value_as_address () + baseaddr
;
13104 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13106 if (cu
->call_site_htab
== NULL
)
13107 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13108 NULL
, &objfile
->objfile_obstack
,
13109 hashtab_obstack_allocate
, NULL
);
13110 call_site_local
.pc
= pc
;
13111 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13114 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13115 "DIE %s [in module %s]"),
13116 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13117 objfile_name (objfile
));
13121 /* Count parameters at the caller. */
13124 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13125 child_die
= sibling_die (child_die
))
13127 if (child_die
->tag
!= DW_TAG_call_site_parameter
13128 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13130 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13131 "DW_TAG_call_site child DIE %s [in module %s]"),
13132 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13133 objfile_name (objfile
));
13141 = ((struct call_site
*)
13142 obstack_alloc (&objfile
->objfile_obstack
,
13143 sizeof (*call_site
)
13144 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13146 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13147 call_site
->pc
= pc
;
13149 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13150 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13152 struct die_info
*func_die
;
13154 /* Skip also over DW_TAG_inlined_subroutine. */
13155 for (func_die
= die
->parent
;
13156 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13157 && func_die
->tag
!= DW_TAG_subroutine_type
;
13158 func_die
= func_die
->parent
);
13160 /* DW_AT_call_all_calls is a superset
13161 of DW_AT_call_all_tail_calls. */
13163 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13164 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13165 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13166 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13168 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13169 not complete. But keep CALL_SITE for look ups via call_site_htab,
13170 both the initial caller containing the real return address PC and
13171 the final callee containing the current PC of a chain of tail
13172 calls do not need to have the tail call list complete. But any
13173 function candidate for a virtual tail call frame searched via
13174 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13175 determined unambiguously. */
13179 struct type
*func_type
= NULL
;
13182 func_type
= get_die_type (func_die
, cu
);
13183 if (func_type
!= NULL
)
13185 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13187 /* Enlist this call site to the function. */
13188 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13189 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13192 complaint (_("Cannot find function owning DW_TAG_call_site "
13193 "DIE %s [in module %s]"),
13194 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13198 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13200 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13202 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13205 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13206 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13208 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13209 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13210 /* Keep NULL DWARF_BLOCK. */;
13211 else if (attr
->form_is_block ())
13213 struct dwarf2_locexpr_baton
*dlbaton
;
13215 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13216 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13217 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13218 dlbaton
->per_cu
= cu
->per_cu
;
13220 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13222 else if (attr
->form_is_ref ())
13224 struct dwarf2_cu
*target_cu
= cu
;
13225 struct die_info
*target_die
;
13227 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13228 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13229 if (die_is_declaration (target_die
, target_cu
))
13231 const char *target_physname
;
13233 /* Prefer the mangled name; otherwise compute the demangled one. */
13234 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13235 if (target_physname
== NULL
)
13236 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13237 if (target_physname
== NULL
)
13238 complaint (_("DW_AT_call_target target DIE has invalid "
13239 "physname, for referencing DIE %s [in module %s]"),
13240 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13242 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13248 /* DW_AT_entry_pc should be preferred. */
13249 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13250 <= PC_BOUNDS_INVALID
)
13251 complaint (_("DW_AT_call_target target DIE has invalid "
13252 "low pc, for referencing DIE %s [in module %s]"),
13253 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13256 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13257 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13262 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13263 "block nor reference, for DIE %s [in module %s]"),
13264 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13266 call_site
->per_cu
= cu
->per_cu
;
13268 for (child_die
= die
->child
;
13269 child_die
&& child_die
->tag
;
13270 child_die
= sibling_die (child_die
))
13272 struct call_site_parameter
*parameter
;
13273 struct attribute
*loc
, *origin
;
13275 if (child_die
->tag
!= DW_TAG_call_site_parameter
13276 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13278 /* Already printed the complaint above. */
13282 gdb_assert (call_site
->parameter_count
< nparams
);
13283 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13285 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13286 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13287 register is contained in DW_AT_call_value. */
13289 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13290 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13291 if (origin
== NULL
)
13293 /* This was a pre-DWARF-5 GNU extension alias
13294 for DW_AT_call_parameter. */
13295 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13297 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13299 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13301 sect_offset sect_off
13302 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13303 if (!cu
->header
.offset_in_cu_p (sect_off
))
13305 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13306 binding can be done only inside one CU. Such referenced DIE
13307 therefore cannot be even moved to DW_TAG_partial_unit. */
13308 complaint (_("DW_AT_call_parameter offset is not in CU for "
13309 "DW_TAG_call_site child DIE %s [in module %s]"),
13310 sect_offset_str (child_die
->sect_off
),
13311 objfile_name (objfile
));
13314 parameter
->u
.param_cu_off
13315 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13317 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13319 complaint (_("No DW_FORM_block* DW_AT_location for "
13320 "DW_TAG_call_site child DIE %s [in module %s]"),
13321 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13326 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13327 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13328 if (parameter
->u
.dwarf_reg
!= -1)
13329 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13330 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13331 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13332 ¶meter
->u
.fb_offset
))
13333 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13336 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13337 "for DW_FORM_block* DW_AT_location is supported for "
13338 "DW_TAG_call_site child DIE %s "
13340 sect_offset_str (child_die
->sect_off
),
13341 objfile_name (objfile
));
13346 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13348 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13349 if (attr
== NULL
|| !attr
->form_is_block ())
13351 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13352 "DW_TAG_call_site child DIE %s [in module %s]"),
13353 sect_offset_str (child_die
->sect_off
),
13354 objfile_name (objfile
));
13357 parameter
->value
= DW_BLOCK (attr
)->data
;
13358 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13360 /* Parameters are not pre-cleared by memset above. */
13361 parameter
->data_value
= NULL
;
13362 parameter
->data_value_size
= 0;
13363 call_site
->parameter_count
++;
13365 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13367 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13368 if (attr
!= nullptr)
13370 if (!attr
->form_is_block ())
13371 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13372 "DW_TAG_call_site child DIE %s [in module %s]"),
13373 sect_offset_str (child_die
->sect_off
),
13374 objfile_name (objfile
));
13377 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13378 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13384 /* Helper function for read_variable. If DIE represents a virtual
13385 table, then return the type of the concrete object that is
13386 associated with the virtual table. Otherwise, return NULL. */
13388 static struct type
*
13389 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13391 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13395 /* Find the type DIE. */
13396 struct die_info
*type_die
= NULL
;
13397 struct dwarf2_cu
*type_cu
= cu
;
13399 if (attr
->form_is_ref ())
13400 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13401 if (type_die
== NULL
)
13404 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13406 return die_containing_type (type_die
, type_cu
);
13409 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13412 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13414 struct rust_vtable_symbol
*storage
= NULL
;
13416 if (cu
->language
== language_rust
)
13418 struct type
*containing_type
= rust_containing_type (die
, cu
);
13420 if (containing_type
!= NULL
)
13422 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13424 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13425 initialize_objfile_symbol (storage
);
13426 storage
->concrete_type
= containing_type
;
13427 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13431 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13432 struct attribute
*abstract_origin
13433 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13434 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13435 if (res
== NULL
&& loc
&& abstract_origin
)
13437 /* We have a variable without a name, but with a location and an abstract
13438 origin. This may be a concrete instance of an abstract variable
13439 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13441 struct dwarf2_cu
*origin_cu
= cu
;
13442 struct die_info
*origin_die
13443 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13444 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13445 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13449 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13450 reading .debug_rnglists.
13451 Callback's type should be:
13452 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13453 Return true if the attributes are present and valid, otherwise,
13456 template <typename Callback
>
13458 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13459 Callback
&&callback
)
13461 struct dwarf2_per_objfile
*dwarf2_per_objfile
13462 = cu
->per_cu
->dwarf2_per_objfile
;
13463 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13464 bfd
*obfd
= objfile
->obfd
;
13465 /* Base address selection entry. */
13468 const gdb_byte
*buffer
;
13469 CORE_ADDR baseaddr
;
13470 bool overflow
= false;
13472 found_base
= cu
->base_known
;
13473 base
= cu
->base_address
;
13475 dwarf2_per_objfile
->rnglists
.read (objfile
);
13476 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13478 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13482 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13484 baseaddr
= objfile
->text_section_offset ();
13488 /* Initialize it due to a false compiler warning. */
13489 CORE_ADDR range_beginning
= 0, range_end
= 0;
13490 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13491 + dwarf2_per_objfile
->rnglists
.size
);
13492 unsigned int bytes_read
;
13494 if (buffer
== buf_end
)
13499 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13502 case DW_RLE_end_of_list
:
13504 case DW_RLE_base_address
:
13505 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13510 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13512 buffer
+= bytes_read
;
13514 case DW_RLE_start_length
:
13515 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13520 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13522 buffer
+= bytes_read
;
13523 range_end
= (range_beginning
13524 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13525 buffer
+= bytes_read
;
13526 if (buffer
> buf_end
)
13532 case DW_RLE_offset_pair
:
13533 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13534 buffer
+= bytes_read
;
13535 if (buffer
> buf_end
)
13540 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13541 buffer
+= bytes_read
;
13542 if (buffer
> buf_end
)
13548 case DW_RLE_start_end
:
13549 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13554 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13556 buffer
+= bytes_read
;
13557 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13558 buffer
+= bytes_read
;
13561 complaint (_("Invalid .debug_rnglists data (no base address)"));
13564 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13566 if (rlet
== DW_RLE_base_address
)
13571 /* We have no valid base address for the ranges
13573 complaint (_("Invalid .debug_rnglists data (no base address)"));
13577 if (range_beginning
> range_end
)
13579 /* Inverted range entries are invalid. */
13580 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13584 /* Empty range entries have no effect. */
13585 if (range_beginning
== range_end
)
13588 range_beginning
+= base
;
13591 /* A not-uncommon case of bad debug info.
13592 Don't pollute the addrmap with bad data. */
13593 if (range_beginning
+ baseaddr
== 0
13594 && !dwarf2_per_objfile
->has_section_at_zero
)
13596 complaint (_(".debug_rnglists entry has start address of zero"
13597 " [in module %s]"), objfile_name (objfile
));
13601 callback (range_beginning
, range_end
);
13606 complaint (_("Offset %d is not terminated "
13607 "for DW_AT_ranges attribute"),
13615 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13616 Callback's type should be:
13617 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13618 Return 1 if the attributes are present and valid, otherwise, return 0. */
13620 template <typename Callback
>
13622 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13623 Callback
&&callback
)
13625 struct dwarf2_per_objfile
*dwarf2_per_objfile
13626 = cu
->per_cu
->dwarf2_per_objfile
;
13627 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13628 struct comp_unit_head
*cu_header
= &cu
->header
;
13629 bfd
*obfd
= objfile
->obfd
;
13630 unsigned int addr_size
= cu_header
->addr_size
;
13631 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13632 /* Base address selection entry. */
13635 unsigned int dummy
;
13636 const gdb_byte
*buffer
;
13637 CORE_ADDR baseaddr
;
13639 if (cu_header
->version
>= 5)
13640 return dwarf2_rnglists_process (offset
, cu
, callback
);
13642 found_base
= cu
->base_known
;
13643 base
= cu
->base_address
;
13645 dwarf2_per_objfile
->ranges
.read (objfile
);
13646 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13648 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13652 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13654 baseaddr
= objfile
->text_section_offset ();
13658 CORE_ADDR range_beginning
, range_end
;
13660 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13661 buffer
+= addr_size
;
13662 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13663 buffer
+= addr_size
;
13664 offset
+= 2 * addr_size
;
13666 /* An end of list marker is a pair of zero addresses. */
13667 if (range_beginning
== 0 && range_end
== 0)
13668 /* Found the end of list entry. */
13671 /* Each base address selection entry is a pair of 2 values.
13672 The first is the largest possible address, the second is
13673 the base address. Check for a base address here. */
13674 if ((range_beginning
& mask
) == mask
)
13676 /* If we found the largest possible address, then we already
13677 have the base address in range_end. */
13685 /* We have no valid base address for the ranges
13687 complaint (_("Invalid .debug_ranges data (no base address)"));
13691 if (range_beginning
> range_end
)
13693 /* Inverted range entries are invalid. */
13694 complaint (_("Invalid .debug_ranges data (inverted range)"));
13698 /* Empty range entries have no effect. */
13699 if (range_beginning
== range_end
)
13702 range_beginning
+= base
;
13705 /* A not-uncommon case of bad debug info.
13706 Don't pollute the addrmap with bad data. */
13707 if (range_beginning
+ baseaddr
== 0
13708 && !dwarf2_per_objfile
->has_section_at_zero
)
13710 complaint (_(".debug_ranges entry has start address of zero"
13711 " [in module %s]"), objfile_name (objfile
));
13715 callback (range_beginning
, range_end
);
13721 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13722 Return 1 if the attributes are present and valid, otherwise, return 0.
13723 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13726 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13727 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13728 dwarf2_psymtab
*ranges_pst
)
13730 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13731 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13732 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13735 CORE_ADDR high
= 0;
13738 retval
= dwarf2_ranges_process (offset
, cu
,
13739 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13741 if (ranges_pst
!= NULL
)
13746 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13747 range_beginning
+ baseaddr
)
13749 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13750 range_end
+ baseaddr
)
13752 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13753 lowpc
, highpc
- 1, ranges_pst
);
13756 /* FIXME: This is recording everything as a low-high
13757 segment of consecutive addresses. We should have a
13758 data structure for discontiguous block ranges
13762 low
= range_beginning
;
13768 if (range_beginning
< low
)
13769 low
= range_beginning
;
13770 if (range_end
> high
)
13778 /* If the first entry is an end-of-list marker, the range
13779 describes an empty scope, i.e. no instructions. */
13785 *high_return
= high
;
13789 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13790 definition for the return value. *LOWPC and *HIGHPC are set iff
13791 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13793 static enum pc_bounds_kind
13794 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13795 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13796 dwarf2_psymtab
*pst
)
13798 struct dwarf2_per_objfile
*dwarf2_per_objfile
13799 = cu
->per_cu
->dwarf2_per_objfile
;
13800 struct attribute
*attr
;
13801 struct attribute
*attr_high
;
13803 CORE_ADDR high
= 0;
13804 enum pc_bounds_kind ret
;
13806 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13809 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13810 if (attr
!= nullptr)
13812 low
= attr
->value_as_address ();
13813 high
= attr_high
->value_as_address ();
13814 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13818 /* Found high w/o low attribute. */
13819 return PC_BOUNDS_INVALID
;
13821 /* Found consecutive range of addresses. */
13822 ret
= PC_BOUNDS_HIGH_LOW
;
13826 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13829 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13830 We take advantage of the fact that DW_AT_ranges does not appear
13831 in DW_TAG_compile_unit of DWO files. */
13832 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13833 unsigned int ranges_offset
= (DW_UNSND (attr
)
13834 + (need_ranges_base
13838 /* Value of the DW_AT_ranges attribute is the offset in the
13839 .debug_ranges section. */
13840 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13841 return PC_BOUNDS_INVALID
;
13842 /* Found discontinuous range of addresses. */
13843 ret
= PC_BOUNDS_RANGES
;
13846 return PC_BOUNDS_NOT_PRESENT
;
13849 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13851 return PC_BOUNDS_INVALID
;
13853 /* When using the GNU linker, .gnu.linkonce. sections are used to
13854 eliminate duplicate copies of functions and vtables and such.
13855 The linker will arbitrarily choose one and discard the others.
13856 The AT_*_pc values for such functions refer to local labels in
13857 these sections. If the section from that file was discarded, the
13858 labels are not in the output, so the relocs get a value of 0.
13859 If this is a discarded function, mark the pc bounds as invalid,
13860 so that GDB will ignore it. */
13861 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13862 return PC_BOUNDS_INVALID
;
13870 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13871 its low and high PC addresses. Do nothing if these addresses could not
13872 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13873 and HIGHPC to the high address if greater than HIGHPC. */
13876 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13877 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13878 struct dwarf2_cu
*cu
)
13880 CORE_ADDR low
, high
;
13881 struct die_info
*child
= die
->child
;
13883 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13885 *lowpc
= std::min (*lowpc
, low
);
13886 *highpc
= std::max (*highpc
, high
);
13889 /* If the language does not allow nested subprograms (either inside
13890 subprograms or lexical blocks), we're done. */
13891 if (cu
->language
!= language_ada
)
13894 /* Check all the children of the given DIE. If it contains nested
13895 subprograms, then check their pc bounds. Likewise, we need to
13896 check lexical blocks as well, as they may also contain subprogram
13898 while (child
&& child
->tag
)
13900 if (child
->tag
== DW_TAG_subprogram
13901 || child
->tag
== DW_TAG_lexical_block
)
13902 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13903 child
= sibling_die (child
);
13907 /* Get the low and high pc's represented by the scope DIE, and store
13908 them in *LOWPC and *HIGHPC. If the correct values can't be
13909 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13912 get_scope_pc_bounds (struct die_info
*die
,
13913 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13914 struct dwarf2_cu
*cu
)
13916 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13917 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13918 CORE_ADDR current_low
, current_high
;
13920 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13921 >= PC_BOUNDS_RANGES
)
13923 best_low
= current_low
;
13924 best_high
= current_high
;
13928 struct die_info
*child
= die
->child
;
13930 while (child
&& child
->tag
)
13932 switch (child
->tag
) {
13933 case DW_TAG_subprogram
:
13934 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13936 case DW_TAG_namespace
:
13937 case DW_TAG_module
:
13938 /* FIXME: carlton/2004-01-16: Should we do this for
13939 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13940 that current GCC's always emit the DIEs corresponding
13941 to definitions of methods of classes as children of a
13942 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13943 the DIEs giving the declarations, which could be
13944 anywhere). But I don't see any reason why the
13945 standards says that they have to be there. */
13946 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13948 if (current_low
!= ((CORE_ADDR
) -1))
13950 best_low
= std::min (best_low
, current_low
);
13951 best_high
= std::max (best_high
, current_high
);
13959 child
= sibling_die (child
);
13964 *highpc
= best_high
;
13967 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13971 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13972 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13974 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13975 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13976 struct attribute
*attr
;
13977 struct attribute
*attr_high
;
13979 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13982 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13983 if (attr
!= nullptr)
13985 CORE_ADDR low
= attr
->value_as_address ();
13986 CORE_ADDR high
= attr_high
->value_as_address ();
13988 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13991 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13992 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13993 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
13997 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13998 if (attr
!= nullptr)
14000 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14001 We take advantage of the fact that DW_AT_ranges does not appear
14002 in DW_TAG_compile_unit of DWO files. */
14003 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14005 /* The value of the DW_AT_ranges attribute is the offset of the
14006 address range list in the .debug_ranges section. */
14007 unsigned long offset
= (DW_UNSND (attr
)
14008 + (need_ranges_base
? cu
->ranges_base
: 0));
14010 std::vector
<blockrange
> blockvec
;
14011 dwarf2_ranges_process (offset
, cu
,
14012 [&] (CORE_ADDR start
, CORE_ADDR end
)
14016 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14017 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14018 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14019 blockvec
.emplace_back (start
, end
);
14022 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14026 /* Check whether the producer field indicates either of GCC < 4.6, or the
14027 Intel C/C++ compiler, and cache the result in CU. */
14030 check_producer (struct dwarf2_cu
*cu
)
14034 if (cu
->producer
== NULL
)
14036 /* For unknown compilers expect their behavior is DWARF version
14039 GCC started to support .debug_types sections by -gdwarf-4 since
14040 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14041 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14042 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14043 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14045 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14047 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14048 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14050 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14052 cu
->producer_is_icc
= true;
14053 cu
->producer_is_icc_lt_14
= major
< 14;
14055 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14056 cu
->producer_is_codewarrior
= true;
14059 /* For other non-GCC compilers, expect their behavior is DWARF version
14063 cu
->checked_producer
= true;
14066 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14067 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14068 during 4.6.0 experimental. */
14071 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14073 if (!cu
->checked_producer
)
14074 check_producer (cu
);
14076 return cu
->producer_is_gxx_lt_4_6
;
14080 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14081 with incorrect is_stmt attributes. */
14084 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14086 if (!cu
->checked_producer
)
14087 check_producer (cu
);
14089 return cu
->producer_is_codewarrior
;
14092 /* Return the default accessibility type if it is not overridden by
14093 DW_AT_accessibility. */
14095 static enum dwarf_access_attribute
14096 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14098 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14100 /* The default DWARF 2 accessibility for members is public, the default
14101 accessibility for inheritance is private. */
14103 if (die
->tag
!= DW_TAG_inheritance
)
14104 return DW_ACCESS_public
;
14106 return DW_ACCESS_private
;
14110 /* DWARF 3+ defines the default accessibility a different way. The same
14111 rules apply now for DW_TAG_inheritance as for the members and it only
14112 depends on the container kind. */
14114 if (die
->parent
->tag
== DW_TAG_class_type
)
14115 return DW_ACCESS_private
;
14117 return DW_ACCESS_public
;
14121 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14122 offset. If the attribute was not found return 0, otherwise return
14123 1. If it was found but could not properly be handled, set *OFFSET
14127 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14130 struct attribute
*attr
;
14132 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14137 /* Note that we do not check for a section offset first here.
14138 This is because DW_AT_data_member_location is new in DWARF 4,
14139 so if we see it, we can assume that a constant form is really
14140 a constant and not a section offset. */
14141 if (attr
->form_is_constant ())
14142 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14143 else if (attr
->form_is_section_offset ())
14144 dwarf2_complex_location_expr_complaint ();
14145 else if (attr
->form_is_block ())
14146 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14148 dwarf2_complex_location_expr_complaint ();
14156 /* Add an aggregate field to the field list. */
14159 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14160 struct dwarf2_cu
*cu
)
14162 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14163 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14164 struct nextfield
*new_field
;
14165 struct attribute
*attr
;
14167 const char *fieldname
= "";
14169 if (die
->tag
== DW_TAG_inheritance
)
14171 fip
->baseclasses
.emplace_back ();
14172 new_field
= &fip
->baseclasses
.back ();
14176 fip
->fields
.emplace_back ();
14177 new_field
= &fip
->fields
.back ();
14182 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14183 if (attr
!= nullptr)
14184 new_field
->accessibility
= DW_UNSND (attr
);
14186 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14187 if (new_field
->accessibility
!= DW_ACCESS_public
)
14188 fip
->non_public_fields
= 1;
14190 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14191 if (attr
!= nullptr)
14192 new_field
->virtuality
= DW_UNSND (attr
);
14194 new_field
->virtuality
= DW_VIRTUALITY_none
;
14196 fp
= &new_field
->field
;
14198 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14202 /* Data member other than a C++ static data member. */
14204 /* Get type of field. */
14205 fp
->type
= die_type (die
, cu
);
14207 SET_FIELD_BITPOS (*fp
, 0);
14209 /* Get bit size of field (zero if none). */
14210 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14211 if (attr
!= nullptr)
14213 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14217 FIELD_BITSIZE (*fp
) = 0;
14220 /* Get bit offset of field. */
14221 if (handle_data_member_location (die
, cu
, &offset
))
14222 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14223 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14224 if (attr
!= nullptr)
14226 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14228 /* For big endian bits, the DW_AT_bit_offset gives the
14229 additional bit offset from the MSB of the containing
14230 anonymous object to the MSB of the field. We don't
14231 have to do anything special since we don't need to
14232 know the size of the anonymous object. */
14233 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14237 /* For little endian bits, compute the bit offset to the
14238 MSB of the anonymous object, subtract off the number of
14239 bits from the MSB of the field to the MSB of the
14240 object, and then subtract off the number of bits of
14241 the field itself. The result is the bit offset of
14242 the LSB of the field. */
14243 int anonymous_size
;
14244 int bit_offset
= DW_UNSND (attr
);
14246 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14247 if (attr
!= nullptr)
14249 /* The size of the anonymous object containing
14250 the bit field is explicit, so use the
14251 indicated size (in bytes). */
14252 anonymous_size
= DW_UNSND (attr
);
14256 /* The size of the anonymous object containing
14257 the bit field must be inferred from the type
14258 attribute of the data member containing the
14260 anonymous_size
= TYPE_LENGTH (fp
->type
);
14262 SET_FIELD_BITPOS (*fp
,
14263 (FIELD_BITPOS (*fp
)
14264 + anonymous_size
* bits_per_byte
14265 - bit_offset
- FIELD_BITSIZE (*fp
)));
14268 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14270 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14271 + dwarf2_get_attr_constant_value (attr
, 0)));
14273 /* Get name of field. */
14274 fieldname
= dwarf2_name (die
, cu
);
14275 if (fieldname
== NULL
)
14278 /* The name is already allocated along with this objfile, so we don't
14279 need to duplicate it for the type. */
14280 fp
->name
= fieldname
;
14282 /* Change accessibility for artificial fields (e.g. virtual table
14283 pointer or virtual base class pointer) to private. */
14284 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14286 FIELD_ARTIFICIAL (*fp
) = 1;
14287 new_field
->accessibility
= DW_ACCESS_private
;
14288 fip
->non_public_fields
= 1;
14291 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14293 /* C++ static member. */
14295 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14296 is a declaration, but all versions of G++ as of this writing
14297 (so through at least 3.2.1) incorrectly generate
14298 DW_TAG_variable tags. */
14300 const char *physname
;
14302 /* Get name of field. */
14303 fieldname
= dwarf2_name (die
, cu
);
14304 if (fieldname
== NULL
)
14307 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14309 /* Only create a symbol if this is an external value.
14310 new_symbol checks this and puts the value in the global symbol
14311 table, which we want. If it is not external, new_symbol
14312 will try to put the value in cu->list_in_scope which is wrong. */
14313 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14315 /* A static const member, not much different than an enum as far as
14316 we're concerned, except that we can support more types. */
14317 new_symbol (die
, NULL
, cu
);
14320 /* Get physical name. */
14321 physname
= dwarf2_physname (fieldname
, die
, cu
);
14323 /* The name is already allocated along with this objfile, so we don't
14324 need to duplicate it for the type. */
14325 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14326 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14327 FIELD_NAME (*fp
) = fieldname
;
14329 else if (die
->tag
== DW_TAG_inheritance
)
14333 /* C++ base class field. */
14334 if (handle_data_member_location (die
, cu
, &offset
))
14335 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14336 FIELD_BITSIZE (*fp
) = 0;
14337 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14338 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14340 else if (die
->tag
== DW_TAG_variant_part
)
14342 /* process_structure_scope will treat this DIE as a union. */
14343 process_structure_scope (die
, cu
);
14345 /* The variant part is relative to the start of the enclosing
14347 SET_FIELD_BITPOS (*fp
, 0);
14348 fp
->type
= get_die_type (die
, cu
);
14349 fp
->artificial
= 1;
14350 fp
->name
= "<<variant>>";
14352 /* Normally a DW_TAG_variant_part won't have a size, but our
14353 representation requires one, so set it to the maximum of the
14354 child sizes, being sure to account for the offset at which
14355 each child is seen. */
14356 if (TYPE_LENGTH (fp
->type
) == 0)
14359 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14361 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14362 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14366 TYPE_LENGTH (fp
->type
) = max
;
14370 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14373 /* Can the type given by DIE define another type? */
14376 type_can_define_types (const struct die_info
*die
)
14380 case DW_TAG_typedef
:
14381 case DW_TAG_class_type
:
14382 case DW_TAG_structure_type
:
14383 case DW_TAG_union_type
:
14384 case DW_TAG_enumeration_type
:
14392 /* Add a type definition defined in the scope of the FIP's class. */
14395 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14396 struct dwarf2_cu
*cu
)
14398 struct decl_field fp
;
14399 memset (&fp
, 0, sizeof (fp
));
14401 gdb_assert (type_can_define_types (die
));
14403 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14404 fp
.name
= dwarf2_name (die
, cu
);
14405 fp
.type
= read_type_die (die
, cu
);
14407 /* Save accessibility. */
14408 enum dwarf_access_attribute accessibility
;
14409 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14411 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14413 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14414 switch (accessibility
)
14416 case DW_ACCESS_public
:
14417 /* The assumed value if neither private nor protected. */
14419 case DW_ACCESS_private
:
14422 case DW_ACCESS_protected
:
14423 fp
.is_protected
= 1;
14426 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14429 if (die
->tag
== DW_TAG_typedef
)
14430 fip
->typedef_field_list
.push_back (fp
);
14432 fip
->nested_types_list
.push_back (fp
);
14435 /* Create the vector of fields, and attach it to the type. */
14438 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14439 struct dwarf2_cu
*cu
)
14441 int nfields
= fip
->nfields
;
14443 /* Record the field count, allocate space for the array of fields,
14444 and create blank accessibility bitfields if necessary. */
14445 TYPE_NFIELDS (type
) = nfields
;
14446 TYPE_FIELDS (type
) = (struct field
*)
14447 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14449 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14451 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14453 TYPE_FIELD_PRIVATE_BITS (type
) =
14454 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14455 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14457 TYPE_FIELD_PROTECTED_BITS (type
) =
14458 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14459 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14461 TYPE_FIELD_IGNORE_BITS (type
) =
14462 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14463 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14466 /* If the type has baseclasses, allocate and clear a bit vector for
14467 TYPE_FIELD_VIRTUAL_BITS. */
14468 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14470 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14471 unsigned char *pointer
;
14473 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14474 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14475 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14476 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14477 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14480 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14482 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14484 for (int index
= 0; index
< nfields
; ++index
)
14486 struct nextfield
&field
= fip
->fields
[index
];
14488 if (field
.variant
.is_discriminant
)
14489 di
->discriminant_index
= index
;
14490 else if (field
.variant
.default_branch
)
14491 di
->default_index
= index
;
14493 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14497 /* Copy the saved-up fields into the field vector. */
14498 for (int i
= 0; i
< nfields
; ++i
)
14500 struct nextfield
&field
14501 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14502 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14504 TYPE_FIELD (type
, i
) = field
.field
;
14505 switch (field
.accessibility
)
14507 case DW_ACCESS_private
:
14508 if (cu
->language
!= language_ada
)
14509 SET_TYPE_FIELD_PRIVATE (type
, i
);
14512 case DW_ACCESS_protected
:
14513 if (cu
->language
!= language_ada
)
14514 SET_TYPE_FIELD_PROTECTED (type
, i
);
14517 case DW_ACCESS_public
:
14521 /* Unknown accessibility. Complain and treat it as public. */
14523 complaint (_("unsupported accessibility %d"),
14524 field
.accessibility
);
14528 if (i
< fip
->baseclasses
.size ())
14530 switch (field
.virtuality
)
14532 case DW_VIRTUALITY_virtual
:
14533 case DW_VIRTUALITY_pure_virtual
:
14534 if (cu
->language
== language_ada
)
14535 error (_("unexpected virtuality in component of Ada type"));
14536 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14543 /* Return true if this member function is a constructor, false
14547 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14549 const char *fieldname
;
14550 const char *type_name
;
14553 if (die
->parent
== NULL
)
14556 if (die
->parent
->tag
!= DW_TAG_structure_type
14557 && die
->parent
->tag
!= DW_TAG_union_type
14558 && die
->parent
->tag
!= DW_TAG_class_type
)
14561 fieldname
= dwarf2_name (die
, cu
);
14562 type_name
= dwarf2_name (die
->parent
, cu
);
14563 if (fieldname
== NULL
|| type_name
== NULL
)
14566 len
= strlen (fieldname
);
14567 return (strncmp (fieldname
, type_name
, len
) == 0
14568 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14571 /* Check if the given VALUE is a recognized enum
14572 dwarf_defaulted_attribute constant according to DWARF5 spec,
14576 is_valid_DW_AT_defaulted (ULONGEST value
)
14580 case DW_DEFAULTED_no
:
14581 case DW_DEFAULTED_in_class
:
14582 case DW_DEFAULTED_out_of_class
:
14586 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14590 /* Add a member function to the proper fieldlist. */
14593 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14594 struct type
*type
, struct dwarf2_cu
*cu
)
14596 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14597 struct attribute
*attr
;
14599 struct fnfieldlist
*flp
= nullptr;
14600 struct fn_field
*fnp
;
14601 const char *fieldname
;
14602 struct type
*this_type
;
14603 enum dwarf_access_attribute accessibility
;
14605 if (cu
->language
== language_ada
)
14606 error (_("unexpected member function in Ada type"));
14608 /* Get name of member function. */
14609 fieldname
= dwarf2_name (die
, cu
);
14610 if (fieldname
== NULL
)
14613 /* Look up member function name in fieldlist. */
14614 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14616 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14618 flp
= &fip
->fnfieldlists
[i
];
14623 /* Create a new fnfieldlist if necessary. */
14624 if (flp
== nullptr)
14626 fip
->fnfieldlists
.emplace_back ();
14627 flp
= &fip
->fnfieldlists
.back ();
14628 flp
->name
= fieldname
;
14629 i
= fip
->fnfieldlists
.size () - 1;
14632 /* Create a new member function field and add it to the vector of
14634 flp
->fnfields
.emplace_back ();
14635 fnp
= &flp
->fnfields
.back ();
14637 /* Delay processing of the physname until later. */
14638 if (cu
->language
== language_cplus
)
14639 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14643 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14644 fnp
->physname
= physname
? physname
: "";
14647 fnp
->type
= alloc_type (objfile
);
14648 this_type
= read_type_die (die
, cu
);
14649 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14651 int nparams
= TYPE_NFIELDS (this_type
);
14653 /* TYPE is the domain of this method, and THIS_TYPE is the type
14654 of the method itself (TYPE_CODE_METHOD). */
14655 smash_to_method_type (fnp
->type
, type
,
14656 TYPE_TARGET_TYPE (this_type
),
14657 TYPE_FIELDS (this_type
),
14658 TYPE_NFIELDS (this_type
),
14659 TYPE_VARARGS (this_type
));
14661 /* Handle static member functions.
14662 Dwarf2 has no clean way to discern C++ static and non-static
14663 member functions. G++ helps GDB by marking the first
14664 parameter for non-static member functions (which is the this
14665 pointer) as artificial. We obtain this information from
14666 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14667 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14668 fnp
->voffset
= VOFFSET_STATIC
;
14671 complaint (_("member function type missing for '%s'"),
14672 dwarf2_full_name (fieldname
, die
, cu
));
14674 /* Get fcontext from DW_AT_containing_type if present. */
14675 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14676 fnp
->fcontext
= die_containing_type (die
, cu
);
14678 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14679 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14681 /* Get accessibility. */
14682 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14683 if (attr
!= nullptr)
14684 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14686 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14687 switch (accessibility
)
14689 case DW_ACCESS_private
:
14690 fnp
->is_private
= 1;
14692 case DW_ACCESS_protected
:
14693 fnp
->is_protected
= 1;
14697 /* Check for artificial methods. */
14698 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14699 if (attr
&& DW_UNSND (attr
) != 0)
14700 fnp
->is_artificial
= 1;
14702 /* Check for defaulted methods. */
14703 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14704 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14705 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14707 /* Check for deleted methods. */
14708 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14709 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14710 fnp
->is_deleted
= 1;
14712 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14714 /* Get index in virtual function table if it is a virtual member
14715 function. For older versions of GCC, this is an offset in the
14716 appropriate virtual table, as specified by DW_AT_containing_type.
14717 For everyone else, it is an expression to be evaluated relative
14718 to the object address. */
14720 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14721 if (attr
!= nullptr)
14723 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14725 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14727 /* Old-style GCC. */
14728 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14730 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14731 || (DW_BLOCK (attr
)->size
> 1
14732 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14733 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14735 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14736 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14737 dwarf2_complex_location_expr_complaint ();
14739 fnp
->voffset
/= cu
->header
.addr_size
;
14743 dwarf2_complex_location_expr_complaint ();
14745 if (!fnp
->fcontext
)
14747 /* If there is no `this' field and no DW_AT_containing_type,
14748 we cannot actually find a base class context for the
14750 if (TYPE_NFIELDS (this_type
) == 0
14751 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14753 complaint (_("cannot determine context for virtual member "
14754 "function \"%s\" (offset %s)"),
14755 fieldname
, sect_offset_str (die
->sect_off
));
14760 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14764 else if (attr
->form_is_section_offset ())
14766 dwarf2_complex_location_expr_complaint ();
14770 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14776 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14777 if (attr
&& DW_UNSND (attr
))
14779 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14780 complaint (_("Member function \"%s\" (offset %s) is virtual "
14781 "but the vtable offset is not specified"),
14782 fieldname
, sect_offset_str (die
->sect_off
));
14783 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14784 TYPE_CPLUS_DYNAMIC (type
) = 1;
14789 /* Create the vector of member function fields, and attach it to the type. */
14792 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14793 struct dwarf2_cu
*cu
)
14795 if (cu
->language
== language_ada
)
14796 error (_("unexpected member functions in Ada type"));
14798 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14799 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14801 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14803 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14805 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14806 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14808 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14809 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14810 fn_flp
->fn_fields
= (struct fn_field
*)
14811 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14813 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14814 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14817 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14820 /* Returns non-zero if NAME is the name of a vtable member in CU's
14821 language, zero otherwise. */
14823 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14825 static const char vptr
[] = "_vptr";
14827 /* Look for the C++ form of the vtable. */
14828 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14834 /* GCC outputs unnamed structures that are really pointers to member
14835 functions, with the ABI-specified layout. If TYPE describes
14836 such a structure, smash it into a member function type.
14838 GCC shouldn't do this; it should just output pointer to member DIEs.
14839 This is GCC PR debug/28767. */
14842 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14844 struct type
*pfn_type
, *self_type
, *new_type
;
14846 /* Check for a structure with no name and two children. */
14847 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14850 /* Check for __pfn and __delta members. */
14851 if (TYPE_FIELD_NAME (type
, 0) == NULL
14852 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14853 || TYPE_FIELD_NAME (type
, 1) == NULL
14854 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14857 /* Find the type of the method. */
14858 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14859 if (pfn_type
== NULL
14860 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14861 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14864 /* Look for the "this" argument. */
14865 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14866 if (TYPE_NFIELDS (pfn_type
) == 0
14867 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14868 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14871 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14872 new_type
= alloc_type (objfile
);
14873 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14874 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14875 TYPE_VARARGS (pfn_type
));
14876 smash_to_methodptr_type (type
, new_type
);
14879 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14880 appropriate error checking and issuing complaints if there is a
14884 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14886 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14888 if (attr
== nullptr)
14891 if (!attr
->form_is_constant ())
14893 complaint (_("DW_AT_alignment must have constant form"
14894 " - DIE at %s [in module %s]"),
14895 sect_offset_str (die
->sect_off
),
14896 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14901 if (attr
->form
== DW_FORM_sdata
)
14903 LONGEST val
= DW_SND (attr
);
14906 complaint (_("DW_AT_alignment value must not be negative"
14907 " - DIE at %s [in module %s]"),
14908 sect_offset_str (die
->sect_off
),
14909 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14915 align
= DW_UNSND (attr
);
14919 complaint (_("DW_AT_alignment value must not be zero"
14920 " - DIE at %s [in module %s]"),
14921 sect_offset_str (die
->sect_off
),
14922 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14925 if ((align
& (align
- 1)) != 0)
14927 complaint (_("DW_AT_alignment value must be a power of 2"
14928 " - DIE at %s [in module %s]"),
14929 sect_offset_str (die
->sect_off
),
14930 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14937 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14938 the alignment for TYPE. */
14941 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14944 if (!set_type_align (type
, get_alignment (cu
, die
)))
14945 complaint (_("DW_AT_alignment value too large"
14946 " - DIE at %s [in module %s]"),
14947 sect_offset_str (die
->sect_off
),
14948 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14951 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14952 constant for a type, according to DWARF5 spec, Table 5.5. */
14955 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14960 case DW_CC_pass_by_reference
:
14961 case DW_CC_pass_by_value
:
14965 complaint (_("unrecognized DW_AT_calling_convention value "
14966 "(%s) for a type"), pulongest (value
));
14971 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14972 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14973 also according to GNU-specific values (see include/dwarf2.h). */
14976 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14981 case DW_CC_program
:
14985 case DW_CC_GNU_renesas_sh
:
14986 case DW_CC_GNU_borland_fastcall_i386
:
14987 case DW_CC_GDB_IBM_OpenCL
:
14991 complaint (_("unrecognized DW_AT_calling_convention value "
14992 "(%s) for a subroutine"), pulongest (value
));
14997 /* Called when we find the DIE that starts a structure or union scope
14998 (definition) to create a type for the structure or union. Fill in
14999 the type's name and general properties; the members will not be
15000 processed until process_structure_scope. A symbol table entry for
15001 the type will also not be done until process_structure_scope (assuming
15002 the type has a name).
15004 NOTE: we need to call these functions regardless of whether or not the
15005 DIE has a DW_AT_name attribute, since it might be an anonymous
15006 structure or union. This gets the type entered into our set of
15007 user defined types. */
15009 static struct type
*
15010 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15012 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15014 struct attribute
*attr
;
15017 /* If the definition of this type lives in .debug_types, read that type.
15018 Don't follow DW_AT_specification though, that will take us back up
15019 the chain and we want to go down. */
15020 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15021 if (attr
!= nullptr)
15023 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15025 /* The type's CU may not be the same as CU.
15026 Ensure TYPE is recorded with CU in die_type_hash. */
15027 return set_die_type (die
, type
, cu
);
15030 type
= alloc_type (objfile
);
15031 INIT_CPLUS_SPECIFIC (type
);
15033 name
= dwarf2_name (die
, cu
);
15036 if (cu
->language
== language_cplus
15037 || cu
->language
== language_d
15038 || cu
->language
== language_rust
)
15040 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15042 /* dwarf2_full_name might have already finished building the DIE's
15043 type. If so, there is no need to continue. */
15044 if (get_die_type (die
, cu
) != NULL
)
15045 return get_die_type (die
, cu
);
15047 TYPE_NAME (type
) = full_name
;
15051 /* The name is already allocated along with this objfile, so
15052 we don't need to duplicate it for the type. */
15053 TYPE_NAME (type
) = name
;
15057 if (die
->tag
== DW_TAG_structure_type
)
15059 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15061 else if (die
->tag
== DW_TAG_union_type
)
15063 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15065 else if (die
->tag
== DW_TAG_variant_part
)
15067 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15068 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15072 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15075 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15076 TYPE_DECLARED_CLASS (type
) = 1;
15078 /* Store the calling convention in the type if it's available in
15079 the die. Otherwise the calling convention remains set to
15080 the default value DW_CC_normal. */
15081 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15082 if (attr
!= nullptr
15083 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15085 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15086 TYPE_CPLUS_CALLING_CONVENTION (type
)
15087 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15090 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15091 if (attr
!= nullptr)
15093 if (attr
->form_is_constant ())
15094 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15097 /* For the moment, dynamic type sizes are not supported
15098 by GDB's struct type. The actual size is determined
15099 on-demand when resolving the type of a given object,
15100 so set the type's length to zero for now. Otherwise,
15101 we record an expression as the length, and that expression
15102 could lead to a very large value, which could eventually
15103 lead to us trying to allocate that much memory when creating
15104 a value of that type. */
15105 TYPE_LENGTH (type
) = 0;
15110 TYPE_LENGTH (type
) = 0;
15113 maybe_set_alignment (cu
, die
, type
);
15115 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15117 /* ICC<14 does not output the required DW_AT_declaration on
15118 incomplete types, but gives them a size of zero. */
15119 TYPE_STUB (type
) = 1;
15122 TYPE_STUB_SUPPORTED (type
) = 1;
15124 if (die_is_declaration (die
, cu
))
15125 TYPE_STUB (type
) = 1;
15126 else if (attr
== NULL
&& die
->child
== NULL
15127 && producer_is_realview (cu
->producer
))
15128 /* RealView does not output the required DW_AT_declaration
15129 on incomplete types. */
15130 TYPE_STUB (type
) = 1;
15132 /* We need to add the type field to the die immediately so we don't
15133 infinitely recurse when dealing with pointers to the structure
15134 type within the structure itself. */
15135 set_die_type (die
, type
, cu
);
15137 /* set_die_type should be already done. */
15138 set_descriptive_type (type
, die
, cu
);
15143 /* A helper for process_structure_scope that handles a single member
15147 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15148 struct field_info
*fi
,
15149 std::vector
<struct symbol
*> *template_args
,
15150 struct dwarf2_cu
*cu
)
15152 if (child_die
->tag
== DW_TAG_member
15153 || child_die
->tag
== DW_TAG_variable
15154 || child_die
->tag
== DW_TAG_variant_part
)
15156 /* NOTE: carlton/2002-11-05: A C++ static data member
15157 should be a DW_TAG_member that is a declaration, but
15158 all versions of G++ as of this writing (so through at
15159 least 3.2.1) incorrectly generate DW_TAG_variable
15160 tags for them instead. */
15161 dwarf2_add_field (fi
, child_die
, cu
);
15163 else if (child_die
->tag
== DW_TAG_subprogram
)
15165 /* Rust doesn't have member functions in the C++ sense.
15166 However, it does emit ordinary functions as children
15167 of a struct DIE. */
15168 if (cu
->language
== language_rust
)
15169 read_func_scope (child_die
, cu
);
15172 /* C++ member function. */
15173 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15176 else if (child_die
->tag
== DW_TAG_inheritance
)
15178 /* C++ base class field. */
15179 dwarf2_add_field (fi
, child_die
, cu
);
15181 else if (type_can_define_types (child_die
))
15182 dwarf2_add_type_defn (fi
, child_die
, cu
);
15183 else if (child_die
->tag
== DW_TAG_template_type_param
15184 || child_die
->tag
== DW_TAG_template_value_param
)
15186 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15189 template_args
->push_back (arg
);
15191 else if (child_die
->tag
== DW_TAG_variant
)
15193 /* In a variant we want to get the discriminant and also add a
15194 field for our sole member child. */
15195 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15197 for (die_info
*variant_child
= child_die
->child
;
15198 variant_child
!= NULL
;
15199 variant_child
= sibling_die (variant_child
))
15201 if (variant_child
->tag
== DW_TAG_member
)
15203 handle_struct_member_die (variant_child
, type
, fi
,
15204 template_args
, cu
);
15205 /* Only handle the one. */
15210 /* We don't handle this but we might as well report it if we see
15212 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15213 complaint (_("DW_AT_discr_list is not supported yet"
15214 " - DIE at %s [in module %s]"),
15215 sect_offset_str (child_die
->sect_off
),
15216 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15218 /* The first field was just added, so we can stash the
15219 discriminant there. */
15220 gdb_assert (!fi
->fields
.empty ());
15222 fi
->fields
.back ().variant
.default_branch
= true;
15224 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15228 /* Finish creating a structure or union type, including filling in
15229 its members and creating a symbol for it. */
15232 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15234 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15235 struct die_info
*child_die
;
15238 type
= get_die_type (die
, cu
);
15240 type
= read_structure_type (die
, cu
);
15242 /* When reading a DW_TAG_variant_part, we need to notice when we
15243 read the discriminant member, so we can record it later in the
15244 discriminant_info. */
15245 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15246 sect_offset discr_offset
{};
15247 bool has_template_parameters
= false;
15249 if (is_variant_part
)
15251 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15254 /* Maybe it's a univariant form, an extension we support.
15255 In this case arrange not to check the offset. */
15256 is_variant_part
= false;
15258 else if (discr
->form_is_ref ())
15260 struct dwarf2_cu
*target_cu
= cu
;
15261 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15263 discr_offset
= target_die
->sect_off
;
15267 complaint (_("DW_AT_discr does not have DIE reference form"
15268 " - DIE at %s [in module %s]"),
15269 sect_offset_str (die
->sect_off
),
15270 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15271 is_variant_part
= false;
15275 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15277 struct field_info fi
;
15278 std::vector
<struct symbol
*> template_args
;
15280 child_die
= die
->child
;
15282 while (child_die
&& child_die
->tag
)
15284 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15286 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15287 fi
.fields
.back ().variant
.is_discriminant
= true;
15289 child_die
= sibling_die (child_die
);
15292 /* Attach template arguments to type. */
15293 if (!template_args
.empty ())
15295 has_template_parameters
= true;
15296 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15297 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15298 TYPE_TEMPLATE_ARGUMENTS (type
)
15299 = XOBNEWVEC (&objfile
->objfile_obstack
,
15301 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15302 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15303 template_args
.data (),
15304 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15305 * sizeof (struct symbol
*)));
15308 /* Attach fields and member functions to the type. */
15310 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15311 if (!fi
.fnfieldlists
.empty ())
15313 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15315 /* Get the type which refers to the base class (possibly this
15316 class itself) which contains the vtable pointer for the current
15317 class from the DW_AT_containing_type attribute. This use of
15318 DW_AT_containing_type is a GNU extension. */
15320 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15322 struct type
*t
= die_containing_type (die
, cu
);
15324 set_type_vptr_basetype (type
, t
);
15329 /* Our own class provides vtbl ptr. */
15330 for (i
= TYPE_NFIELDS (t
) - 1;
15331 i
>= TYPE_N_BASECLASSES (t
);
15334 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15336 if (is_vtable_name (fieldname
, cu
))
15338 set_type_vptr_fieldno (type
, i
);
15343 /* Complain if virtual function table field not found. */
15344 if (i
< TYPE_N_BASECLASSES (t
))
15345 complaint (_("virtual function table pointer "
15346 "not found when defining class '%s'"),
15347 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15351 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15354 else if (cu
->producer
15355 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15357 /* The IBM XLC compiler does not provide direct indication
15358 of the containing type, but the vtable pointer is
15359 always named __vfp. */
15363 for (i
= TYPE_NFIELDS (type
) - 1;
15364 i
>= TYPE_N_BASECLASSES (type
);
15367 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15369 set_type_vptr_fieldno (type
, i
);
15370 set_type_vptr_basetype (type
, type
);
15377 /* Copy fi.typedef_field_list linked list elements content into the
15378 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15379 if (!fi
.typedef_field_list
.empty ())
15381 int count
= fi
.typedef_field_list
.size ();
15383 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15384 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15385 = ((struct decl_field
*)
15387 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15388 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15390 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15391 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15394 /* Copy fi.nested_types_list linked list elements content into the
15395 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15396 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15398 int count
= fi
.nested_types_list
.size ();
15400 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15401 TYPE_NESTED_TYPES_ARRAY (type
)
15402 = ((struct decl_field
*)
15403 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15404 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15406 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15407 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15411 quirk_gcc_member_function_pointer (type
, objfile
);
15412 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15413 cu
->rust_unions
.push_back (type
);
15415 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15416 snapshots) has been known to create a die giving a declaration
15417 for a class that has, as a child, a die giving a definition for a
15418 nested class. So we have to process our children even if the
15419 current die is a declaration. Normally, of course, a declaration
15420 won't have any children at all. */
15422 child_die
= die
->child
;
15424 while (child_die
!= NULL
&& child_die
->tag
)
15426 if (child_die
->tag
== DW_TAG_member
15427 || child_die
->tag
== DW_TAG_variable
15428 || child_die
->tag
== DW_TAG_inheritance
15429 || child_die
->tag
== DW_TAG_template_value_param
15430 || child_die
->tag
== DW_TAG_template_type_param
)
15435 process_die (child_die
, cu
);
15437 child_die
= sibling_die (child_die
);
15440 /* Do not consider external references. According to the DWARF standard,
15441 these DIEs are identified by the fact that they have no byte_size
15442 attribute, and a declaration attribute. */
15443 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15444 || !die_is_declaration (die
, cu
))
15446 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15448 if (has_template_parameters
)
15450 struct symtab
*symtab
;
15451 if (sym
!= nullptr)
15452 symtab
= symbol_symtab (sym
);
15453 else if (cu
->line_header
!= nullptr)
15455 /* Any related symtab will do. */
15457 = cu
->line_header
->file_names ()[0].symtab
;
15462 complaint (_("could not find suitable "
15463 "symtab for template parameter"
15464 " - DIE at %s [in module %s]"),
15465 sect_offset_str (die
->sect_off
),
15466 objfile_name (objfile
));
15469 if (symtab
!= nullptr)
15471 /* Make sure that the symtab is set on the new symbols.
15472 Even though they don't appear in this symtab directly,
15473 other parts of gdb assume that symbols do, and this is
15474 reasonably true. */
15475 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15476 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15482 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15483 update TYPE using some information only available in DIE's children. */
15486 update_enumeration_type_from_children (struct die_info
*die
,
15488 struct dwarf2_cu
*cu
)
15490 struct die_info
*child_die
;
15491 int unsigned_enum
= 1;
15495 auto_obstack obstack
;
15497 for (child_die
= die
->child
;
15498 child_die
!= NULL
&& child_die
->tag
;
15499 child_die
= sibling_die (child_die
))
15501 struct attribute
*attr
;
15503 const gdb_byte
*bytes
;
15504 struct dwarf2_locexpr_baton
*baton
;
15507 if (child_die
->tag
!= DW_TAG_enumerator
)
15510 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15514 name
= dwarf2_name (child_die
, cu
);
15516 name
= "<anonymous enumerator>";
15518 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15519 &value
, &bytes
, &baton
);
15525 else if ((mask
& value
) != 0)
15530 /* If we already know that the enum type is neither unsigned, nor
15531 a flag type, no need to look at the rest of the enumerates. */
15532 if (!unsigned_enum
&& !flag_enum
)
15537 TYPE_UNSIGNED (type
) = 1;
15539 TYPE_FLAG_ENUM (type
) = 1;
15542 /* Given a DW_AT_enumeration_type die, set its type. We do not
15543 complete the type's fields yet, or create any symbols. */
15545 static struct type
*
15546 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15548 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15550 struct attribute
*attr
;
15553 /* If the definition of this type lives in .debug_types, read that type.
15554 Don't follow DW_AT_specification though, that will take us back up
15555 the chain and we want to go down. */
15556 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15557 if (attr
!= nullptr)
15559 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15561 /* The type's CU may not be the same as CU.
15562 Ensure TYPE is recorded with CU in die_type_hash. */
15563 return set_die_type (die
, type
, cu
);
15566 type
= alloc_type (objfile
);
15568 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15569 name
= dwarf2_full_name (NULL
, die
, cu
);
15571 TYPE_NAME (type
) = name
;
15573 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15576 struct type
*underlying_type
= die_type (die
, cu
);
15578 TYPE_TARGET_TYPE (type
) = underlying_type
;
15581 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15582 if (attr
!= nullptr)
15584 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15588 TYPE_LENGTH (type
) = 0;
15591 maybe_set_alignment (cu
, die
, type
);
15593 /* The enumeration DIE can be incomplete. In Ada, any type can be
15594 declared as private in the package spec, and then defined only
15595 inside the package body. Such types are known as Taft Amendment
15596 Types. When another package uses such a type, an incomplete DIE
15597 may be generated by the compiler. */
15598 if (die_is_declaration (die
, cu
))
15599 TYPE_STUB (type
) = 1;
15601 /* Finish the creation of this type by using the enum's children.
15602 We must call this even when the underlying type has been provided
15603 so that we can determine if we're looking at a "flag" enum. */
15604 update_enumeration_type_from_children (die
, type
, cu
);
15606 /* If this type has an underlying type that is not a stub, then we
15607 may use its attributes. We always use the "unsigned" attribute
15608 in this situation, because ordinarily we guess whether the type
15609 is unsigned -- but the guess can be wrong and the underlying type
15610 can tell us the reality. However, we defer to a local size
15611 attribute if one exists, because this lets the compiler override
15612 the underlying type if needed. */
15613 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15615 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15616 if (TYPE_LENGTH (type
) == 0)
15617 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15618 if (TYPE_RAW_ALIGN (type
) == 0
15619 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15620 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15623 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15625 return set_die_type (die
, type
, cu
);
15628 /* Given a pointer to a die which begins an enumeration, process all
15629 the dies that define the members of the enumeration, and create the
15630 symbol for the enumeration type.
15632 NOTE: We reverse the order of the element list. */
15635 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15637 struct type
*this_type
;
15639 this_type
= get_die_type (die
, cu
);
15640 if (this_type
== NULL
)
15641 this_type
= read_enumeration_type (die
, cu
);
15643 if (die
->child
!= NULL
)
15645 struct die_info
*child_die
;
15646 struct symbol
*sym
;
15647 std::vector
<struct field
> fields
;
15650 child_die
= die
->child
;
15651 while (child_die
&& child_die
->tag
)
15653 if (child_die
->tag
!= DW_TAG_enumerator
)
15655 process_die (child_die
, cu
);
15659 name
= dwarf2_name (child_die
, cu
);
15662 sym
= new_symbol (child_die
, this_type
, cu
);
15664 fields
.emplace_back ();
15665 struct field
&field
= fields
.back ();
15667 FIELD_NAME (field
) = sym
->linkage_name ();
15668 FIELD_TYPE (field
) = NULL
;
15669 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15670 FIELD_BITSIZE (field
) = 0;
15674 child_die
= sibling_die (child_die
);
15677 if (!fields
.empty ())
15679 TYPE_NFIELDS (this_type
) = fields
.size ();
15680 TYPE_FIELDS (this_type
) = (struct field
*)
15681 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15682 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15683 sizeof (struct field
) * fields
.size ());
15687 /* If we are reading an enum from a .debug_types unit, and the enum
15688 is a declaration, and the enum is not the signatured type in the
15689 unit, then we do not want to add a symbol for it. Adding a
15690 symbol would in some cases obscure the true definition of the
15691 enum, giving users an incomplete type when the definition is
15692 actually available. Note that we do not want to do this for all
15693 enums which are just declarations, because C++0x allows forward
15694 enum declarations. */
15695 if (cu
->per_cu
->is_debug_types
15696 && die_is_declaration (die
, cu
))
15698 struct signatured_type
*sig_type
;
15700 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15701 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15702 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15706 new_symbol (die
, this_type
, cu
);
15709 /* Extract all information from a DW_TAG_array_type DIE and put it in
15710 the DIE's type field. For now, this only handles one dimensional
15713 static struct type
*
15714 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15716 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15717 struct die_info
*child_die
;
15719 struct type
*element_type
, *range_type
, *index_type
;
15720 struct attribute
*attr
;
15722 struct dynamic_prop
*byte_stride_prop
= NULL
;
15723 unsigned int bit_stride
= 0;
15725 element_type
= die_type (die
, cu
);
15727 /* The die_type call above may have already set the type for this DIE. */
15728 type
= get_die_type (die
, cu
);
15732 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15736 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15739 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15740 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15744 complaint (_("unable to read array DW_AT_byte_stride "
15745 " - DIE at %s [in module %s]"),
15746 sect_offset_str (die
->sect_off
),
15747 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15748 /* Ignore this attribute. We will likely not be able to print
15749 arrays of this type correctly, but there is little we can do
15750 to help if we cannot read the attribute's value. */
15751 byte_stride_prop
= NULL
;
15755 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15757 bit_stride
= DW_UNSND (attr
);
15759 /* Irix 6.2 native cc creates array types without children for
15760 arrays with unspecified length. */
15761 if (die
->child
== NULL
)
15763 index_type
= objfile_type (objfile
)->builtin_int
;
15764 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15765 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15766 byte_stride_prop
, bit_stride
);
15767 return set_die_type (die
, type
, cu
);
15770 std::vector
<struct type
*> range_types
;
15771 child_die
= die
->child
;
15772 while (child_die
&& child_die
->tag
)
15774 if (child_die
->tag
== DW_TAG_subrange_type
)
15776 struct type
*child_type
= read_type_die (child_die
, cu
);
15778 if (child_type
!= NULL
)
15780 /* The range type was succesfully read. Save it for the
15781 array type creation. */
15782 range_types
.push_back (child_type
);
15785 child_die
= sibling_die (child_die
);
15788 /* Dwarf2 dimensions are output from left to right, create the
15789 necessary array types in backwards order. */
15791 type
= element_type
;
15793 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15797 while (i
< range_types
.size ())
15798 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15799 byte_stride_prop
, bit_stride
);
15803 size_t ndim
= range_types
.size ();
15805 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15806 byte_stride_prop
, bit_stride
);
15809 /* Understand Dwarf2 support for vector types (like they occur on
15810 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15811 array type. This is not part of the Dwarf2/3 standard yet, but a
15812 custom vendor extension. The main difference between a regular
15813 array and the vector variant is that vectors are passed by value
15815 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15816 if (attr
!= nullptr)
15817 make_vector_type (type
);
15819 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15820 implementation may choose to implement triple vectors using this
15822 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15823 if (attr
!= nullptr)
15825 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15826 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15828 complaint (_("DW_AT_byte_size for array type smaller "
15829 "than the total size of elements"));
15832 name
= dwarf2_name (die
, cu
);
15834 TYPE_NAME (type
) = name
;
15836 maybe_set_alignment (cu
, die
, type
);
15838 /* Install the type in the die. */
15839 set_die_type (die
, type
, cu
);
15841 /* set_die_type should be already done. */
15842 set_descriptive_type (type
, die
, cu
);
15847 static enum dwarf_array_dim_ordering
15848 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15850 struct attribute
*attr
;
15852 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15854 if (attr
!= nullptr)
15855 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15857 /* GNU F77 is a special case, as at 08/2004 array type info is the
15858 opposite order to the dwarf2 specification, but data is still
15859 laid out as per normal fortran.
15861 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15862 version checking. */
15864 if (cu
->language
== language_fortran
15865 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15867 return DW_ORD_row_major
;
15870 switch (cu
->language_defn
->la_array_ordering
)
15872 case array_column_major
:
15873 return DW_ORD_col_major
;
15874 case array_row_major
:
15876 return DW_ORD_row_major
;
15880 /* Extract all information from a DW_TAG_set_type DIE and put it in
15881 the DIE's type field. */
15883 static struct type
*
15884 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15886 struct type
*domain_type
, *set_type
;
15887 struct attribute
*attr
;
15889 domain_type
= die_type (die
, cu
);
15891 /* The die_type call above may have already set the type for this DIE. */
15892 set_type
= get_die_type (die
, cu
);
15896 set_type
= create_set_type (NULL
, domain_type
);
15898 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15899 if (attr
!= nullptr)
15900 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15902 maybe_set_alignment (cu
, die
, set_type
);
15904 return set_die_type (die
, set_type
, cu
);
15907 /* A helper for read_common_block that creates a locexpr baton.
15908 SYM is the symbol which we are marking as computed.
15909 COMMON_DIE is the DIE for the common block.
15910 COMMON_LOC is the location expression attribute for the common
15912 MEMBER_LOC is the location expression attribute for the particular
15913 member of the common block that we are processing.
15914 CU is the CU from which the above come. */
15917 mark_common_block_symbol_computed (struct symbol
*sym
,
15918 struct die_info
*common_die
,
15919 struct attribute
*common_loc
,
15920 struct attribute
*member_loc
,
15921 struct dwarf2_cu
*cu
)
15923 struct dwarf2_per_objfile
*dwarf2_per_objfile
15924 = cu
->per_cu
->dwarf2_per_objfile
;
15925 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15926 struct dwarf2_locexpr_baton
*baton
;
15928 unsigned int cu_off
;
15929 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15930 LONGEST offset
= 0;
15932 gdb_assert (common_loc
&& member_loc
);
15933 gdb_assert (common_loc
->form_is_block ());
15934 gdb_assert (member_loc
->form_is_block ()
15935 || member_loc
->form_is_constant ());
15937 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15938 baton
->per_cu
= cu
->per_cu
;
15939 gdb_assert (baton
->per_cu
);
15941 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15943 if (member_loc
->form_is_constant ())
15945 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
15946 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15949 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15951 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15954 *ptr
++ = DW_OP_call4
;
15955 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15956 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15959 if (member_loc
->form_is_constant ())
15961 *ptr
++ = DW_OP_addr
;
15962 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15963 ptr
+= cu
->header
.addr_size
;
15967 /* We have to copy the data here, because DW_OP_call4 will only
15968 use a DW_AT_location attribute. */
15969 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15970 ptr
+= DW_BLOCK (member_loc
)->size
;
15973 *ptr
++ = DW_OP_plus
;
15974 gdb_assert (ptr
- baton
->data
== baton
->size
);
15976 SYMBOL_LOCATION_BATON (sym
) = baton
;
15977 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15980 /* Create appropriate locally-scoped variables for all the
15981 DW_TAG_common_block entries. Also create a struct common_block
15982 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15983 is used to separate the common blocks name namespace from regular
15987 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15989 struct attribute
*attr
;
15991 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15992 if (attr
!= nullptr)
15994 /* Support the .debug_loc offsets. */
15995 if (attr
->form_is_block ())
15999 else if (attr
->form_is_section_offset ())
16001 dwarf2_complex_location_expr_complaint ();
16006 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16007 "common block member");
16012 if (die
->child
!= NULL
)
16014 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16015 struct die_info
*child_die
;
16016 size_t n_entries
= 0, size
;
16017 struct common_block
*common_block
;
16018 struct symbol
*sym
;
16020 for (child_die
= die
->child
;
16021 child_die
&& child_die
->tag
;
16022 child_die
= sibling_die (child_die
))
16025 size
= (sizeof (struct common_block
)
16026 + (n_entries
- 1) * sizeof (struct symbol
*));
16028 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16030 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16031 common_block
->n_entries
= 0;
16033 for (child_die
= die
->child
;
16034 child_die
&& child_die
->tag
;
16035 child_die
= sibling_die (child_die
))
16037 /* Create the symbol in the DW_TAG_common_block block in the current
16039 sym
= new_symbol (child_die
, NULL
, cu
);
16042 struct attribute
*member_loc
;
16044 common_block
->contents
[common_block
->n_entries
++] = sym
;
16046 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16050 /* GDB has handled this for a long time, but it is
16051 not specified by DWARF. It seems to have been
16052 emitted by gfortran at least as recently as:
16053 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16054 complaint (_("Variable in common block has "
16055 "DW_AT_data_member_location "
16056 "- DIE at %s [in module %s]"),
16057 sect_offset_str (child_die
->sect_off
),
16058 objfile_name (objfile
));
16060 if (member_loc
->form_is_section_offset ())
16061 dwarf2_complex_location_expr_complaint ();
16062 else if (member_loc
->form_is_constant ()
16063 || member_loc
->form_is_block ())
16065 if (attr
!= nullptr)
16066 mark_common_block_symbol_computed (sym
, die
, attr
,
16070 dwarf2_complex_location_expr_complaint ();
16075 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16076 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16080 /* Create a type for a C++ namespace. */
16082 static struct type
*
16083 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16085 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16086 const char *previous_prefix
, *name
;
16090 /* For extensions, reuse the type of the original namespace. */
16091 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16093 struct die_info
*ext_die
;
16094 struct dwarf2_cu
*ext_cu
= cu
;
16096 ext_die
= dwarf2_extension (die
, &ext_cu
);
16097 type
= read_type_die (ext_die
, ext_cu
);
16099 /* EXT_CU may not be the same as CU.
16100 Ensure TYPE is recorded with CU in die_type_hash. */
16101 return set_die_type (die
, type
, cu
);
16104 name
= namespace_name (die
, &is_anonymous
, cu
);
16106 /* Now build the name of the current namespace. */
16108 previous_prefix
= determine_prefix (die
, cu
);
16109 if (previous_prefix
[0] != '\0')
16110 name
= typename_concat (&objfile
->objfile_obstack
,
16111 previous_prefix
, name
, 0, cu
);
16113 /* Create the type. */
16114 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16116 return set_die_type (die
, type
, cu
);
16119 /* Read a namespace scope. */
16122 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16124 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16127 /* Add a symbol associated to this if we haven't seen the namespace
16128 before. Also, add a using directive if it's an anonymous
16131 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16135 type
= read_type_die (die
, cu
);
16136 new_symbol (die
, type
, cu
);
16138 namespace_name (die
, &is_anonymous
, cu
);
16141 const char *previous_prefix
= determine_prefix (die
, cu
);
16143 std::vector
<const char *> excludes
;
16144 add_using_directive (using_directives (cu
),
16145 previous_prefix
, TYPE_NAME (type
), NULL
,
16146 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16150 if (die
->child
!= NULL
)
16152 struct die_info
*child_die
= die
->child
;
16154 while (child_die
&& child_die
->tag
)
16156 process_die (child_die
, cu
);
16157 child_die
= sibling_die (child_die
);
16162 /* Read a Fortran module as type. This DIE can be only a declaration used for
16163 imported module. Still we need that type as local Fortran "use ... only"
16164 declaration imports depend on the created type in determine_prefix. */
16166 static struct type
*
16167 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16169 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16170 const char *module_name
;
16173 module_name
= dwarf2_name (die
, cu
);
16174 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16176 return set_die_type (die
, type
, cu
);
16179 /* Read a Fortran module. */
16182 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16184 struct die_info
*child_die
= die
->child
;
16187 type
= read_type_die (die
, cu
);
16188 new_symbol (die
, type
, cu
);
16190 while (child_die
&& child_die
->tag
)
16192 process_die (child_die
, cu
);
16193 child_die
= sibling_die (child_die
);
16197 /* Return the name of the namespace represented by DIE. Set
16198 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16201 static const char *
16202 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16204 struct die_info
*current_die
;
16205 const char *name
= NULL
;
16207 /* Loop through the extensions until we find a name. */
16209 for (current_die
= die
;
16210 current_die
!= NULL
;
16211 current_die
= dwarf2_extension (die
, &cu
))
16213 /* We don't use dwarf2_name here so that we can detect the absence
16214 of a name -> anonymous namespace. */
16215 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16221 /* Is it an anonymous namespace? */
16223 *is_anonymous
= (name
== NULL
);
16225 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16230 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16231 the user defined type vector. */
16233 static struct type
*
16234 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16236 struct gdbarch
*gdbarch
16237 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16238 struct comp_unit_head
*cu_header
= &cu
->header
;
16240 struct attribute
*attr_byte_size
;
16241 struct attribute
*attr_address_class
;
16242 int byte_size
, addr_class
;
16243 struct type
*target_type
;
16245 target_type
= die_type (die
, cu
);
16247 /* The die_type call above may have already set the type for this DIE. */
16248 type
= get_die_type (die
, cu
);
16252 type
= lookup_pointer_type (target_type
);
16254 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16255 if (attr_byte_size
)
16256 byte_size
= DW_UNSND (attr_byte_size
);
16258 byte_size
= cu_header
->addr_size
;
16260 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16261 if (attr_address_class
)
16262 addr_class
= DW_UNSND (attr_address_class
);
16264 addr_class
= DW_ADDR_none
;
16266 ULONGEST alignment
= get_alignment (cu
, die
);
16268 /* If the pointer size, alignment, or address class is different
16269 than the default, create a type variant marked as such and set
16270 the length accordingly. */
16271 if (TYPE_LENGTH (type
) != byte_size
16272 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16273 && alignment
!= TYPE_RAW_ALIGN (type
))
16274 || addr_class
!= DW_ADDR_none
)
16276 if (gdbarch_address_class_type_flags_p (gdbarch
))
16280 type_flags
= gdbarch_address_class_type_flags
16281 (gdbarch
, byte_size
, addr_class
);
16282 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16284 type
= make_type_with_address_space (type
, type_flags
);
16286 else if (TYPE_LENGTH (type
) != byte_size
)
16288 complaint (_("invalid pointer size %d"), byte_size
);
16290 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16292 complaint (_("Invalid DW_AT_alignment"
16293 " - DIE at %s [in module %s]"),
16294 sect_offset_str (die
->sect_off
),
16295 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16299 /* Should we also complain about unhandled address classes? */
16303 TYPE_LENGTH (type
) = byte_size
;
16304 set_type_align (type
, alignment
);
16305 return set_die_type (die
, type
, cu
);
16308 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16309 the user defined type vector. */
16311 static struct type
*
16312 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16315 struct type
*to_type
;
16316 struct type
*domain
;
16318 to_type
= die_type (die
, cu
);
16319 domain
= die_containing_type (die
, cu
);
16321 /* The calls above may have already set the type for this DIE. */
16322 type
= get_die_type (die
, cu
);
16326 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16327 type
= lookup_methodptr_type (to_type
);
16328 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16330 struct type
*new_type
16331 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16333 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16334 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16335 TYPE_VARARGS (to_type
));
16336 type
= lookup_methodptr_type (new_type
);
16339 type
= lookup_memberptr_type (to_type
, domain
);
16341 return set_die_type (die
, type
, cu
);
16344 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16345 the user defined type vector. */
16347 static struct type
*
16348 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16349 enum type_code refcode
)
16351 struct comp_unit_head
*cu_header
= &cu
->header
;
16352 struct type
*type
, *target_type
;
16353 struct attribute
*attr
;
16355 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16357 target_type
= die_type (die
, cu
);
16359 /* The die_type call above may have already set the type for this DIE. */
16360 type
= get_die_type (die
, cu
);
16364 type
= lookup_reference_type (target_type
, refcode
);
16365 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16366 if (attr
!= nullptr)
16368 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16372 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16374 maybe_set_alignment (cu
, die
, type
);
16375 return set_die_type (die
, type
, cu
);
16378 /* Add the given cv-qualifiers to the element type of the array. GCC
16379 outputs DWARF type qualifiers that apply to an array, not the
16380 element type. But GDB relies on the array element type to carry
16381 the cv-qualifiers. This mimics section 6.7.3 of the C99
16384 static struct type
*
16385 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16386 struct type
*base_type
, int cnst
, int voltl
)
16388 struct type
*el_type
, *inner_array
;
16390 base_type
= copy_type (base_type
);
16391 inner_array
= base_type
;
16393 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16395 TYPE_TARGET_TYPE (inner_array
) =
16396 copy_type (TYPE_TARGET_TYPE (inner_array
));
16397 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16400 el_type
= TYPE_TARGET_TYPE (inner_array
);
16401 cnst
|= TYPE_CONST (el_type
);
16402 voltl
|= TYPE_VOLATILE (el_type
);
16403 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16405 return set_die_type (die
, base_type
, cu
);
16408 static struct type
*
16409 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16411 struct type
*base_type
, *cv_type
;
16413 base_type
= die_type (die
, cu
);
16415 /* The die_type call above may have already set the type for this DIE. */
16416 cv_type
= get_die_type (die
, cu
);
16420 /* In case the const qualifier is applied to an array type, the element type
16421 is so qualified, not the array type (section 6.7.3 of C99). */
16422 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16423 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16425 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16426 return set_die_type (die
, cv_type
, cu
);
16429 static struct type
*
16430 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16432 struct type
*base_type
, *cv_type
;
16434 base_type
= die_type (die
, cu
);
16436 /* The die_type call above may have already set the type for this DIE. */
16437 cv_type
= get_die_type (die
, cu
);
16441 /* In case the volatile qualifier is applied to an array type, the
16442 element type is so qualified, not the array type (section 6.7.3
16444 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16445 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16447 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16448 return set_die_type (die
, cv_type
, cu
);
16451 /* Handle DW_TAG_restrict_type. */
16453 static struct type
*
16454 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16456 struct type
*base_type
, *cv_type
;
16458 base_type
= die_type (die
, cu
);
16460 /* The die_type call above may have already set the type for this DIE. */
16461 cv_type
= get_die_type (die
, cu
);
16465 cv_type
= make_restrict_type (base_type
);
16466 return set_die_type (die
, cv_type
, cu
);
16469 /* Handle DW_TAG_atomic_type. */
16471 static struct type
*
16472 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16474 struct type
*base_type
, *cv_type
;
16476 base_type
= die_type (die
, cu
);
16478 /* The die_type call above may have already set the type for this DIE. */
16479 cv_type
= get_die_type (die
, cu
);
16483 cv_type
= make_atomic_type (base_type
);
16484 return set_die_type (die
, cv_type
, cu
);
16487 /* Extract all information from a DW_TAG_string_type DIE and add to
16488 the user defined type vector. It isn't really a user defined type,
16489 but it behaves like one, with other DIE's using an AT_user_def_type
16490 attribute to reference it. */
16492 static struct type
*
16493 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16495 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16496 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16497 struct type
*type
, *range_type
, *index_type
, *char_type
;
16498 struct attribute
*attr
;
16499 struct dynamic_prop prop
;
16500 bool length_is_constant
= true;
16503 /* There are a couple of places where bit sizes might be made use of
16504 when parsing a DW_TAG_string_type, however, no producer that we know
16505 of make use of these. Handling bit sizes that are a multiple of the
16506 byte size is easy enough, but what about other bit sizes? Lets deal
16507 with that problem when we have to. Warn about these attributes being
16508 unsupported, then parse the type and ignore them like we always
16510 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16511 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16513 static bool warning_printed
= false;
16514 if (!warning_printed
)
16516 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16517 "currently supported on DW_TAG_string_type."));
16518 warning_printed
= true;
16522 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16523 if (attr
!= nullptr && !attr
->form_is_constant ())
16525 /* The string length describes the location at which the length of
16526 the string can be found. The size of the length field can be
16527 specified with one of the attributes below. */
16528 struct type
*prop_type
;
16529 struct attribute
*len
16530 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16531 if (len
== nullptr)
16532 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16533 if (len
!= nullptr && len
->form_is_constant ())
16535 /* Pass 0 as the default as we know this attribute is constant
16536 and the default value will not be returned. */
16537 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
16538 prop_type
= cu
->per_cu
->int_type (sz
, true);
16542 /* If the size is not specified then we assume it is the size of
16543 an address on this target. */
16544 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16547 /* Convert the attribute into a dynamic property. */
16548 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16551 length_is_constant
= false;
16553 else if (attr
!= nullptr)
16555 /* This DW_AT_string_length just contains the length with no
16556 indirection. There's no need to create a dynamic property in this
16557 case. Pass 0 for the default value as we know it will not be
16558 returned in this case. */
16559 length
= dwarf2_get_attr_constant_value (attr
, 0);
16561 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16563 /* We don't currently support non-constant byte sizes for strings. */
16564 length
= dwarf2_get_attr_constant_value (attr
, 1);
16568 /* Use 1 as a fallback length if we have nothing else. */
16572 index_type
= objfile_type (objfile
)->builtin_int
;
16573 if (length_is_constant
)
16574 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16577 struct dynamic_prop low_bound
;
16579 low_bound
.kind
= PROP_CONST
;
16580 low_bound
.data
.const_val
= 1;
16581 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16583 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16584 type
= create_string_type (NULL
, char_type
, range_type
);
16586 return set_die_type (die
, type
, cu
);
16589 /* Assuming that DIE corresponds to a function, returns nonzero
16590 if the function is prototyped. */
16593 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16595 struct attribute
*attr
;
16597 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16598 if (attr
&& (DW_UNSND (attr
) != 0))
16601 /* The DWARF standard implies that the DW_AT_prototyped attribute
16602 is only meaningful for C, but the concept also extends to other
16603 languages that allow unprototyped functions (Eg: Objective C).
16604 For all other languages, assume that functions are always
16606 if (cu
->language
!= language_c
16607 && cu
->language
!= language_objc
16608 && cu
->language
!= language_opencl
)
16611 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16612 prototyped and unprototyped functions; default to prototyped,
16613 since that is more common in modern code (and RealView warns
16614 about unprototyped functions). */
16615 if (producer_is_realview (cu
->producer
))
16621 /* Handle DIES due to C code like:
16625 int (*funcp)(int a, long l);
16629 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16631 static struct type
*
16632 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16634 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16635 struct type
*type
; /* Type that this function returns. */
16636 struct type
*ftype
; /* Function that returns above type. */
16637 struct attribute
*attr
;
16639 type
= die_type (die
, cu
);
16641 /* The die_type call above may have already set the type for this DIE. */
16642 ftype
= get_die_type (die
, cu
);
16646 ftype
= lookup_function_type (type
);
16648 if (prototyped_function_p (die
, cu
))
16649 TYPE_PROTOTYPED (ftype
) = 1;
16651 /* Store the calling convention in the type if it's available in
16652 the subroutine die. Otherwise set the calling convention to
16653 the default value DW_CC_normal. */
16654 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16655 if (attr
!= nullptr
16656 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16657 TYPE_CALLING_CONVENTION (ftype
)
16658 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16659 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16660 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16662 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16664 /* Record whether the function returns normally to its caller or not
16665 if the DWARF producer set that information. */
16666 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16667 if (attr
&& (DW_UNSND (attr
) != 0))
16668 TYPE_NO_RETURN (ftype
) = 1;
16670 /* We need to add the subroutine type to the die immediately so
16671 we don't infinitely recurse when dealing with parameters
16672 declared as the same subroutine type. */
16673 set_die_type (die
, ftype
, cu
);
16675 if (die
->child
!= NULL
)
16677 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16678 struct die_info
*child_die
;
16679 int nparams
, iparams
;
16681 /* Count the number of parameters.
16682 FIXME: GDB currently ignores vararg functions, but knows about
16683 vararg member functions. */
16685 child_die
= die
->child
;
16686 while (child_die
&& child_die
->tag
)
16688 if (child_die
->tag
== DW_TAG_formal_parameter
)
16690 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16691 TYPE_VARARGS (ftype
) = 1;
16692 child_die
= sibling_die (child_die
);
16695 /* Allocate storage for parameters and fill them in. */
16696 TYPE_NFIELDS (ftype
) = nparams
;
16697 TYPE_FIELDS (ftype
) = (struct field
*)
16698 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16700 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16701 even if we error out during the parameters reading below. */
16702 for (iparams
= 0; iparams
< nparams
; iparams
++)
16703 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16706 child_die
= die
->child
;
16707 while (child_die
&& child_die
->tag
)
16709 if (child_die
->tag
== DW_TAG_formal_parameter
)
16711 struct type
*arg_type
;
16713 /* DWARF version 2 has no clean way to discern C++
16714 static and non-static member functions. G++ helps
16715 GDB by marking the first parameter for non-static
16716 member functions (which is the this pointer) as
16717 artificial. We pass this information to
16718 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16720 DWARF version 3 added DW_AT_object_pointer, which GCC
16721 4.5 does not yet generate. */
16722 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16723 if (attr
!= nullptr)
16724 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16726 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16727 arg_type
= die_type (child_die
, cu
);
16729 /* RealView does not mark THIS as const, which the testsuite
16730 expects. GCC marks THIS as const in method definitions,
16731 but not in the class specifications (GCC PR 43053). */
16732 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16733 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16736 struct dwarf2_cu
*arg_cu
= cu
;
16737 const char *name
= dwarf2_name (child_die
, cu
);
16739 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16740 if (attr
!= nullptr)
16742 /* If the compiler emits this, use it. */
16743 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16746 else if (name
&& strcmp (name
, "this") == 0)
16747 /* Function definitions will have the argument names. */
16749 else if (name
== NULL
&& iparams
== 0)
16750 /* Declarations may not have the names, so like
16751 elsewhere in GDB, assume an artificial first
16752 argument is "this". */
16756 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16760 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16763 child_die
= sibling_die (child_die
);
16770 static struct type
*
16771 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16773 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16774 const char *name
= NULL
;
16775 struct type
*this_type
, *target_type
;
16777 name
= dwarf2_full_name (NULL
, die
, cu
);
16778 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16779 TYPE_TARGET_STUB (this_type
) = 1;
16780 set_die_type (die
, this_type
, cu
);
16781 target_type
= die_type (die
, cu
);
16782 if (target_type
!= this_type
)
16783 TYPE_TARGET_TYPE (this_type
) = target_type
;
16786 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16787 spec and cause infinite loops in GDB. */
16788 complaint (_("Self-referential DW_TAG_typedef "
16789 "- DIE at %s [in module %s]"),
16790 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16791 TYPE_TARGET_TYPE (this_type
) = NULL
;
16796 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16797 (which may be different from NAME) to the architecture back-end to allow
16798 it to guess the correct format if necessary. */
16800 static struct type
*
16801 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16802 const char *name_hint
, enum bfd_endian byte_order
)
16804 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16805 const struct floatformat
**format
;
16808 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16810 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16812 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16817 /* Allocate an integer type of size BITS and name NAME. */
16819 static struct type
*
16820 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16821 int bits
, int unsigned_p
, const char *name
)
16825 /* Versions of Intel's C Compiler generate an integer type called "void"
16826 instead of using DW_TAG_unspecified_type. This has been seen on
16827 at least versions 14, 17, and 18. */
16828 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16829 && strcmp (name
, "void") == 0)
16830 type
= objfile_type (objfile
)->builtin_void
;
16832 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16837 /* Initialise and return a floating point type of size BITS suitable for
16838 use as a component of a complex number. The NAME_HINT is passed through
16839 when initialising the floating point type and is the name of the complex
16842 As DWARF doesn't currently provide an explicit name for the components
16843 of a complex number, but it can be helpful to have these components
16844 named, we try to select a suitable name based on the size of the
16846 static struct type
*
16847 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16848 struct objfile
*objfile
,
16849 int bits
, const char *name_hint
,
16850 enum bfd_endian byte_order
)
16852 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16853 struct type
*tt
= nullptr;
16855 /* Try to find a suitable floating point builtin type of size BITS.
16856 We're going to use the name of this type as the name for the complex
16857 target type that we are about to create. */
16858 switch (cu
->language
)
16860 case language_fortran
:
16864 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16867 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16869 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16871 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16879 tt
= builtin_type (gdbarch
)->builtin_float
;
16882 tt
= builtin_type (gdbarch
)->builtin_double
;
16884 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16886 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16892 /* If the type we found doesn't match the size we were looking for, then
16893 pretend we didn't find a type at all, the complex target type we
16894 create will then be nameless. */
16895 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16898 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16899 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16902 /* Find a representation of a given base type and install
16903 it in the TYPE field of the die. */
16905 static struct type
*
16906 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16908 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16910 struct attribute
*attr
;
16911 int encoding
= 0, bits
= 0;
16915 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16916 if (attr
!= nullptr)
16917 encoding
= DW_UNSND (attr
);
16918 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16919 if (attr
!= nullptr)
16920 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16921 name
= dwarf2_name (die
, cu
);
16923 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16925 arch
= get_objfile_arch (objfile
);
16926 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16928 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16931 int endianity
= DW_UNSND (attr
);
16936 byte_order
= BFD_ENDIAN_BIG
;
16938 case DW_END_little
:
16939 byte_order
= BFD_ENDIAN_LITTLE
;
16942 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16949 case DW_ATE_address
:
16950 /* Turn DW_ATE_address into a void * pointer. */
16951 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16952 type
= init_pointer_type (objfile
, bits
, name
, type
);
16954 case DW_ATE_boolean
:
16955 type
= init_boolean_type (objfile
, bits
, 1, name
);
16957 case DW_ATE_complex_float
:
16958 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16960 type
= init_complex_type (objfile
, name
, type
);
16962 case DW_ATE_decimal_float
:
16963 type
= init_decfloat_type (objfile
, bits
, name
);
16966 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16968 case DW_ATE_signed
:
16969 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16971 case DW_ATE_unsigned
:
16972 if (cu
->language
== language_fortran
16974 && startswith (name
, "character("))
16975 type
= init_character_type (objfile
, bits
, 1, name
);
16977 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16979 case DW_ATE_signed_char
:
16980 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16981 || cu
->language
== language_pascal
16982 || cu
->language
== language_fortran
)
16983 type
= init_character_type (objfile
, bits
, 0, name
);
16985 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16987 case DW_ATE_unsigned_char
:
16988 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16989 || cu
->language
== language_pascal
16990 || cu
->language
== language_fortran
16991 || cu
->language
== language_rust
)
16992 type
= init_character_type (objfile
, bits
, 1, name
);
16994 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16999 type
= builtin_type (arch
)->builtin_char16
;
17000 else if (bits
== 32)
17001 type
= builtin_type (arch
)->builtin_char32
;
17004 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17006 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17008 return set_die_type (die
, type
, cu
);
17013 complaint (_("unsupported DW_AT_encoding: '%s'"),
17014 dwarf_type_encoding_name (encoding
));
17015 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17019 if (name
&& strcmp (name
, "char") == 0)
17020 TYPE_NOSIGN (type
) = 1;
17022 maybe_set_alignment (cu
, die
, type
);
17024 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17026 return set_die_type (die
, type
, cu
);
17029 /* Parse dwarf attribute if it's a block, reference or constant and put the
17030 resulting value of the attribute into struct bound_prop.
17031 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17034 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17035 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17036 struct type
*default_type
)
17038 struct dwarf2_property_baton
*baton
;
17039 struct obstack
*obstack
17040 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17042 gdb_assert (default_type
!= NULL
);
17044 if (attr
== NULL
|| prop
== NULL
)
17047 if (attr
->form_is_block ())
17049 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17050 baton
->property_type
= default_type
;
17051 baton
->locexpr
.per_cu
= cu
->per_cu
;
17052 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17053 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17054 switch (attr
->name
)
17056 case DW_AT_string_length
:
17057 baton
->locexpr
.is_reference
= true;
17060 baton
->locexpr
.is_reference
= false;
17063 prop
->data
.baton
= baton
;
17064 prop
->kind
= PROP_LOCEXPR
;
17065 gdb_assert (prop
->data
.baton
!= NULL
);
17067 else if (attr
->form_is_ref ())
17069 struct dwarf2_cu
*target_cu
= cu
;
17070 struct die_info
*target_die
;
17071 struct attribute
*target_attr
;
17073 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17074 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17075 if (target_attr
== NULL
)
17076 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17078 if (target_attr
== NULL
)
17081 switch (target_attr
->name
)
17083 case DW_AT_location
:
17084 if (target_attr
->form_is_section_offset ())
17086 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17087 baton
->property_type
= die_type (target_die
, target_cu
);
17088 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17089 prop
->data
.baton
= baton
;
17090 prop
->kind
= PROP_LOCLIST
;
17091 gdb_assert (prop
->data
.baton
!= NULL
);
17093 else if (target_attr
->form_is_block ())
17095 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17096 baton
->property_type
= die_type (target_die
, target_cu
);
17097 baton
->locexpr
.per_cu
= cu
->per_cu
;
17098 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17099 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17100 baton
->locexpr
.is_reference
= true;
17101 prop
->data
.baton
= baton
;
17102 prop
->kind
= PROP_LOCEXPR
;
17103 gdb_assert (prop
->data
.baton
!= NULL
);
17107 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17108 "dynamic property");
17112 case DW_AT_data_member_location
:
17116 if (!handle_data_member_location (target_die
, target_cu
,
17120 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17121 baton
->property_type
= read_type_die (target_die
->parent
,
17123 baton
->offset_info
.offset
= offset
;
17124 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17125 prop
->data
.baton
= baton
;
17126 prop
->kind
= PROP_ADDR_OFFSET
;
17131 else if (attr
->form_is_constant ())
17133 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17134 prop
->kind
= PROP_CONST
;
17138 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17139 dwarf2_name (die
, cu
));
17149 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17151 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17152 struct type
*int_type
;
17154 /* Helper macro to examine the various builtin types. */
17155 #define TRY_TYPE(F) \
17156 int_type = (unsigned_p \
17157 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17158 : objfile_type (objfile)->builtin_ ## F); \
17159 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17166 TRY_TYPE (long_long
);
17170 gdb_assert_not_reached ("unable to find suitable integer type");
17176 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17178 int addr_size
= this->addr_size ();
17179 return int_type (addr_size
, unsigned_p
);
17182 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17183 present (which is valid) then compute the default type based on the
17184 compilation units address size. */
17186 static struct type
*
17187 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17189 struct type
*index_type
= die_type (die
, cu
);
17191 /* Dwarf-2 specifications explicitly allows to create subrange types
17192 without specifying a base type.
17193 In that case, the base type must be set to the type of
17194 the lower bound, upper bound or count, in that order, if any of these
17195 three attributes references an object that has a type.
17196 If no base type is found, the Dwarf-2 specifications say that
17197 a signed integer type of size equal to the size of an address should
17199 For the following C code: `extern char gdb_int [];'
17200 GCC produces an empty range DIE.
17201 FIXME: muller/2010-05-28: Possible references to object for low bound,
17202 high bound or count are not yet handled by this code. */
17203 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17204 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17209 /* Read the given DW_AT_subrange DIE. */
17211 static struct type
*
17212 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17214 struct type
*base_type
, *orig_base_type
;
17215 struct type
*range_type
;
17216 struct attribute
*attr
;
17217 struct dynamic_prop low
, high
;
17218 int low_default_is_valid
;
17219 int high_bound_is_count
= 0;
17221 ULONGEST negative_mask
;
17223 orig_base_type
= read_subrange_index_type (die
, cu
);
17225 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17226 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17227 creating the range type, but we use the result of check_typedef
17228 when examining properties of the type. */
17229 base_type
= check_typedef (orig_base_type
);
17231 /* The die_type call above may have already set the type for this DIE. */
17232 range_type
= get_die_type (die
, cu
);
17236 low
.kind
= PROP_CONST
;
17237 high
.kind
= PROP_CONST
;
17238 high
.data
.const_val
= 0;
17240 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17241 omitting DW_AT_lower_bound. */
17242 switch (cu
->language
)
17245 case language_cplus
:
17246 low
.data
.const_val
= 0;
17247 low_default_is_valid
= 1;
17249 case language_fortran
:
17250 low
.data
.const_val
= 1;
17251 low_default_is_valid
= 1;
17254 case language_objc
:
17255 case language_rust
:
17256 low
.data
.const_val
= 0;
17257 low_default_is_valid
= (cu
->header
.version
>= 4);
17261 case language_pascal
:
17262 low
.data
.const_val
= 1;
17263 low_default_is_valid
= (cu
->header
.version
>= 4);
17266 low
.data
.const_val
= 0;
17267 low_default_is_valid
= 0;
17271 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17272 if (attr
!= nullptr)
17273 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17274 else if (!low_default_is_valid
)
17275 complaint (_("Missing DW_AT_lower_bound "
17276 "- DIE at %s [in module %s]"),
17277 sect_offset_str (die
->sect_off
),
17278 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17280 struct attribute
*attr_ub
, *attr_count
;
17281 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17282 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17284 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17285 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17287 /* If bounds are constant do the final calculation here. */
17288 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17289 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17291 high_bound_is_count
= 1;
17295 if (attr_ub
!= NULL
)
17296 complaint (_("Unresolved DW_AT_upper_bound "
17297 "- DIE at %s [in module %s]"),
17298 sect_offset_str (die
->sect_off
),
17299 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17300 if (attr_count
!= NULL
)
17301 complaint (_("Unresolved DW_AT_count "
17302 "- DIE at %s [in module %s]"),
17303 sect_offset_str (die
->sect_off
),
17304 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17309 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17310 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17311 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17313 /* Normally, the DWARF producers are expected to use a signed
17314 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17315 But this is unfortunately not always the case, as witnessed
17316 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17317 is used instead. To work around that ambiguity, we treat
17318 the bounds as signed, and thus sign-extend their values, when
17319 the base type is signed. */
17321 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17322 if (low
.kind
== PROP_CONST
17323 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17324 low
.data
.const_val
|= negative_mask
;
17325 if (high
.kind
== PROP_CONST
17326 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17327 high
.data
.const_val
|= negative_mask
;
17329 /* Check for bit and byte strides. */
17330 struct dynamic_prop byte_stride_prop
;
17331 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17332 if (attr_byte_stride
!= nullptr)
17334 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17335 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17339 struct dynamic_prop bit_stride_prop
;
17340 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17341 if (attr_bit_stride
!= nullptr)
17343 /* It only makes sense to have either a bit or byte stride. */
17344 if (attr_byte_stride
!= nullptr)
17346 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17347 "- DIE at %s [in module %s]"),
17348 sect_offset_str (die
->sect_off
),
17349 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17350 attr_bit_stride
= nullptr;
17354 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17355 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17360 if (attr_byte_stride
!= nullptr
17361 || attr_bit_stride
!= nullptr)
17363 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17364 struct dynamic_prop
*stride
17365 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17368 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17369 &high
, bias
, stride
, byte_stride_p
);
17372 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17374 if (high_bound_is_count
)
17375 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17377 /* Ada expects an empty array on no boundary attributes. */
17378 if (attr
== NULL
&& cu
->language
!= language_ada
)
17379 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17381 name
= dwarf2_name (die
, cu
);
17383 TYPE_NAME (range_type
) = name
;
17385 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17386 if (attr
!= nullptr)
17387 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17389 maybe_set_alignment (cu
, die
, range_type
);
17391 set_die_type (die
, range_type
, cu
);
17393 /* set_die_type should be already done. */
17394 set_descriptive_type (range_type
, die
, cu
);
17399 static struct type
*
17400 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17404 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17406 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17408 /* In Ada, an unspecified type is typically used when the description
17409 of the type is deferred to a different unit. When encountering
17410 such a type, we treat it as a stub, and try to resolve it later on,
17412 if (cu
->language
== language_ada
)
17413 TYPE_STUB (type
) = 1;
17415 return set_die_type (die
, type
, cu
);
17418 /* Read a single die and all its descendents. Set the die's sibling
17419 field to NULL; set other fields in the die correctly, and set all
17420 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17421 location of the info_ptr after reading all of those dies. PARENT
17422 is the parent of the die in question. */
17424 static struct die_info
*
17425 read_die_and_children (const struct die_reader_specs
*reader
,
17426 const gdb_byte
*info_ptr
,
17427 const gdb_byte
**new_info_ptr
,
17428 struct die_info
*parent
)
17430 struct die_info
*die
;
17431 const gdb_byte
*cur_ptr
;
17433 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17436 *new_info_ptr
= cur_ptr
;
17439 store_in_ref_table (die
, reader
->cu
);
17441 if (die
->has_children
)
17442 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17446 *new_info_ptr
= cur_ptr
;
17449 die
->sibling
= NULL
;
17450 die
->parent
= parent
;
17454 /* Read a die, all of its descendents, and all of its siblings; set
17455 all of the fields of all of the dies correctly. Arguments are as
17456 in read_die_and_children. */
17458 static struct die_info
*
17459 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17460 const gdb_byte
*info_ptr
,
17461 const gdb_byte
**new_info_ptr
,
17462 struct die_info
*parent
)
17464 struct die_info
*first_die
, *last_sibling
;
17465 const gdb_byte
*cur_ptr
;
17467 cur_ptr
= info_ptr
;
17468 first_die
= last_sibling
= NULL
;
17472 struct die_info
*die
17473 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17477 *new_info_ptr
= cur_ptr
;
17484 last_sibling
->sibling
= die
;
17486 last_sibling
= die
;
17490 /* Read a die, all of its descendents, and all of its siblings; set
17491 all of the fields of all of the dies correctly. Arguments are as
17492 in read_die_and_children.
17493 This the main entry point for reading a DIE and all its children. */
17495 static struct die_info
*
17496 read_die_and_siblings (const struct die_reader_specs
*reader
,
17497 const gdb_byte
*info_ptr
,
17498 const gdb_byte
**new_info_ptr
,
17499 struct die_info
*parent
)
17501 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17502 new_info_ptr
, parent
);
17504 if (dwarf_die_debug
)
17506 fprintf_unfiltered (gdb_stdlog
,
17507 "Read die from %s@0x%x of %s:\n",
17508 reader
->die_section
->get_name (),
17509 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17510 bfd_get_filename (reader
->abfd
));
17511 dump_die (die
, dwarf_die_debug
);
17517 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17519 The caller is responsible for filling in the extra attributes
17520 and updating (*DIEP)->num_attrs.
17521 Set DIEP to point to a newly allocated die with its information,
17522 except for its child, sibling, and parent fields. */
17524 static const gdb_byte
*
17525 read_full_die_1 (const struct die_reader_specs
*reader
,
17526 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17527 int num_extra_attrs
)
17529 unsigned int abbrev_number
, bytes_read
, i
;
17530 struct abbrev_info
*abbrev
;
17531 struct die_info
*die
;
17532 struct dwarf2_cu
*cu
= reader
->cu
;
17533 bfd
*abfd
= reader
->abfd
;
17535 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17536 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17537 info_ptr
+= bytes_read
;
17538 if (!abbrev_number
)
17544 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17546 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17548 bfd_get_filename (abfd
));
17550 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17551 die
->sect_off
= sect_off
;
17552 die
->tag
= abbrev
->tag
;
17553 die
->abbrev
= abbrev_number
;
17554 die
->has_children
= abbrev
->has_children
;
17556 /* Make the result usable.
17557 The caller needs to update num_attrs after adding the extra
17559 die
->num_attrs
= abbrev
->num_attrs
;
17561 std::vector
<int> indexes_that_need_reprocess
;
17562 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17564 bool need_reprocess
;
17566 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17567 info_ptr
, &need_reprocess
);
17568 if (need_reprocess
)
17569 indexes_that_need_reprocess
.push_back (i
);
17572 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
17573 if (attr
!= nullptr)
17574 cu
->str_offsets_base
= DW_UNSND (attr
);
17576 auto maybe_addr_base
= lookup_addr_base(die
);
17577 if (maybe_addr_base
.has_value ())
17578 cu
->addr_base
= *maybe_addr_base
;
17579 for (int index
: indexes_that_need_reprocess
)
17580 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17585 /* Read a die and all its attributes.
17586 Set DIEP to point to a newly allocated die with its information,
17587 except for its child, sibling, and parent fields. */
17589 static const gdb_byte
*
17590 read_full_die (const struct die_reader_specs
*reader
,
17591 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17593 const gdb_byte
*result
;
17595 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17597 if (dwarf_die_debug
)
17599 fprintf_unfiltered (gdb_stdlog
,
17600 "Read die from %s@0x%x of %s:\n",
17601 reader
->die_section
->get_name (),
17602 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17603 bfd_get_filename (reader
->abfd
));
17604 dump_die (*diep
, dwarf_die_debug
);
17611 /* Returns nonzero if TAG represents a type that we might generate a partial
17615 is_type_tag_for_partial (int tag
)
17620 /* Some types that would be reasonable to generate partial symbols for,
17621 that we don't at present. */
17622 case DW_TAG_array_type
:
17623 case DW_TAG_file_type
:
17624 case DW_TAG_ptr_to_member_type
:
17625 case DW_TAG_set_type
:
17626 case DW_TAG_string_type
:
17627 case DW_TAG_subroutine_type
:
17629 case DW_TAG_base_type
:
17630 case DW_TAG_class_type
:
17631 case DW_TAG_interface_type
:
17632 case DW_TAG_enumeration_type
:
17633 case DW_TAG_structure_type
:
17634 case DW_TAG_subrange_type
:
17635 case DW_TAG_typedef
:
17636 case DW_TAG_union_type
:
17643 /* Load all DIEs that are interesting for partial symbols into memory. */
17645 static struct partial_die_info
*
17646 load_partial_dies (const struct die_reader_specs
*reader
,
17647 const gdb_byte
*info_ptr
, int building_psymtab
)
17649 struct dwarf2_cu
*cu
= reader
->cu
;
17650 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17651 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17652 unsigned int bytes_read
;
17653 unsigned int load_all
= 0;
17654 int nesting_level
= 1;
17659 gdb_assert (cu
->per_cu
!= NULL
);
17660 if (cu
->per_cu
->load_all_dies
)
17664 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17668 &cu
->comp_unit_obstack
,
17669 hashtab_obstack_allocate
,
17670 dummy_obstack_deallocate
);
17674 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17676 /* A NULL abbrev means the end of a series of children. */
17677 if (abbrev
== NULL
)
17679 if (--nesting_level
== 0)
17682 info_ptr
+= bytes_read
;
17683 last_die
= parent_die
;
17684 parent_die
= parent_die
->die_parent
;
17688 /* Check for template arguments. We never save these; if
17689 they're seen, we just mark the parent, and go on our way. */
17690 if (parent_die
!= NULL
17691 && cu
->language
== language_cplus
17692 && (abbrev
->tag
== DW_TAG_template_type_param
17693 || abbrev
->tag
== DW_TAG_template_value_param
))
17695 parent_die
->has_template_arguments
= 1;
17699 /* We don't need a partial DIE for the template argument. */
17700 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17705 /* We only recurse into c++ subprograms looking for template arguments.
17706 Skip their other children. */
17708 && cu
->language
== language_cplus
17709 && parent_die
!= NULL
17710 && parent_die
->tag
== DW_TAG_subprogram
)
17712 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17716 /* Check whether this DIE is interesting enough to save. Normally
17717 we would not be interested in members here, but there may be
17718 later variables referencing them via DW_AT_specification (for
17719 static members). */
17721 && !is_type_tag_for_partial (abbrev
->tag
)
17722 && abbrev
->tag
!= DW_TAG_constant
17723 && abbrev
->tag
!= DW_TAG_enumerator
17724 && abbrev
->tag
!= DW_TAG_subprogram
17725 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17726 && abbrev
->tag
!= DW_TAG_lexical_block
17727 && abbrev
->tag
!= DW_TAG_variable
17728 && abbrev
->tag
!= DW_TAG_namespace
17729 && abbrev
->tag
!= DW_TAG_module
17730 && abbrev
->tag
!= DW_TAG_member
17731 && abbrev
->tag
!= DW_TAG_imported_unit
17732 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17734 /* Otherwise we skip to the next sibling, if any. */
17735 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17739 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17742 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17744 /* This two-pass algorithm for processing partial symbols has a
17745 high cost in cache pressure. Thus, handle some simple cases
17746 here which cover the majority of C partial symbols. DIEs
17747 which neither have specification tags in them, nor could have
17748 specification tags elsewhere pointing at them, can simply be
17749 processed and discarded.
17751 This segment is also optional; scan_partial_symbols and
17752 add_partial_symbol will handle these DIEs if we chain
17753 them in normally. When compilers which do not emit large
17754 quantities of duplicate debug information are more common,
17755 this code can probably be removed. */
17757 /* Any complete simple types at the top level (pretty much all
17758 of them, for a language without namespaces), can be processed
17760 if (parent_die
== NULL
17761 && pdi
.has_specification
== 0
17762 && pdi
.is_declaration
== 0
17763 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17764 || pdi
.tag
== DW_TAG_base_type
17765 || pdi
.tag
== DW_TAG_subrange_type
))
17767 if (building_psymtab
&& pdi
.name
!= NULL
)
17768 add_psymbol_to_list (pdi
.name
, false,
17769 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17770 psymbol_placement::STATIC
,
17771 0, cu
->language
, objfile
);
17772 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17776 /* The exception for DW_TAG_typedef with has_children above is
17777 a workaround of GCC PR debug/47510. In the case of this complaint
17778 type_name_or_error will error on such types later.
17780 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17781 it could not find the child DIEs referenced later, this is checked
17782 above. In correct DWARF DW_TAG_typedef should have no children. */
17784 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17785 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17786 "- DIE at %s [in module %s]"),
17787 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17789 /* If we're at the second level, and we're an enumerator, and
17790 our parent has no specification (meaning possibly lives in a
17791 namespace elsewhere), then we can add the partial symbol now
17792 instead of queueing it. */
17793 if (pdi
.tag
== DW_TAG_enumerator
17794 && parent_die
!= NULL
17795 && parent_die
->die_parent
== NULL
17796 && parent_die
->tag
== DW_TAG_enumeration_type
17797 && parent_die
->has_specification
== 0)
17799 if (pdi
.name
== NULL
)
17800 complaint (_("malformed enumerator DIE ignored"));
17801 else if (building_psymtab
)
17802 add_psymbol_to_list (pdi
.name
, false,
17803 VAR_DOMAIN
, LOC_CONST
, -1,
17804 cu
->language
== language_cplus
17805 ? psymbol_placement::GLOBAL
17806 : psymbol_placement::STATIC
,
17807 0, cu
->language
, objfile
);
17809 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17813 struct partial_die_info
*part_die
17814 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17816 /* We'll save this DIE so link it in. */
17817 part_die
->die_parent
= parent_die
;
17818 part_die
->die_sibling
= NULL
;
17819 part_die
->die_child
= NULL
;
17821 if (last_die
&& last_die
== parent_die
)
17822 last_die
->die_child
= part_die
;
17824 last_die
->die_sibling
= part_die
;
17826 last_die
= part_die
;
17828 if (first_die
== NULL
)
17829 first_die
= part_die
;
17831 /* Maybe add the DIE to the hash table. Not all DIEs that we
17832 find interesting need to be in the hash table, because we
17833 also have the parent/sibling/child chains; only those that we
17834 might refer to by offset later during partial symbol reading.
17836 For now this means things that might have be the target of a
17837 DW_AT_specification, DW_AT_abstract_origin, or
17838 DW_AT_extension. DW_AT_extension will refer only to
17839 namespaces; DW_AT_abstract_origin refers to functions (and
17840 many things under the function DIE, but we do not recurse
17841 into function DIEs during partial symbol reading) and
17842 possibly variables as well; DW_AT_specification refers to
17843 declarations. Declarations ought to have the DW_AT_declaration
17844 flag. It happens that GCC forgets to put it in sometimes, but
17845 only for functions, not for types.
17847 Adding more things than necessary to the hash table is harmless
17848 except for the performance cost. Adding too few will result in
17849 wasted time in find_partial_die, when we reread the compilation
17850 unit with load_all_dies set. */
17853 || abbrev
->tag
== DW_TAG_constant
17854 || abbrev
->tag
== DW_TAG_subprogram
17855 || abbrev
->tag
== DW_TAG_variable
17856 || abbrev
->tag
== DW_TAG_namespace
17857 || part_die
->is_declaration
)
17861 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17862 to_underlying (part_die
->sect_off
),
17867 /* For some DIEs we want to follow their children (if any). For C
17868 we have no reason to follow the children of structures; for other
17869 languages we have to, so that we can get at method physnames
17870 to infer fully qualified class names, for DW_AT_specification,
17871 and for C++ template arguments. For C++, we also look one level
17872 inside functions to find template arguments (if the name of the
17873 function does not already contain the template arguments).
17875 For Ada and Fortran, we need to scan the children of subprograms
17876 and lexical blocks as well because these languages allow the
17877 definition of nested entities that could be interesting for the
17878 debugger, such as nested subprograms for instance. */
17879 if (last_die
->has_children
17881 || last_die
->tag
== DW_TAG_namespace
17882 || last_die
->tag
== DW_TAG_module
17883 || last_die
->tag
== DW_TAG_enumeration_type
17884 || (cu
->language
== language_cplus
17885 && last_die
->tag
== DW_TAG_subprogram
17886 && (last_die
->name
== NULL
17887 || strchr (last_die
->name
, '<') == NULL
))
17888 || (cu
->language
!= language_c
17889 && (last_die
->tag
== DW_TAG_class_type
17890 || last_die
->tag
== DW_TAG_interface_type
17891 || last_die
->tag
== DW_TAG_structure_type
17892 || last_die
->tag
== DW_TAG_union_type
))
17893 || ((cu
->language
== language_ada
17894 || cu
->language
== language_fortran
)
17895 && (last_die
->tag
== DW_TAG_subprogram
17896 || last_die
->tag
== DW_TAG_lexical_block
))))
17899 parent_die
= last_die
;
17903 /* Otherwise we skip to the next sibling, if any. */
17904 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17906 /* Back to the top, do it again. */
17910 partial_die_info::partial_die_info (sect_offset sect_off_
,
17911 struct abbrev_info
*abbrev
)
17912 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17916 /* Read a minimal amount of information into the minimal die structure.
17917 INFO_PTR should point just after the initial uleb128 of a DIE. */
17920 partial_die_info::read (const struct die_reader_specs
*reader
,
17921 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17923 struct dwarf2_cu
*cu
= reader
->cu
;
17924 struct dwarf2_per_objfile
*dwarf2_per_objfile
17925 = cu
->per_cu
->dwarf2_per_objfile
;
17927 int has_low_pc_attr
= 0;
17928 int has_high_pc_attr
= 0;
17929 int high_pc_relative
= 0;
17931 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17932 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17934 bool need_reprocess
;
17935 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17936 info_ptr
, &need_reprocess
);
17937 /* String and address offsets that need to do the reprocessing have
17938 already been read at this point, so there is no need to wait until
17939 the loop terminates to do the reprocessing. */
17940 if (need_reprocess
)
17941 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17942 attribute
&attr
= attr_vec
[i
];
17943 /* Store the data if it is of an attribute we want to keep in a
17944 partial symbol table. */
17950 case DW_TAG_compile_unit
:
17951 case DW_TAG_partial_unit
:
17952 case DW_TAG_type_unit
:
17953 /* Compilation units have a DW_AT_name that is a filename, not
17954 a source language identifier. */
17955 case DW_TAG_enumeration_type
:
17956 case DW_TAG_enumerator
:
17957 /* These tags always have simple identifiers already; no need
17958 to canonicalize them. */
17959 name
= DW_STRING (&attr
);
17963 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17966 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
17967 &objfile
->per_bfd
->storage_obstack
);
17972 case DW_AT_linkage_name
:
17973 case DW_AT_MIPS_linkage_name
:
17974 /* Note that both forms of linkage name might appear. We
17975 assume they will be the same, and we only store the last
17977 linkage_name
= DW_STRING (&attr
);
17980 has_low_pc_attr
= 1;
17981 lowpc
= attr
.value_as_address ();
17983 case DW_AT_high_pc
:
17984 has_high_pc_attr
= 1;
17985 highpc
= attr
.value_as_address ();
17986 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
17987 high_pc_relative
= 1;
17989 case DW_AT_location
:
17990 /* Support the .debug_loc offsets. */
17991 if (attr
.form_is_block ())
17993 d
.locdesc
= DW_BLOCK (&attr
);
17995 else if (attr
.form_is_section_offset ())
17997 dwarf2_complex_location_expr_complaint ();
18001 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18002 "partial symbol information");
18005 case DW_AT_external
:
18006 is_external
= DW_UNSND (&attr
);
18008 case DW_AT_declaration
:
18009 is_declaration
= DW_UNSND (&attr
);
18014 case DW_AT_abstract_origin
:
18015 case DW_AT_specification
:
18016 case DW_AT_extension
:
18017 has_specification
= 1;
18018 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18019 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18020 || cu
->per_cu
->is_dwz
);
18022 case DW_AT_sibling
:
18023 /* Ignore absolute siblings, they might point outside of
18024 the current compile unit. */
18025 if (attr
.form
== DW_FORM_ref_addr
)
18026 complaint (_("ignoring absolute DW_AT_sibling"));
18029 const gdb_byte
*buffer
= reader
->buffer
;
18030 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18031 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18033 if (sibling_ptr
< info_ptr
)
18034 complaint (_("DW_AT_sibling points backwards"));
18035 else if (sibling_ptr
> reader
->buffer_end
)
18036 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18038 sibling
= sibling_ptr
;
18041 case DW_AT_byte_size
:
18044 case DW_AT_const_value
:
18045 has_const_value
= 1;
18047 case DW_AT_calling_convention
:
18048 /* DWARF doesn't provide a way to identify a program's source-level
18049 entry point. DW_AT_calling_convention attributes are only meant
18050 to describe functions' calling conventions.
18052 However, because it's a necessary piece of information in
18053 Fortran, and before DWARF 4 DW_CC_program was the only
18054 piece of debugging information whose definition refers to
18055 a 'main program' at all, several compilers marked Fortran
18056 main programs with DW_CC_program --- even when those
18057 functions use the standard calling conventions.
18059 Although DWARF now specifies a way to provide this
18060 information, we support this practice for backward
18062 if (DW_UNSND (&attr
) == DW_CC_program
18063 && cu
->language
== language_fortran
)
18064 main_subprogram
= 1;
18067 if (DW_UNSND (&attr
) == DW_INL_inlined
18068 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18069 may_be_inlined
= 1;
18073 if (tag
== DW_TAG_imported_unit
)
18075 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18076 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18077 || cu
->per_cu
->is_dwz
);
18081 case DW_AT_main_subprogram
:
18082 main_subprogram
= DW_UNSND (&attr
);
18087 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18088 but that requires a full DIE, so instead we just
18090 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18091 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18092 + (need_ranges_base
18096 /* Value of the DW_AT_ranges attribute is the offset in the
18097 .debug_ranges section. */
18098 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18109 /* For Ada, if both the name and the linkage name appear, we prefer
18110 the latter. This lets "catch exception" work better, regardless
18111 of the order in which the name and linkage name were emitted.
18112 Really, though, this is just a workaround for the fact that gdb
18113 doesn't store both the name and the linkage name. */
18114 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18115 name
= linkage_name
;
18117 if (high_pc_relative
)
18120 if (has_low_pc_attr
&& has_high_pc_attr
)
18122 /* When using the GNU linker, .gnu.linkonce. sections are used to
18123 eliminate duplicate copies of functions and vtables and such.
18124 The linker will arbitrarily choose one and discard the others.
18125 The AT_*_pc values for such functions refer to local labels in
18126 these sections. If the section from that file was discarded, the
18127 labels are not in the output, so the relocs get a value of 0.
18128 If this is a discarded function, mark the pc bounds as invalid,
18129 so that GDB will ignore it. */
18130 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18132 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18133 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18135 complaint (_("DW_AT_low_pc %s is zero "
18136 "for DIE at %s [in module %s]"),
18137 paddress (gdbarch
, lowpc
),
18138 sect_offset_str (sect_off
),
18139 objfile_name (objfile
));
18141 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18142 else if (lowpc
>= highpc
)
18144 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18145 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18147 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18148 "for DIE at %s [in module %s]"),
18149 paddress (gdbarch
, lowpc
),
18150 paddress (gdbarch
, highpc
),
18151 sect_offset_str (sect_off
),
18152 objfile_name (objfile
));
18161 /* Find a cached partial DIE at OFFSET in CU. */
18163 struct partial_die_info
*
18164 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18166 struct partial_die_info
*lookup_die
= NULL
;
18167 struct partial_die_info
part_die (sect_off
);
18169 lookup_die
= ((struct partial_die_info
*)
18170 htab_find_with_hash (partial_dies
, &part_die
,
18171 to_underlying (sect_off
)));
18176 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18177 except in the case of .debug_types DIEs which do not reference
18178 outside their CU (they do however referencing other types via
18179 DW_FORM_ref_sig8). */
18181 static const struct cu_partial_die_info
18182 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18184 struct dwarf2_per_objfile
*dwarf2_per_objfile
18185 = cu
->per_cu
->dwarf2_per_objfile
;
18186 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18187 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18188 struct partial_die_info
*pd
= NULL
;
18190 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18191 && cu
->header
.offset_in_cu_p (sect_off
))
18193 pd
= cu
->find_partial_die (sect_off
);
18196 /* We missed recording what we needed.
18197 Load all dies and try again. */
18198 per_cu
= cu
->per_cu
;
18202 /* TUs don't reference other CUs/TUs (except via type signatures). */
18203 if (cu
->per_cu
->is_debug_types
)
18205 error (_("Dwarf Error: Type Unit at offset %s contains"
18206 " external reference to offset %s [in module %s].\n"),
18207 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18208 bfd_get_filename (objfile
->obfd
));
18210 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18211 dwarf2_per_objfile
);
18213 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18214 load_partial_comp_unit (per_cu
);
18216 per_cu
->cu
->last_used
= 0;
18217 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18220 /* If we didn't find it, and not all dies have been loaded,
18221 load them all and try again. */
18223 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18225 per_cu
->load_all_dies
= 1;
18227 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18228 THIS_CU->cu may already be in use. So we can't just free it and
18229 replace its DIEs with the ones we read in. Instead, we leave those
18230 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18231 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18233 load_partial_comp_unit (per_cu
);
18235 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18239 internal_error (__FILE__
, __LINE__
,
18240 _("could not find partial DIE %s "
18241 "in cache [from module %s]\n"),
18242 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18243 return { per_cu
->cu
, pd
};
18246 /* See if we can figure out if the class lives in a namespace. We do
18247 this by looking for a member function; its demangled name will
18248 contain namespace info, if there is any. */
18251 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18252 struct dwarf2_cu
*cu
)
18254 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18255 what template types look like, because the demangler
18256 frequently doesn't give the same name as the debug info. We
18257 could fix this by only using the demangled name to get the
18258 prefix (but see comment in read_structure_type). */
18260 struct partial_die_info
*real_pdi
;
18261 struct partial_die_info
*child_pdi
;
18263 /* If this DIE (this DIE's specification, if any) has a parent, then
18264 we should not do this. We'll prepend the parent's fully qualified
18265 name when we create the partial symbol. */
18267 real_pdi
= struct_pdi
;
18268 while (real_pdi
->has_specification
)
18270 auto res
= find_partial_die (real_pdi
->spec_offset
,
18271 real_pdi
->spec_is_dwz
, cu
);
18272 real_pdi
= res
.pdi
;
18276 if (real_pdi
->die_parent
!= NULL
)
18279 for (child_pdi
= struct_pdi
->die_child
;
18281 child_pdi
= child_pdi
->die_sibling
)
18283 if (child_pdi
->tag
== DW_TAG_subprogram
18284 && child_pdi
->linkage_name
!= NULL
)
18286 gdb::unique_xmalloc_ptr
<char> actual_class_name
18287 (language_class_name_from_physname (cu
->language_defn
,
18288 child_pdi
->linkage_name
));
18289 if (actual_class_name
!= NULL
)
18291 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18293 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
18294 actual_class_name
.get ());
18302 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18304 /* Once we've fixed up a die, there's no point in doing so again.
18305 This also avoids a memory leak if we were to call
18306 guess_partial_die_structure_name multiple times. */
18310 /* If we found a reference attribute and the DIE has no name, try
18311 to find a name in the referred to DIE. */
18313 if (name
== NULL
&& has_specification
)
18315 struct partial_die_info
*spec_die
;
18317 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18318 spec_die
= res
.pdi
;
18321 spec_die
->fixup (cu
);
18323 if (spec_die
->name
)
18325 name
= spec_die
->name
;
18327 /* Copy DW_AT_external attribute if it is set. */
18328 if (spec_die
->is_external
)
18329 is_external
= spec_die
->is_external
;
18333 /* Set default names for some unnamed DIEs. */
18335 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18336 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18338 /* If there is no parent die to provide a namespace, and there are
18339 children, see if we can determine the namespace from their linkage
18341 if (cu
->language
== language_cplus
18342 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18343 && die_parent
== NULL
18345 && (tag
== DW_TAG_class_type
18346 || tag
== DW_TAG_structure_type
18347 || tag
== DW_TAG_union_type
))
18348 guess_partial_die_structure_name (this, cu
);
18350 /* GCC might emit a nameless struct or union that has a linkage
18351 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18353 && (tag
== DW_TAG_class_type
18354 || tag
== DW_TAG_interface_type
18355 || tag
== DW_TAG_structure_type
18356 || tag
== DW_TAG_union_type
)
18357 && linkage_name
!= NULL
)
18359 gdb::unique_xmalloc_ptr
<char> demangled
18360 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18361 if (demangled
!= nullptr)
18365 /* Strip any leading namespaces/classes, keep only the base name.
18366 DW_AT_name for named DIEs does not contain the prefixes. */
18367 base
= strrchr (demangled
.get (), ':');
18368 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18371 base
= demangled
.get ();
18373 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18374 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
18381 /* Process the attributes that had to be skipped in the first round. These
18382 attributes are the ones that need str_offsets_base or addr_base attributes.
18383 They could not have been processed in the first round, because at the time
18384 the values of str_offsets_base or addr_base may not have been known. */
18385 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18386 struct attribute
*attr
)
18388 struct dwarf2_cu
*cu
= reader
->cu
;
18389 switch (attr
->form
)
18391 case DW_FORM_addrx
:
18392 case DW_FORM_GNU_addr_index
:
18393 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18396 case DW_FORM_strx1
:
18397 case DW_FORM_strx2
:
18398 case DW_FORM_strx3
:
18399 case DW_FORM_strx4
:
18400 case DW_FORM_GNU_str_index
:
18402 unsigned int str_index
= DW_UNSND (attr
);
18403 if (reader
->dwo_file
!= NULL
)
18405 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18406 DW_STRING_IS_CANONICAL (attr
) = 0;
18410 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18411 DW_STRING_IS_CANONICAL (attr
) = 0;
18416 gdb_assert_not_reached (_("Unexpected DWARF form."));
18420 /* Read an attribute value described by an attribute form. */
18422 static const gdb_byte
*
18423 read_attribute_value (const struct die_reader_specs
*reader
,
18424 struct attribute
*attr
, unsigned form
,
18425 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18426 bool *need_reprocess
)
18428 struct dwarf2_cu
*cu
= reader
->cu
;
18429 struct dwarf2_per_objfile
*dwarf2_per_objfile
18430 = cu
->per_cu
->dwarf2_per_objfile
;
18431 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18432 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18433 bfd
*abfd
= reader
->abfd
;
18434 struct comp_unit_head
*cu_header
= &cu
->header
;
18435 unsigned int bytes_read
;
18436 struct dwarf_block
*blk
;
18437 *need_reprocess
= false;
18439 attr
->form
= (enum dwarf_form
) form
;
18442 case DW_FORM_ref_addr
:
18443 if (cu
->header
.version
== 2)
18444 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18447 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18449 info_ptr
+= bytes_read
;
18451 case DW_FORM_GNU_ref_alt
:
18452 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18453 info_ptr
+= bytes_read
;
18456 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18457 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18458 info_ptr
+= bytes_read
;
18460 case DW_FORM_block2
:
18461 blk
= dwarf_alloc_block (cu
);
18462 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18464 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18465 info_ptr
+= blk
->size
;
18466 DW_BLOCK (attr
) = blk
;
18468 case DW_FORM_block4
:
18469 blk
= dwarf_alloc_block (cu
);
18470 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18472 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18473 info_ptr
+= blk
->size
;
18474 DW_BLOCK (attr
) = blk
;
18476 case DW_FORM_data2
:
18477 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18480 case DW_FORM_data4
:
18481 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18484 case DW_FORM_data8
:
18485 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18488 case DW_FORM_data16
:
18489 blk
= dwarf_alloc_block (cu
);
18491 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18493 DW_BLOCK (attr
) = blk
;
18495 case DW_FORM_sec_offset
:
18496 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18497 info_ptr
+= bytes_read
;
18499 case DW_FORM_string
:
18500 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18501 DW_STRING_IS_CANONICAL (attr
) = 0;
18502 info_ptr
+= bytes_read
;
18505 if (!cu
->per_cu
->is_dwz
)
18507 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18508 abfd
, info_ptr
, cu_header
,
18510 DW_STRING_IS_CANONICAL (attr
) = 0;
18511 info_ptr
+= bytes_read
;
18515 case DW_FORM_line_strp
:
18516 if (!cu
->per_cu
->is_dwz
)
18518 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
18520 cu_header
, &bytes_read
);
18521 DW_STRING_IS_CANONICAL (attr
) = 0;
18522 info_ptr
+= bytes_read
;
18526 case DW_FORM_GNU_strp_alt
:
18528 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18529 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18532 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
18534 DW_STRING_IS_CANONICAL (attr
) = 0;
18535 info_ptr
+= bytes_read
;
18538 case DW_FORM_exprloc
:
18539 case DW_FORM_block
:
18540 blk
= dwarf_alloc_block (cu
);
18541 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18542 info_ptr
+= bytes_read
;
18543 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18544 info_ptr
+= blk
->size
;
18545 DW_BLOCK (attr
) = blk
;
18547 case DW_FORM_block1
:
18548 blk
= dwarf_alloc_block (cu
);
18549 blk
->size
= read_1_byte (abfd
, info_ptr
);
18551 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18552 info_ptr
+= blk
->size
;
18553 DW_BLOCK (attr
) = blk
;
18555 case DW_FORM_data1
:
18556 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18560 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18563 case DW_FORM_flag_present
:
18564 DW_UNSND (attr
) = 1;
18566 case DW_FORM_sdata
:
18567 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18568 info_ptr
+= bytes_read
;
18570 case DW_FORM_udata
:
18571 case DW_FORM_rnglistx
:
18572 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18573 info_ptr
+= bytes_read
;
18576 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18577 + read_1_byte (abfd
, info_ptr
));
18581 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18582 + read_2_bytes (abfd
, info_ptr
));
18586 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18587 + read_4_bytes (abfd
, info_ptr
));
18591 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18592 + read_8_bytes (abfd
, info_ptr
));
18595 case DW_FORM_ref_sig8
:
18596 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18599 case DW_FORM_ref_udata
:
18600 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18601 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18602 info_ptr
+= bytes_read
;
18604 case DW_FORM_indirect
:
18605 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18606 info_ptr
+= bytes_read
;
18607 if (form
== DW_FORM_implicit_const
)
18609 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18610 info_ptr
+= bytes_read
;
18612 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18613 info_ptr
, need_reprocess
);
18615 case DW_FORM_implicit_const
:
18616 DW_SND (attr
) = implicit_const
;
18618 case DW_FORM_addrx
:
18619 case DW_FORM_GNU_addr_index
:
18620 *need_reprocess
= true;
18621 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18622 info_ptr
+= bytes_read
;
18625 case DW_FORM_strx1
:
18626 case DW_FORM_strx2
:
18627 case DW_FORM_strx3
:
18628 case DW_FORM_strx4
:
18629 case DW_FORM_GNU_str_index
:
18631 ULONGEST str_index
;
18632 if (form
== DW_FORM_strx1
)
18634 str_index
= read_1_byte (abfd
, info_ptr
);
18637 else if (form
== DW_FORM_strx2
)
18639 str_index
= read_2_bytes (abfd
, info_ptr
);
18642 else if (form
== DW_FORM_strx3
)
18644 str_index
= read_3_bytes (abfd
, info_ptr
);
18647 else if (form
== DW_FORM_strx4
)
18649 str_index
= read_4_bytes (abfd
, info_ptr
);
18654 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18655 info_ptr
+= bytes_read
;
18657 *need_reprocess
= true;
18658 DW_UNSND (attr
) = str_index
;
18662 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18663 dwarf_form_name (form
),
18664 bfd_get_filename (abfd
));
18668 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18669 attr
->form
= DW_FORM_GNU_ref_alt
;
18671 /* We have seen instances where the compiler tried to emit a byte
18672 size attribute of -1 which ended up being encoded as an unsigned
18673 0xffffffff. Although 0xffffffff is technically a valid size value,
18674 an object of this size seems pretty unlikely so we can relatively
18675 safely treat these cases as if the size attribute was invalid and
18676 treat them as zero by default. */
18677 if (attr
->name
== DW_AT_byte_size
18678 && form
== DW_FORM_data4
18679 && DW_UNSND (attr
) >= 0xffffffff)
18682 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18683 hex_string (DW_UNSND (attr
)));
18684 DW_UNSND (attr
) = 0;
18690 /* Read an attribute described by an abbreviated attribute. */
18692 static const gdb_byte
*
18693 read_attribute (const struct die_reader_specs
*reader
,
18694 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18695 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18697 attr
->name
= abbrev
->name
;
18698 return read_attribute_value (reader
, attr
, abbrev
->form
,
18699 abbrev
->implicit_const
, info_ptr
,
18703 /* Cover function for read_initial_length.
18704 Returns the length of the object at BUF, and stores the size of the
18705 initial length in *BYTES_READ and stores the size that offsets will be in
18707 If the initial length size is not equivalent to that specified in
18708 CU_HEADER then issue a complaint.
18709 This is useful when reading non-comp-unit headers. */
18712 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
18713 const struct comp_unit_head
*cu_header
,
18714 unsigned int *bytes_read
,
18715 unsigned int *offset_size
)
18717 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
18719 gdb_assert (cu_header
->initial_length_size
== 4
18720 || cu_header
->initial_length_size
== 8
18721 || cu_header
->initial_length_size
== 12);
18723 if (cu_header
->initial_length_size
!= *bytes_read
)
18724 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
18726 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
18730 /* Return pointer to string at section SECT offset STR_OFFSET with error
18731 reporting strings FORM_NAME and SECT_NAME. */
18733 static const char *
18734 read_indirect_string_at_offset_from (struct objfile
*objfile
,
18735 bfd
*abfd
, LONGEST str_offset
,
18736 struct dwarf2_section_info
*sect
,
18737 const char *form_name
,
18738 const char *sect_name
)
18740 sect
->read (objfile
);
18741 if (sect
->buffer
== NULL
)
18742 error (_("%s used without %s section [in module %s]"),
18743 form_name
, sect_name
, bfd_get_filename (abfd
));
18744 if (str_offset
>= sect
->size
)
18745 error (_("%s pointing outside of %s section [in module %s]"),
18746 form_name
, sect_name
, bfd_get_filename (abfd
));
18747 gdb_assert (HOST_CHAR_BIT
== 8);
18748 if (sect
->buffer
[str_offset
] == '\0')
18750 return (const char *) (sect
->buffer
+ str_offset
);
18753 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18755 static const char *
18756 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18757 bfd
*abfd
, LONGEST str_offset
)
18759 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18761 &dwarf2_per_objfile
->str
,
18762 "DW_FORM_strp", ".debug_str");
18765 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
18767 static const char *
18768 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18769 bfd
*abfd
, LONGEST str_offset
)
18771 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18773 &dwarf2_per_objfile
->line_str
,
18774 "DW_FORM_line_strp",
18775 ".debug_line_str");
18778 /* Read a string at offset STR_OFFSET in the .debug_str section from
18779 the .dwz file DWZ. Throw an error if the offset is too large. If
18780 the string consists of a single NUL byte, return NULL; otherwise
18781 return a pointer to the string. */
18783 static const char *
18784 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
18785 LONGEST str_offset
)
18787 dwz
->str
.read (objfile
);
18789 if (dwz
->str
.buffer
== NULL
)
18790 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
18791 "section [in module %s]"),
18792 bfd_get_filename (dwz
->dwz_bfd
.get ()));
18793 if (str_offset
>= dwz
->str
.size
)
18794 error (_("DW_FORM_GNU_strp_alt pointing outside of "
18795 ".debug_str section [in module %s]"),
18796 bfd_get_filename (dwz
->dwz_bfd
.get ()));
18797 gdb_assert (HOST_CHAR_BIT
== 8);
18798 if (dwz
->str
.buffer
[str_offset
] == '\0')
18800 return (const char *) (dwz
->str
.buffer
+ str_offset
);
18803 /* Return pointer to string at .debug_str offset as read from BUF.
18804 BUF is assumed to be in a compilation unit described by CU_HEADER.
18805 Return *BYTES_READ_PTR count of bytes read from BUF. */
18807 static const char *
18808 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18809 const gdb_byte
*buf
,
18810 const struct comp_unit_head
*cu_header
,
18811 unsigned int *bytes_read_ptr
)
18813 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18815 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
18818 /* Return pointer to string at .debug_line_str offset as read from BUF.
18819 BUF is assumed to be in a compilation unit described by CU_HEADER.
18820 Return *BYTES_READ_PTR count of bytes read from BUF. */
18822 static const char *
18823 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18824 bfd
*abfd
, const gdb_byte
*buf
,
18825 const struct comp_unit_head
*cu_header
,
18826 unsigned int *bytes_read_ptr
)
18828 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18830 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
18834 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18835 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18836 ADDR_SIZE is the size of addresses from the CU header. */
18839 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18840 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18843 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18844 bfd
*abfd
= objfile
->obfd
;
18845 const gdb_byte
*info_ptr
;
18846 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18848 dwarf2_per_objfile
->addr
.read (objfile
);
18849 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18850 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18851 objfile_name (objfile
));
18852 if (addr_base_or_zero
+ addr_index
* addr_size
18853 >= dwarf2_per_objfile
->addr
.size
)
18854 error (_("DW_FORM_addr_index pointing outside of "
18855 ".debug_addr section [in module %s]"),
18856 objfile_name (objfile
));
18857 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18858 + addr_base_or_zero
+ addr_index
* addr_size
);
18859 if (addr_size
== 4)
18860 return bfd_get_32 (abfd
, info_ptr
);
18862 return bfd_get_64 (abfd
, info_ptr
);
18865 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18868 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18870 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18871 cu
->addr_base
, cu
->header
.addr_size
);
18874 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18877 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18878 unsigned int *bytes_read
)
18880 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18881 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18883 return read_addr_index (cu
, addr_index
);
18886 /* Given an index in .debug_addr, fetch the value.
18887 NOTE: This can be called during dwarf expression evaluation,
18888 long after the debug information has been read, and thus per_cu->cu
18889 may no longer exist. */
18892 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
18893 unsigned int addr_index
)
18895 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18896 struct dwarf2_cu
*cu
= per_cu
->cu
;
18897 gdb::optional
<ULONGEST
> addr_base
;
18900 /* We need addr_base and addr_size.
18901 If we don't have PER_CU->cu, we have to get it.
18902 Nasty, but the alternative is storing the needed info in PER_CU,
18903 which at this point doesn't seem justified: it's not clear how frequently
18904 it would get used and it would increase the size of every PER_CU.
18905 Entry points like dwarf2_per_cu_addr_size do a similar thing
18906 so we're not in uncharted territory here.
18907 Alas we need to be a bit more complicated as addr_base is contained
18910 We don't need to read the entire CU(/TU).
18911 We just need the header and top level die.
18913 IWBN to use the aging mechanism to let us lazily later discard the CU.
18914 For now we skip this optimization. */
18918 addr_base
= cu
->addr_base
;
18919 addr_size
= cu
->header
.addr_size
;
18923 cutu_reader
reader (per_cu
, NULL
, 0, 0, false);
18924 addr_base
= reader
.cu
->addr_base
;
18925 addr_size
= reader
.cu
->header
.addr_size
;
18928 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18932 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18933 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18936 static const char *
18937 read_str_index (struct dwarf2_cu
*cu
,
18938 struct dwarf2_section_info
*str_section
,
18939 struct dwarf2_section_info
*str_offsets_section
,
18940 ULONGEST str_offsets_base
, ULONGEST str_index
)
18942 struct dwarf2_per_objfile
*dwarf2_per_objfile
18943 = cu
->per_cu
->dwarf2_per_objfile
;
18944 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18945 const char *objf_name
= objfile_name (objfile
);
18946 bfd
*abfd
= objfile
->obfd
;
18947 const gdb_byte
*info_ptr
;
18948 ULONGEST str_offset
;
18949 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18951 str_section
->read (objfile
);
18952 str_offsets_section
->read (objfile
);
18953 if (str_section
->buffer
== NULL
)
18954 error (_("%s used without %s section"
18955 " in CU at offset %s [in module %s]"),
18956 form_name
, str_section
->get_name (),
18957 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18958 if (str_offsets_section
->buffer
== NULL
)
18959 error (_("%s used without %s section"
18960 " in CU at offset %s [in module %s]"),
18961 form_name
, str_section
->get_name (),
18962 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18963 info_ptr
= (str_offsets_section
->buffer
18965 + str_index
* cu
->header
.offset_size
);
18966 if (cu
->header
.offset_size
== 4)
18967 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18969 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18970 if (str_offset
>= str_section
->size
)
18971 error (_("Offset from %s pointing outside of"
18972 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18973 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18974 return (const char *) (str_section
->buffer
+ str_offset
);
18977 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18979 static const char *
18980 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18982 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18983 ? reader
->cu
->header
.addr_size
: 0;
18984 return read_str_index (reader
->cu
,
18985 &reader
->dwo_file
->sections
.str
,
18986 &reader
->dwo_file
->sections
.str_offsets
,
18987 str_offsets_base
, str_index
);
18990 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
18992 static const char *
18993 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
18995 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18996 const char *objf_name
= objfile_name (objfile
);
18997 static const char form_name
[] = "DW_FORM_GNU_str_index";
18998 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19000 if (!cu
->str_offsets_base
.has_value ())
19001 error (_("%s used in Fission stub without %s"
19002 " in CU at offset 0x%lx [in module %s]"),
19003 form_name
, str_offsets_attr_name
,
19004 (long) cu
->header
.offset_size
, objf_name
);
19006 return read_str_index (cu
,
19007 &cu
->per_cu
->dwarf2_per_objfile
->str
,
19008 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
19009 *cu
->str_offsets_base
, str_index
);
19012 /* Return the length of an LEB128 number in BUF. */
19015 leb128_size (const gdb_byte
*buf
)
19017 const gdb_byte
*begin
= buf
;
19023 if ((byte
& 128) == 0)
19024 return buf
- begin
;
19029 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19038 cu
->language
= language_c
;
19041 case DW_LANG_C_plus_plus
:
19042 case DW_LANG_C_plus_plus_11
:
19043 case DW_LANG_C_plus_plus_14
:
19044 cu
->language
= language_cplus
;
19047 cu
->language
= language_d
;
19049 case DW_LANG_Fortran77
:
19050 case DW_LANG_Fortran90
:
19051 case DW_LANG_Fortran95
:
19052 case DW_LANG_Fortran03
:
19053 case DW_LANG_Fortran08
:
19054 cu
->language
= language_fortran
;
19057 cu
->language
= language_go
;
19059 case DW_LANG_Mips_Assembler
:
19060 cu
->language
= language_asm
;
19062 case DW_LANG_Ada83
:
19063 case DW_LANG_Ada95
:
19064 cu
->language
= language_ada
;
19066 case DW_LANG_Modula2
:
19067 cu
->language
= language_m2
;
19069 case DW_LANG_Pascal83
:
19070 cu
->language
= language_pascal
;
19073 cu
->language
= language_objc
;
19076 case DW_LANG_Rust_old
:
19077 cu
->language
= language_rust
;
19079 case DW_LANG_Cobol74
:
19080 case DW_LANG_Cobol85
:
19082 cu
->language
= language_minimal
;
19085 cu
->language_defn
= language_def (cu
->language
);
19088 /* Return the named attribute or NULL if not there. */
19090 static struct attribute
*
19091 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19096 struct attribute
*spec
= NULL
;
19098 for (i
= 0; i
< die
->num_attrs
; ++i
)
19100 if (die
->attrs
[i
].name
== name
)
19101 return &die
->attrs
[i
];
19102 if (die
->attrs
[i
].name
== DW_AT_specification
19103 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19104 spec
= &die
->attrs
[i
];
19110 die
= follow_die_ref (die
, spec
, &cu
);
19116 /* Return the named attribute or NULL if not there,
19117 but do not follow DW_AT_specification, etc.
19118 This is for use in contexts where we're reading .debug_types dies.
19119 Following DW_AT_specification, DW_AT_abstract_origin will take us
19120 back up the chain, and we want to go down. */
19122 static struct attribute
*
19123 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19127 for (i
= 0; i
< die
->num_attrs
; ++i
)
19128 if (die
->attrs
[i
].name
== name
)
19129 return &die
->attrs
[i
];
19134 /* Return the string associated with a string-typed attribute, or NULL if it
19135 is either not found or is of an incorrect type. */
19137 static const char *
19138 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19140 struct attribute
*attr
;
19141 const char *str
= NULL
;
19143 attr
= dwarf2_attr (die
, name
, cu
);
19147 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19148 || attr
->form
== DW_FORM_string
19149 || attr
->form
== DW_FORM_strx
19150 || attr
->form
== DW_FORM_strx1
19151 || attr
->form
== DW_FORM_strx2
19152 || attr
->form
== DW_FORM_strx3
19153 || attr
->form
== DW_FORM_strx4
19154 || attr
->form
== DW_FORM_GNU_str_index
19155 || attr
->form
== DW_FORM_GNU_strp_alt
)
19156 str
= DW_STRING (attr
);
19158 complaint (_("string type expected for attribute %s for "
19159 "DIE at %s in module %s"),
19160 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19161 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19167 /* Return the dwo name or NULL if not present. If present, it is in either
19168 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19169 static const char *
19170 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19172 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19173 if (dwo_name
== nullptr)
19174 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19178 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19179 and holds a non-zero value. This function should only be used for
19180 DW_FORM_flag or DW_FORM_flag_present attributes. */
19183 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19185 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19187 return (attr
&& DW_UNSND (attr
));
19191 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19193 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19194 which value is non-zero. However, we have to be careful with
19195 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19196 (via dwarf2_flag_true_p) follows this attribute. So we may
19197 end up accidently finding a declaration attribute that belongs
19198 to a different DIE referenced by the specification attribute,
19199 even though the given DIE does not have a declaration attribute. */
19200 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19201 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19204 /* Return the die giving the specification for DIE, if there is
19205 one. *SPEC_CU is the CU containing DIE on input, and the CU
19206 containing the return value on output. If there is no
19207 specification, but there is an abstract origin, that is
19210 static struct die_info
*
19211 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19213 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19216 if (spec_attr
== NULL
)
19217 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19219 if (spec_attr
== NULL
)
19222 return follow_die_ref (die
, spec_attr
, spec_cu
);
19225 /* Stub for free_line_header to match void * callback types. */
19228 free_line_header_voidp (void *arg
)
19230 struct line_header
*lh
= (struct line_header
*) arg
;
19235 /* A convenience function to find the proper .debug_line section for a CU. */
19237 static struct dwarf2_section_info
*
19238 get_debug_line_section (struct dwarf2_cu
*cu
)
19240 struct dwarf2_section_info
*section
;
19241 struct dwarf2_per_objfile
*dwarf2_per_objfile
19242 = cu
->per_cu
->dwarf2_per_objfile
;
19244 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19246 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19247 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19248 else if (cu
->per_cu
->is_dwz
)
19250 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19252 section
= &dwz
->line
;
19255 section
= &dwarf2_per_objfile
->line
;
19260 /* Read directory or file name entry format, starting with byte of
19261 format count entries, ULEB128 pairs of entry formats, ULEB128 of
19262 entries count and the entries themselves in the described entry
19266 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19267 bfd
*abfd
, const gdb_byte
**bufp
,
19268 struct line_header
*lh
,
19269 const struct comp_unit_head
*cu_header
,
19270 void (*callback
) (struct line_header
*lh
,
19273 unsigned int mod_time
,
19274 unsigned int length
))
19276 gdb_byte format_count
, formati
;
19277 ULONGEST data_count
, datai
;
19278 const gdb_byte
*buf
= *bufp
;
19279 const gdb_byte
*format_header_data
;
19280 unsigned int bytes_read
;
19282 format_count
= read_1_byte (abfd
, buf
);
19284 format_header_data
= buf
;
19285 for (formati
= 0; formati
< format_count
; formati
++)
19287 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19289 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19293 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19295 for (datai
= 0; datai
< data_count
; datai
++)
19297 const gdb_byte
*format
= format_header_data
;
19298 struct file_entry fe
;
19300 for (formati
= 0; formati
< format_count
; formati
++)
19302 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19303 format
+= bytes_read
;
19305 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19306 format
+= bytes_read
;
19308 gdb::optional
<const char *> string
;
19309 gdb::optional
<unsigned int> uint
;
19313 case DW_FORM_string
:
19314 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
19318 case DW_FORM_line_strp
:
19319 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
19326 case DW_FORM_data1
:
19327 uint
.emplace (read_1_byte (abfd
, buf
));
19331 case DW_FORM_data2
:
19332 uint
.emplace (read_2_bytes (abfd
, buf
));
19336 case DW_FORM_data4
:
19337 uint
.emplace (read_4_bytes (abfd
, buf
));
19341 case DW_FORM_data8
:
19342 uint
.emplace (read_8_bytes (abfd
, buf
));
19346 case DW_FORM_data16
:
19347 /* This is used for MD5, but file_entry does not record MD5s. */
19351 case DW_FORM_udata
:
19352 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
19356 case DW_FORM_block
:
19357 /* It is valid only for DW_LNCT_timestamp which is ignored by
19362 switch (content_type
)
19365 if (string
.has_value ())
19368 case DW_LNCT_directory_index
:
19369 if (uint
.has_value ())
19370 fe
.d_index
= (dir_index
) *uint
;
19372 case DW_LNCT_timestamp
:
19373 if (uint
.has_value ())
19374 fe
.mod_time
= *uint
;
19377 if (uint
.has_value ())
19383 complaint (_("Unknown format content type %s"),
19384 pulongest (content_type
));
19388 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
19394 /* Read the statement program header starting at OFFSET in
19395 .debug_line, or .debug_line.dwo. Return a pointer
19396 to a struct line_header, allocated using xmalloc.
19397 Returns NULL if there is a problem reading the header, e.g., if it
19398 has a version we don't understand.
19400 NOTE: the strings in the include directory and file name tables of
19401 the returned object point into the dwarf line section buffer,
19402 and must not be freed. */
19404 static line_header_up
19405 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19407 const gdb_byte
*line_ptr
;
19408 unsigned int bytes_read
, offset_size
;
19410 const char *cur_dir
, *cur_file
;
19411 struct dwarf2_section_info
*section
;
19413 struct dwarf2_per_objfile
*dwarf2_per_objfile
19414 = cu
->per_cu
->dwarf2_per_objfile
;
19416 section
= get_debug_line_section (cu
);
19417 section
->read (dwarf2_per_objfile
->objfile
);
19418 if (section
->buffer
== NULL
)
19420 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19421 complaint (_("missing .debug_line.dwo section"));
19423 complaint (_("missing .debug_line section"));
19427 /* We can't do this until we know the section is non-empty.
19428 Only then do we know we have such a section. */
19429 abfd
= section
->get_bfd_owner ();
19431 /* Make sure that at least there's room for the total_length field.
19432 That could be 12 bytes long, but we're just going to fudge that. */
19433 if (to_underlying (sect_off
) + 4 >= section
->size
)
19435 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19439 line_header_up
lh (new line_header ());
19441 lh
->sect_off
= sect_off
;
19442 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
19444 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
19446 /* Read in the header. */
19448 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
19449 &bytes_read
, &offset_size
);
19450 line_ptr
+= bytes_read
;
19452 const gdb_byte
*start_here
= line_ptr
;
19454 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
19456 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19459 lh
->statement_program_end
= start_here
+ lh
->total_length
;
19460 lh
->version
= read_2_bytes (abfd
, line_ptr
);
19462 if (lh
->version
> 5)
19464 /* This is a version we don't understand. The format could have
19465 changed in ways we don't handle properly so just punt. */
19466 complaint (_("unsupported version in .debug_line section"));
19469 if (lh
->version
>= 5)
19471 gdb_byte segment_selector_size
;
19473 /* Skip address size. */
19474 read_1_byte (abfd
, line_ptr
);
19477 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
19479 if (segment_selector_size
!= 0)
19481 complaint (_("unsupported segment selector size %u "
19482 "in .debug_line section"),
19483 segment_selector_size
);
19487 lh
->header_length
= read_offset (abfd
, line_ptr
, offset_size
);
19488 line_ptr
+= offset_size
;
19489 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
19490 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
19492 if (lh
->version
>= 4)
19494 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
19498 lh
->maximum_ops_per_instruction
= 1;
19500 if (lh
->maximum_ops_per_instruction
== 0)
19502 lh
->maximum_ops_per_instruction
= 1;
19503 complaint (_("invalid maximum_ops_per_instruction "
19504 "in `.debug_line' section"));
19507 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
19509 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
19511 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
19513 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
19515 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
19517 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
19518 for (i
= 1; i
< lh
->opcode_base
; ++i
)
19520 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
19524 if (lh
->version
>= 5)
19526 /* Read directory table. */
19527 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19529 [] (struct line_header
*header
, const char *name
,
19530 dir_index d_index
, unsigned int mod_time
,
19531 unsigned int length
)
19533 header
->add_include_dir (name
);
19536 /* Read file name table. */
19537 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19539 [] (struct line_header
*header
, const char *name
,
19540 dir_index d_index
, unsigned int mod_time
,
19541 unsigned int length
)
19543 header
->add_file_name (name
, d_index
, mod_time
, length
);
19548 /* Read directory table. */
19549 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19551 line_ptr
+= bytes_read
;
19552 lh
->add_include_dir (cur_dir
);
19554 line_ptr
+= bytes_read
;
19556 /* Read file name table. */
19557 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19559 unsigned int mod_time
, length
;
19562 line_ptr
+= bytes_read
;
19563 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19564 line_ptr
+= bytes_read
;
19565 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19566 line_ptr
+= bytes_read
;
19567 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19568 line_ptr
+= bytes_read
;
19570 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
19572 line_ptr
+= bytes_read
;
19575 if (line_ptr
> (section
->buffer
+ section
->size
))
19576 complaint (_("line number info header doesn't "
19577 "fit in `.debug_line' section"));
19582 /* Subroutine of dwarf_decode_lines to simplify it.
19583 Return the file name of the psymtab for the given file_entry.
19584 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19585 If space for the result is malloc'd, *NAME_HOLDER will be set.
19586 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19588 static const char *
19589 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19590 const dwarf2_psymtab
*pst
,
19591 const char *comp_dir
,
19592 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19594 const char *include_name
= fe
.name
;
19595 const char *include_name_to_compare
= include_name
;
19596 const char *pst_filename
;
19599 const char *dir_name
= fe
.include_dir (lh
);
19601 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19602 if (!IS_ABSOLUTE_PATH (include_name
)
19603 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19605 /* Avoid creating a duplicate psymtab for PST.
19606 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19607 Before we do the comparison, however, we need to account
19608 for DIR_NAME and COMP_DIR.
19609 First prepend dir_name (if non-NULL). If we still don't
19610 have an absolute path prepend comp_dir (if non-NULL).
19611 However, the directory we record in the include-file's
19612 psymtab does not contain COMP_DIR (to match the
19613 corresponding symtab(s)).
19618 bash$ gcc -g ./hello.c
19619 include_name = "hello.c"
19621 DW_AT_comp_dir = comp_dir = "/tmp"
19622 DW_AT_name = "./hello.c"
19626 if (dir_name
!= NULL
)
19628 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19629 include_name
, (char *) NULL
));
19630 include_name
= name_holder
->get ();
19631 include_name_to_compare
= include_name
;
19633 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19635 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19636 include_name
, (char *) NULL
));
19637 include_name_to_compare
= hold_compare
.get ();
19641 pst_filename
= pst
->filename
;
19642 gdb::unique_xmalloc_ptr
<char> copied_name
;
19643 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19645 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19646 pst_filename
, (char *) NULL
));
19647 pst_filename
= copied_name
.get ();
19650 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19654 return include_name
;
19657 /* State machine to track the state of the line number program. */
19659 class lnp_state_machine
19662 /* Initialize a machine state for the start of a line number
19664 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19665 bool record_lines_p
);
19667 file_entry
*current_file ()
19669 /* lh->file_names is 0-based, but the file name numbers in the
19670 statement program are 1-based. */
19671 return m_line_header
->file_name_at (m_file
);
19674 /* Record the line in the state machine. END_SEQUENCE is true if
19675 we're processing the end of a sequence. */
19676 void record_line (bool end_sequence
);
19678 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19679 nop-out rest of the lines in this sequence. */
19680 void check_line_address (struct dwarf2_cu
*cu
,
19681 const gdb_byte
*line_ptr
,
19682 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19684 void handle_set_discriminator (unsigned int discriminator
)
19686 m_discriminator
= discriminator
;
19687 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19690 /* Handle DW_LNE_set_address. */
19691 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19694 address
+= baseaddr
;
19695 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19698 /* Handle DW_LNS_advance_pc. */
19699 void handle_advance_pc (CORE_ADDR adjust
);
19701 /* Handle a special opcode. */
19702 void handle_special_opcode (unsigned char op_code
);
19704 /* Handle DW_LNS_advance_line. */
19705 void handle_advance_line (int line_delta
)
19707 advance_line (line_delta
);
19710 /* Handle DW_LNS_set_file. */
19711 void handle_set_file (file_name_index file
);
19713 /* Handle DW_LNS_negate_stmt. */
19714 void handle_negate_stmt ()
19716 m_is_stmt
= !m_is_stmt
;
19719 /* Handle DW_LNS_const_add_pc. */
19720 void handle_const_add_pc ();
19722 /* Handle DW_LNS_fixed_advance_pc. */
19723 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19725 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19729 /* Handle DW_LNS_copy. */
19730 void handle_copy ()
19732 record_line (false);
19733 m_discriminator
= 0;
19736 /* Handle DW_LNE_end_sequence. */
19737 void handle_end_sequence ()
19739 m_currently_recording_lines
= true;
19743 /* Advance the line by LINE_DELTA. */
19744 void advance_line (int line_delta
)
19746 m_line
+= line_delta
;
19748 if (line_delta
!= 0)
19749 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19752 struct dwarf2_cu
*m_cu
;
19754 gdbarch
*m_gdbarch
;
19756 /* True if we're recording lines.
19757 Otherwise we're building partial symtabs and are just interested in
19758 finding include files mentioned by the line number program. */
19759 bool m_record_lines_p
;
19761 /* The line number header. */
19762 line_header
*m_line_header
;
19764 /* These are part of the standard DWARF line number state machine,
19765 and initialized according to the DWARF spec. */
19767 unsigned char m_op_index
= 0;
19768 /* The line table index of the current file. */
19769 file_name_index m_file
= 1;
19770 unsigned int m_line
= 1;
19772 /* These are initialized in the constructor. */
19774 CORE_ADDR m_address
;
19776 unsigned int m_discriminator
;
19778 /* Additional bits of state we need to track. */
19780 /* The last file that we called dwarf2_start_subfile for.
19781 This is only used for TLLs. */
19782 unsigned int m_last_file
= 0;
19783 /* The last file a line number was recorded for. */
19784 struct subfile
*m_last_subfile
= NULL
;
19786 /* When true, record the lines we decode. */
19787 bool m_currently_recording_lines
= false;
19789 /* The last line number that was recorded, used to coalesce
19790 consecutive entries for the same line. This can happen, for
19791 example, when discriminators are present. PR 17276. */
19792 unsigned int m_last_line
= 0;
19793 bool m_line_has_non_zero_discriminator
= false;
19797 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19799 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19800 / m_line_header
->maximum_ops_per_instruction
)
19801 * m_line_header
->minimum_instruction_length
);
19802 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19803 m_op_index
= ((m_op_index
+ adjust
)
19804 % m_line_header
->maximum_ops_per_instruction
);
19808 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19810 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19811 CORE_ADDR addr_adj
= (((m_op_index
19812 + (adj_opcode
/ m_line_header
->line_range
))
19813 / m_line_header
->maximum_ops_per_instruction
)
19814 * m_line_header
->minimum_instruction_length
);
19815 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19816 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
19817 % m_line_header
->maximum_ops_per_instruction
);
19819 int line_delta
= (m_line_header
->line_base
19820 + (adj_opcode
% m_line_header
->line_range
));
19821 advance_line (line_delta
);
19822 record_line (false);
19823 m_discriminator
= 0;
19827 lnp_state_machine::handle_set_file (file_name_index file
)
19831 const file_entry
*fe
= current_file ();
19833 dwarf2_debug_line_missing_file_complaint ();
19834 else if (m_record_lines_p
)
19836 const char *dir
= fe
->include_dir (m_line_header
);
19838 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19839 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19840 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19845 lnp_state_machine::handle_const_add_pc ()
19848 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19851 = (((m_op_index
+ adjust
)
19852 / m_line_header
->maximum_ops_per_instruction
)
19853 * m_line_header
->minimum_instruction_length
);
19855 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19856 m_op_index
= ((m_op_index
+ adjust
)
19857 % m_line_header
->maximum_ops_per_instruction
);
19860 /* Return non-zero if we should add LINE to the line number table.
19861 LINE is the line to add, LAST_LINE is the last line that was added,
19862 LAST_SUBFILE is the subfile for LAST_LINE.
19863 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19864 had a non-zero discriminator.
19866 We have to be careful in the presence of discriminators.
19867 E.g., for this line:
19869 for (i = 0; i < 100000; i++);
19871 clang can emit four line number entries for that one line,
19872 each with a different discriminator.
19873 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19875 However, we want gdb to coalesce all four entries into one.
19876 Otherwise the user could stepi into the middle of the line and
19877 gdb would get confused about whether the pc really was in the
19878 middle of the line.
19880 Things are further complicated by the fact that two consecutive
19881 line number entries for the same line is a heuristic used by gcc
19882 to denote the end of the prologue. So we can't just discard duplicate
19883 entries, we have to be selective about it. The heuristic we use is
19884 that we only collapse consecutive entries for the same line if at least
19885 one of those entries has a non-zero discriminator. PR 17276.
19887 Note: Addresses in the line number state machine can never go backwards
19888 within one sequence, thus this coalescing is ok. */
19891 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19892 unsigned int line
, unsigned int last_line
,
19893 int line_has_non_zero_discriminator
,
19894 struct subfile
*last_subfile
)
19896 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19898 if (line
!= last_line
)
19900 /* Same line for the same file that we've seen already.
19901 As a last check, for pr 17276, only record the line if the line
19902 has never had a non-zero discriminator. */
19903 if (!line_has_non_zero_discriminator
)
19908 /* Use the CU's builder to record line number LINE beginning at
19909 address ADDRESS in the line table of subfile SUBFILE. */
19912 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19913 unsigned int line
, CORE_ADDR address
,
19914 struct dwarf2_cu
*cu
)
19916 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19918 if (dwarf_line_debug
)
19920 fprintf_unfiltered (gdb_stdlog
,
19921 "Recording line %u, file %s, address %s\n",
19922 line
, lbasename (subfile
->name
),
19923 paddress (gdbarch
, address
));
19927 cu
->get_builder ()->record_line (subfile
, line
, addr
);
19930 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19931 Mark the end of a set of line number records.
19932 The arguments are the same as for dwarf_record_line_1.
19933 If SUBFILE is NULL the request is ignored. */
19936 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19937 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19939 if (subfile
== NULL
)
19942 if (dwarf_line_debug
)
19944 fprintf_unfiltered (gdb_stdlog
,
19945 "Finishing current line, file %s, address %s\n",
19946 lbasename (subfile
->name
),
19947 paddress (gdbarch
, address
));
19950 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
19954 lnp_state_machine::record_line (bool end_sequence
)
19956 if (dwarf_line_debug
)
19958 fprintf_unfiltered (gdb_stdlog
,
19959 "Processing actual line %u: file %u,"
19960 " address %s, is_stmt %u, discrim %u%s\n",
19962 paddress (m_gdbarch
, m_address
),
19963 m_is_stmt
, m_discriminator
,
19964 (end_sequence
? "\t(end sequence)" : ""));
19967 file_entry
*fe
= current_file ();
19970 dwarf2_debug_line_missing_file_complaint ();
19971 /* For now we ignore lines not starting on an instruction boundary.
19972 But not when processing end_sequence for compatibility with the
19973 previous version of the code. */
19974 else if (m_op_index
== 0 || end_sequence
)
19976 fe
->included_p
= 1;
19977 if (m_record_lines_p
19978 && (producer_is_codewarrior (m_cu
) || m_is_stmt
|| end_sequence
))
19980 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19983 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19984 m_currently_recording_lines
? m_cu
: nullptr);
19989 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19990 m_line_has_non_zero_discriminator
,
19993 buildsym_compunit
*builder
= m_cu
->get_builder ();
19994 dwarf_record_line_1 (m_gdbarch
,
19995 builder
->get_current_subfile (),
19997 m_currently_recording_lines
? m_cu
: nullptr);
19999 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20000 m_last_line
= m_line
;
20006 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20007 line_header
*lh
, bool record_lines_p
)
20011 m_record_lines_p
= record_lines_p
;
20012 m_line_header
= lh
;
20014 m_currently_recording_lines
= true;
20016 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20017 was a line entry for it so that the backend has a chance to adjust it
20018 and also record it in case it needs it. This is currently used by MIPS
20019 code, cf. `mips_adjust_dwarf2_line'. */
20020 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20021 m_is_stmt
= lh
->default_is_stmt
;
20022 m_discriminator
= 0;
20026 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20027 const gdb_byte
*line_ptr
,
20028 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20030 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20031 the pc range of the CU. However, we restrict the test to only ADDRESS
20032 values of zero to preserve GDB's previous behaviour which is to handle
20033 the specific case of a function being GC'd by the linker. */
20035 if (address
== 0 && address
< unrelocated_lowpc
)
20037 /* This line table is for a function which has been
20038 GCd by the linker. Ignore it. PR gdb/12528 */
20040 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20041 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20043 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20044 line_offset
, objfile_name (objfile
));
20045 m_currently_recording_lines
= false;
20046 /* Note: m_currently_recording_lines is left as false until we see
20047 DW_LNE_end_sequence. */
20051 /* Subroutine of dwarf_decode_lines to simplify it.
20052 Process the line number information in LH.
20053 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20054 program in order to set included_p for every referenced header. */
20057 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20058 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20060 const gdb_byte
*line_ptr
, *extended_end
;
20061 const gdb_byte
*line_end
;
20062 unsigned int bytes_read
, extended_len
;
20063 unsigned char op_code
, extended_op
;
20064 CORE_ADDR baseaddr
;
20065 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20066 bfd
*abfd
= objfile
->obfd
;
20067 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20068 /* True if we're recording line info (as opposed to building partial
20069 symtabs and just interested in finding include files mentioned by
20070 the line number program). */
20071 bool record_lines_p
= !decode_for_pst_p
;
20073 baseaddr
= objfile
->text_section_offset ();
20075 line_ptr
= lh
->statement_program_start
;
20076 line_end
= lh
->statement_program_end
;
20078 /* Read the statement sequences until there's nothing left. */
20079 while (line_ptr
< line_end
)
20081 /* The DWARF line number program state machine. Reset the state
20082 machine at the start of each sequence. */
20083 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20084 bool end_sequence
= false;
20086 if (record_lines_p
)
20088 /* Start a subfile for the current file of the state
20090 const file_entry
*fe
= state_machine
.current_file ();
20093 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20096 /* Decode the table. */
20097 while (line_ptr
< line_end
&& !end_sequence
)
20099 op_code
= read_1_byte (abfd
, line_ptr
);
20102 if (op_code
>= lh
->opcode_base
)
20104 /* Special opcode. */
20105 state_machine
.handle_special_opcode (op_code
);
20107 else switch (op_code
)
20109 case DW_LNS_extended_op
:
20110 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20112 line_ptr
+= bytes_read
;
20113 extended_end
= line_ptr
+ extended_len
;
20114 extended_op
= read_1_byte (abfd
, line_ptr
);
20116 switch (extended_op
)
20118 case DW_LNE_end_sequence
:
20119 state_machine
.handle_end_sequence ();
20120 end_sequence
= true;
20122 case DW_LNE_set_address
:
20125 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20126 line_ptr
+= bytes_read
;
20128 state_machine
.check_line_address (cu
, line_ptr
,
20129 lowpc
- baseaddr
, address
);
20130 state_machine
.handle_set_address (baseaddr
, address
);
20133 case DW_LNE_define_file
:
20135 const char *cur_file
;
20136 unsigned int mod_time
, length
;
20139 cur_file
= read_direct_string (abfd
, line_ptr
,
20141 line_ptr
+= bytes_read
;
20142 dindex
= (dir_index
)
20143 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20144 line_ptr
+= bytes_read
;
20146 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20147 line_ptr
+= bytes_read
;
20149 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20150 line_ptr
+= bytes_read
;
20151 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20154 case DW_LNE_set_discriminator
:
20156 /* The discriminator is not interesting to the
20157 debugger; just ignore it. We still need to
20158 check its value though:
20159 if there are consecutive entries for the same
20160 (non-prologue) line we want to coalesce them.
20163 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20164 line_ptr
+= bytes_read
;
20166 state_machine
.handle_set_discriminator (discr
);
20170 complaint (_("mangled .debug_line section"));
20173 /* Make sure that we parsed the extended op correctly. If e.g.
20174 we expected a different address size than the producer used,
20175 we may have read the wrong number of bytes. */
20176 if (line_ptr
!= extended_end
)
20178 complaint (_("mangled .debug_line section"));
20183 state_machine
.handle_copy ();
20185 case DW_LNS_advance_pc
:
20188 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20189 line_ptr
+= bytes_read
;
20191 state_machine
.handle_advance_pc (adjust
);
20194 case DW_LNS_advance_line
:
20197 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20198 line_ptr
+= bytes_read
;
20200 state_machine
.handle_advance_line (line_delta
);
20203 case DW_LNS_set_file
:
20205 file_name_index file
20206 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20208 line_ptr
+= bytes_read
;
20210 state_machine
.handle_set_file (file
);
20213 case DW_LNS_set_column
:
20214 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20215 line_ptr
+= bytes_read
;
20217 case DW_LNS_negate_stmt
:
20218 state_machine
.handle_negate_stmt ();
20220 case DW_LNS_set_basic_block
:
20222 /* Add to the address register of the state machine the
20223 address increment value corresponding to special opcode
20224 255. I.e., this value is scaled by the minimum
20225 instruction length since special opcode 255 would have
20226 scaled the increment. */
20227 case DW_LNS_const_add_pc
:
20228 state_machine
.handle_const_add_pc ();
20230 case DW_LNS_fixed_advance_pc
:
20232 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20235 state_machine
.handle_fixed_advance_pc (addr_adj
);
20240 /* Unknown standard opcode, ignore it. */
20243 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20245 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20246 line_ptr
+= bytes_read
;
20253 dwarf2_debug_line_missing_end_sequence_complaint ();
20255 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20256 in which case we still finish recording the last line). */
20257 state_machine
.record_line (true);
20261 /* Decode the Line Number Program (LNP) for the given line_header
20262 structure and CU. The actual information extracted and the type
20263 of structures created from the LNP depends on the value of PST.
20265 1. If PST is NULL, then this procedure uses the data from the program
20266 to create all necessary symbol tables, and their linetables.
20268 2. If PST is not NULL, this procedure reads the program to determine
20269 the list of files included by the unit represented by PST, and
20270 builds all the associated partial symbol tables.
20272 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20273 It is used for relative paths in the line table.
20274 NOTE: When processing partial symtabs (pst != NULL),
20275 comp_dir == pst->dirname.
20277 NOTE: It is important that psymtabs have the same file name (via strcmp)
20278 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20279 symtab we don't use it in the name of the psymtabs we create.
20280 E.g. expand_line_sal requires this when finding psymtabs to expand.
20281 A good testcase for this is mb-inline.exp.
20283 LOWPC is the lowest address in CU (or 0 if not known).
20285 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20286 for its PC<->lines mapping information. Otherwise only the filename
20287 table is read in. */
20290 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20291 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20292 CORE_ADDR lowpc
, int decode_mapping
)
20294 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20295 const int decode_for_pst_p
= (pst
!= NULL
);
20297 if (decode_mapping
)
20298 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20300 if (decode_for_pst_p
)
20302 /* Now that we're done scanning the Line Header Program, we can
20303 create the psymtab of each included file. */
20304 for (auto &file_entry
: lh
->file_names ())
20305 if (file_entry
.included_p
== 1)
20307 gdb::unique_xmalloc_ptr
<char> name_holder
;
20308 const char *include_name
=
20309 psymtab_include_file_name (lh
, file_entry
, pst
,
20310 comp_dir
, &name_holder
);
20311 if (include_name
!= NULL
)
20312 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20317 /* Make sure a symtab is created for every file, even files
20318 which contain only variables (i.e. no code with associated
20320 buildsym_compunit
*builder
= cu
->get_builder ();
20321 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20323 for (auto &fe
: lh
->file_names ())
20325 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20326 if (builder
->get_current_subfile ()->symtab
== NULL
)
20328 builder
->get_current_subfile ()->symtab
20329 = allocate_symtab (cust
,
20330 builder
->get_current_subfile ()->name
);
20332 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20337 /* Start a subfile for DWARF. FILENAME is the name of the file and
20338 DIRNAME the name of the source directory which contains FILENAME
20339 or NULL if not known.
20340 This routine tries to keep line numbers from identical absolute and
20341 relative file names in a common subfile.
20343 Using the `list' example from the GDB testsuite, which resides in
20344 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20345 of /srcdir/list0.c yields the following debugging information for list0.c:
20347 DW_AT_name: /srcdir/list0.c
20348 DW_AT_comp_dir: /compdir
20349 files.files[0].name: list0.h
20350 files.files[0].dir: /srcdir
20351 files.files[1].name: list0.c
20352 files.files[1].dir: /srcdir
20354 The line number information for list0.c has to end up in a single
20355 subfile, so that `break /srcdir/list0.c:1' works as expected.
20356 start_subfile will ensure that this happens provided that we pass the
20357 concatenation of files.files[1].dir and files.files[1].name as the
20361 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20362 const char *dirname
)
20364 gdb::unique_xmalloc_ptr
<char> copy
;
20366 /* In order not to lose the line information directory,
20367 we concatenate it to the filename when it makes sense.
20368 Note that the Dwarf3 standard says (speaking of filenames in line
20369 information): ``The directory index is ignored for file names
20370 that represent full path names''. Thus ignoring dirname in the
20371 `else' branch below isn't an issue. */
20373 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20375 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20376 filename
= copy
.get ();
20379 cu
->get_builder ()->start_subfile (filename
);
20382 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20383 buildsym_compunit constructor. */
20385 struct compunit_symtab
*
20386 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20389 gdb_assert (m_builder
== nullptr);
20391 m_builder
.reset (new struct buildsym_compunit
20392 (per_cu
->dwarf2_per_objfile
->objfile
,
20393 name
, comp_dir
, language
, low_pc
));
20395 list_in_scope
= get_builder ()->get_file_symbols ();
20397 get_builder ()->record_debugformat ("DWARF 2");
20398 get_builder ()->record_producer (producer
);
20400 processing_has_namespace_info
= false;
20402 return get_builder ()->get_compunit_symtab ();
20406 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20407 struct dwarf2_cu
*cu
)
20409 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20410 struct comp_unit_head
*cu_header
= &cu
->header
;
20412 /* NOTE drow/2003-01-30: There used to be a comment and some special
20413 code here to turn a symbol with DW_AT_external and a
20414 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20415 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20416 with some versions of binutils) where shared libraries could have
20417 relocations against symbols in their debug information - the
20418 minimal symbol would have the right address, but the debug info
20419 would not. It's no longer necessary, because we will explicitly
20420 apply relocations when we read in the debug information now. */
20422 /* A DW_AT_location attribute with no contents indicates that a
20423 variable has been optimized away. */
20424 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20426 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20430 /* Handle one degenerate form of location expression specially, to
20431 preserve GDB's previous behavior when section offsets are
20432 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20433 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20435 if (attr
->form_is_block ()
20436 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20437 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20438 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20439 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20440 && (DW_BLOCK (attr
)->size
20441 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20443 unsigned int dummy
;
20445 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20446 SET_SYMBOL_VALUE_ADDRESS
20447 (sym
, cu
->header
.read_address (objfile
->obfd
,
20448 DW_BLOCK (attr
)->data
+ 1,
20451 SET_SYMBOL_VALUE_ADDRESS
20452 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20454 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20455 fixup_symbol_section (sym
, objfile
);
20456 SET_SYMBOL_VALUE_ADDRESS
20458 SYMBOL_VALUE_ADDRESS (sym
)
20459 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20463 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20464 expression evaluator, and use LOC_COMPUTED only when necessary
20465 (i.e. when the value of a register or memory location is
20466 referenced, or a thread-local block, etc.). Then again, it might
20467 not be worthwhile. I'm assuming that it isn't unless performance
20468 or memory numbers show me otherwise. */
20470 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20472 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20473 cu
->has_loclist
= true;
20476 /* Given a pointer to a DWARF information entry, figure out if we need
20477 to make a symbol table entry for it, and if so, create a new entry
20478 and return a pointer to it.
20479 If TYPE is NULL, determine symbol type from the die, otherwise
20480 used the passed type.
20481 If SPACE is not NULL, use it to hold the new symbol. If it is
20482 NULL, allocate a new symbol on the objfile's obstack. */
20484 static struct symbol
*
20485 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20486 struct symbol
*space
)
20488 struct dwarf2_per_objfile
*dwarf2_per_objfile
20489 = cu
->per_cu
->dwarf2_per_objfile
;
20490 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20491 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20492 struct symbol
*sym
= NULL
;
20494 struct attribute
*attr
= NULL
;
20495 struct attribute
*attr2
= NULL
;
20496 CORE_ADDR baseaddr
;
20497 struct pending
**list_to_add
= NULL
;
20499 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20501 baseaddr
= objfile
->text_section_offset ();
20503 name
= dwarf2_name (die
, cu
);
20506 const char *linkagename
;
20507 int suppress_add
= 0;
20512 sym
= allocate_symbol (objfile
);
20513 OBJSTAT (objfile
, n_syms
++);
20515 /* Cache this symbol's name and the name's demangled form (if any). */
20516 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20517 linkagename
= dwarf2_physname (name
, die
, cu
);
20518 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20520 /* Fortran does not have mangling standard and the mangling does differ
20521 between gfortran, iFort etc. */
20522 if (cu
->language
== language_fortran
20523 && symbol_get_demangled_name (sym
) == NULL
)
20524 symbol_set_demangled_name (sym
,
20525 dwarf2_full_name (name
, die
, cu
),
20528 /* Default assumptions.
20529 Use the passed type or decode it from the die. */
20530 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20531 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20533 SYMBOL_TYPE (sym
) = type
;
20535 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20536 attr
= dwarf2_attr (die
,
20537 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20539 if (attr
!= nullptr)
20541 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20544 attr
= dwarf2_attr (die
,
20545 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20547 if (attr
!= nullptr)
20549 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20550 struct file_entry
*fe
;
20552 if (cu
->line_header
!= NULL
)
20553 fe
= cu
->line_header
->file_name_at (file_index
);
20558 complaint (_("file index out of range"));
20560 symbol_set_symtab (sym
, fe
->symtab
);
20566 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20567 if (attr
!= nullptr)
20571 addr
= attr
->value_as_address ();
20572 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20573 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20575 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20576 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20577 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20578 add_symbol_to_list (sym
, cu
->list_in_scope
);
20580 case DW_TAG_subprogram
:
20581 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20583 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20584 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20585 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20586 || cu
->language
== language_ada
20587 || cu
->language
== language_fortran
)
20589 /* Subprograms marked external are stored as a global symbol.
20590 Ada and Fortran subprograms, whether marked external or
20591 not, are always stored as a global symbol, because we want
20592 to be able to access them globally. For instance, we want
20593 to be able to break on a nested subprogram without having
20594 to specify the context. */
20595 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20599 list_to_add
= cu
->list_in_scope
;
20602 case DW_TAG_inlined_subroutine
:
20603 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20605 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20606 SYMBOL_INLINED (sym
) = 1;
20607 list_to_add
= cu
->list_in_scope
;
20609 case DW_TAG_template_value_param
:
20611 /* Fall through. */
20612 case DW_TAG_constant
:
20613 case DW_TAG_variable
:
20614 case DW_TAG_member
:
20615 /* Compilation with minimal debug info may result in
20616 variables with missing type entries. Change the
20617 misleading `void' type to something sensible. */
20618 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20619 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20621 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20622 /* In the case of DW_TAG_member, we should only be called for
20623 static const members. */
20624 if (die
->tag
== DW_TAG_member
)
20626 /* dwarf2_add_field uses die_is_declaration,
20627 so we do the same. */
20628 gdb_assert (die_is_declaration (die
, cu
));
20631 if (attr
!= nullptr)
20633 dwarf2_const_value (attr
, sym
, cu
);
20634 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20637 if (attr2
&& (DW_UNSND (attr2
) != 0))
20638 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20640 list_to_add
= cu
->list_in_scope
;
20644 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20645 if (attr
!= nullptr)
20647 var_decode_location (attr
, sym
, cu
);
20648 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20650 /* Fortran explicitly imports any global symbols to the local
20651 scope by DW_TAG_common_block. */
20652 if (cu
->language
== language_fortran
&& die
->parent
20653 && die
->parent
->tag
== DW_TAG_common_block
)
20656 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20657 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20658 && !dwarf2_per_objfile
->has_section_at_zero
)
20660 /* When a static variable is eliminated by the linker,
20661 the corresponding debug information is not stripped
20662 out, but the variable address is set to null;
20663 do not add such variables into symbol table. */
20665 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20667 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20668 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20669 && dwarf2_per_objfile
->can_copy
)
20671 /* A global static variable might be subject to
20672 copy relocation. We first check for a local
20673 minsym, though, because maybe the symbol was
20674 marked hidden, in which case this would not
20676 bound_minimal_symbol found
20677 = (lookup_minimal_symbol_linkage
20678 (sym
->linkage_name (), objfile
));
20679 if (found
.minsym
!= nullptr)
20680 sym
->maybe_copied
= 1;
20683 /* A variable with DW_AT_external is never static,
20684 but it may be block-scoped. */
20686 = ((cu
->list_in_scope
20687 == cu
->get_builder ()->get_file_symbols ())
20688 ? cu
->get_builder ()->get_global_symbols ()
20689 : cu
->list_in_scope
);
20692 list_to_add
= cu
->list_in_scope
;
20696 /* We do not know the address of this symbol.
20697 If it is an external symbol and we have type information
20698 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20699 The address of the variable will then be determined from
20700 the minimal symbol table whenever the variable is
20702 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20704 /* Fortran explicitly imports any global symbols to the local
20705 scope by DW_TAG_common_block. */
20706 if (cu
->language
== language_fortran
&& die
->parent
20707 && die
->parent
->tag
== DW_TAG_common_block
)
20709 /* SYMBOL_CLASS doesn't matter here because
20710 read_common_block is going to reset it. */
20712 list_to_add
= cu
->list_in_scope
;
20714 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20715 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20717 /* A variable with DW_AT_external is never static, but it
20718 may be block-scoped. */
20720 = ((cu
->list_in_scope
20721 == cu
->get_builder ()->get_file_symbols ())
20722 ? cu
->get_builder ()->get_global_symbols ()
20723 : cu
->list_in_scope
);
20725 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20727 else if (!die_is_declaration (die
, cu
))
20729 /* Use the default LOC_OPTIMIZED_OUT class. */
20730 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20732 list_to_add
= cu
->list_in_scope
;
20736 case DW_TAG_formal_parameter
:
20738 /* If we are inside a function, mark this as an argument. If
20739 not, we might be looking at an argument to an inlined function
20740 when we do not have enough information to show inlined frames;
20741 pretend it's a local variable in that case so that the user can
20743 struct context_stack
*curr
20744 = cu
->get_builder ()->get_current_context_stack ();
20745 if (curr
!= nullptr && curr
->name
!= nullptr)
20746 SYMBOL_IS_ARGUMENT (sym
) = 1;
20747 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20748 if (attr
!= nullptr)
20750 var_decode_location (attr
, sym
, cu
);
20752 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20753 if (attr
!= nullptr)
20755 dwarf2_const_value (attr
, sym
, cu
);
20758 list_to_add
= cu
->list_in_scope
;
20761 case DW_TAG_unspecified_parameters
:
20762 /* From varargs functions; gdb doesn't seem to have any
20763 interest in this information, so just ignore it for now.
20766 case DW_TAG_template_type_param
:
20768 /* Fall through. */
20769 case DW_TAG_class_type
:
20770 case DW_TAG_interface_type
:
20771 case DW_TAG_structure_type
:
20772 case DW_TAG_union_type
:
20773 case DW_TAG_set_type
:
20774 case DW_TAG_enumeration_type
:
20775 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20776 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20779 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20780 really ever be static objects: otherwise, if you try
20781 to, say, break of a class's method and you're in a file
20782 which doesn't mention that class, it won't work unless
20783 the check for all static symbols in lookup_symbol_aux
20784 saves you. See the OtherFileClass tests in
20785 gdb.c++/namespace.exp. */
20789 buildsym_compunit
*builder
= cu
->get_builder ();
20791 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20792 && cu
->language
== language_cplus
20793 ? builder
->get_global_symbols ()
20794 : cu
->list_in_scope
);
20796 /* The semantics of C++ state that "struct foo {
20797 ... }" also defines a typedef for "foo". */
20798 if (cu
->language
== language_cplus
20799 || cu
->language
== language_ada
20800 || cu
->language
== language_d
20801 || cu
->language
== language_rust
)
20803 /* The symbol's name is already allocated along
20804 with this objfile, so we don't need to
20805 duplicate it for the type. */
20806 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20807 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20812 case DW_TAG_typedef
:
20813 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20814 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20815 list_to_add
= cu
->list_in_scope
;
20817 case DW_TAG_base_type
:
20818 case DW_TAG_subrange_type
:
20819 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20820 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20821 list_to_add
= cu
->list_in_scope
;
20823 case DW_TAG_enumerator
:
20824 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20825 if (attr
!= nullptr)
20827 dwarf2_const_value (attr
, sym
, cu
);
20830 /* NOTE: carlton/2003-11-10: See comment above in the
20831 DW_TAG_class_type, etc. block. */
20834 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20835 && cu
->language
== language_cplus
20836 ? cu
->get_builder ()->get_global_symbols ()
20837 : cu
->list_in_scope
);
20840 case DW_TAG_imported_declaration
:
20841 case DW_TAG_namespace
:
20842 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20843 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20845 case DW_TAG_module
:
20846 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20847 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20848 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20850 case DW_TAG_common_block
:
20851 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20852 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20853 add_symbol_to_list (sym
, cu
->list_in_scope
);
20856 /* Not a tag we recognize. Hopefully we aren't processing
20857 trash data, but since we must specifically ignore things
20858 we don't recognize, there is nothing else we should do at
20860 complaint (_("unsupported tag: '%s'"),
20861 dwarf_tag_name (die
->tag
));
20867 sym
->hash_next
= objfile
->template_symbols
;
20868 objfile
->template_symbols
= sym
;
20869 list_to_add
= NULL
;
20872 if (list_to_add
!= NULL
)
20873 add_symbol_to_list (sym
, list_to_add
);
20875 /* For the benefit of old versions of GCC, check for anonymous
20876 namespaces based on the demangled name. */
20877 if (!cu
->processing_has_namespace_info
20878 && cu
->language
== language_cplus
)
20879 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20884 /* Given an attr with a DW_FORM_dataN value in host byte order,
20885 zero-extend it as appropriate for the symbol's type. The DWARF
20886 standard (v4) is not entirely clear about the meaning of using
20887 DW_FORM_dataN for a constant with a signed type, where the type is
20888 wider than the data. The conclusion of a discussion on the DWARF
20889 list was that this is unspecified. We choose to always zero-extend
20890 because that is the interpretation long in use by GCC. */
20893 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20894 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20896 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20897 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20898 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20899 LONGEST l
= DW_UNSND (attr
);
20901 if (bits
< sizeof (*value
) * 8)
20903 l
&= ((LONGEST
) 1 << bits
) - 1;
20906 else if (bits
== sizeof (*value
) * 8)
20910 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20911 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20918 /* Read a constant value from an attribute. Either set *VALUE, or if
20919 the value does not fit in *VALUE, set *BYTES - either already
20920 allocated on the objfile obstack, or newly allocated on OBSTACK,
20921 or, set *BATON, if we translated the constant to a location
20925 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20926 const char *name
, struct obstack
*obstack
,
20927 struct dwarf2_cu
*cu
,
20928 LONGEST
*value
, const gdb_byte
**bytes
,
20929 struct dwarf2_locexpr_baton
**baton
)
20931 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20932 struct comp_unit_head
*cu_header
= &cu
->header
;
20933 struct dwarf_block
*blk
;
20934 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20935 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20941 switch (attr
->form
)
20944 case DW_FORM_addrx
:
20945 case DW_FORM_GNU_addr_index
:
20949 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20950 dwarf2_const_value_length_mismatch_complaint (name
,
20951 cu_header
->addr_size
,
20952 TYPE_LENGTH (type
));
20953 /* Symbols of this form are reasonably rare, so we just
20954 piggyback on the existing location code rather than writing
20955 a new implementation of symbol_computed_ops. */
20956 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20957 (*baton
)->per_cu
= cu
->per_cu
;
20958 gdb_assert ((*baton
)->per_cu
);
20960 (*baton
)->size
= 2 + cu_header
->addr_size
;
20961 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20962 (*baton
)->data
= data
;
20964 data
[0] = DW_OP_addr
;
20965 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20966 byte_order
, DW_ADDR (attr
));
20967 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20970 case DW_FORM_string
:
20973 case DW_FORM_GNU_str_index
:
20974 case DW_FORM_GNU_strp_alt
:
20975 /* DW_STRING is already allocated on the objfile obstack, point
20977 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20979 case DW_FORM_block1
:
20980 case DW_FORM_block2
:
20981 case DW_FORM_block4
:
20982 case DW_FORM_block
:
20983 case DW_FORM_exprloc
:
20984 case DW_FORM_data16
:
20985 blk
= DW_BLOCK (attr
);
20986 if (TYPE_LENGTH (type
) != blk
->size
)
20987 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20988 TYPE_LENGTH (type
));
20989 *bytes
= blk
->data
;
20992 /* The DW_AT_const_value attributes are supposed to carry the
20993 symbol's value "represented as it would be on the target
20994 architecture." By the time we get here, it's already been
20995 converted to host endianness, so we just need to sign- or
20996 zero-extend it as appropriate. */
20997 case DW_FORM_data1
:
20998 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21000 case DW_FORM_data2
:
21001 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21003 case DW_FORM_data4
:
21004 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21006 case DW_FORM_data8
:
21007 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21010 case DW_FORM_sdata
:
21011 case DW_FORM_implicit_const
:
21012 *value
= DW_SND (attr
);
21015 case DW_FORM_udata
:
21016 *value
= DW_UNSND (attr
);
21020 complaint (_("unsupported const value attribute form: '%s'"),
21021 dwarf_form_name (attr
->form
));
21028 /* Copy constant value from an attribute to a symbol. */
21031 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21032 struct dwarf2_cu
*cu
)
21034 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21036 const gdb_byte
*bytes
;
21037 struct dwarf2_locexpr_baton
*baton
;
21039 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21040 sym
->print_name (),
21041 &objfile
->objfile_obstack
, cu
,
21042 &value
, &bytes
, &baton
);
21046 SYMBOL_LOCATION_BATON (sym
) = baton
;
21047 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21049 else if (bytes
!= NULL
)
21051 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21052 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21056 SYMBOL_VALUE (sym
) = value
;
21057 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21061 /* Return the type of the die in question using its DW_AT_type attribute. */
21063 static struct type
*
21064 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21066 struct attribute
*type_attr
;
21068 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21071 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21072 /* A missing DW_AT_type represents a void type. */
21073 return objfile_type (objfile
)->builtin_void
;
21076 return lookup_die_type (die
, type_attr
, cu
);
21079 /* True iff CU's producer generates GNAT Ada auxiliary information
21080 that allows to find parallel types through that information instead
21081 of having to do expensive parallel lookups by type name. */
21084 need_gnat_info (struct dwarf2_cu
*cu
)
21086 /* Assume that the Ada compiler was GNAT, which always produces
21087 the auxiliary information. */
21088 return (cu
->language
== language_ada
);
21091 /* Return the auxiliary type of the die in question using its
21092 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21093 attribute is not present. */
21095 static struct type
*
21096 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21098 struct attribute
*type_attr
;
21100 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21104 return lookup_die_type (die
, type_attr
, cu
);
21107 /* If DIE has a descriptive_type attribute, then set the TYPE's
21108 descriptive type accordingly. */
21111 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21112 struct dwarf2_cu
*cu
)
21114 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21116 if (descriptive_type
)
21118 ALLOCATE_GNAT_AUX_TYPE (type
);
21119 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21123 /* Return the containing type of the die in question using its
21124 DW_AT_containing_type attribute. */
21126 static struct type
*
21127 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21129 struct attribute
*type_attr
;
21130 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21132 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21134 error (_("Dwarf Error: Problem turning containing type into gdb type "
21135 "[in module %s]"), objfile_name (objfile
));
21137 return lookup_die_type (die
, type_attr
, cu
);
21140 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21142 static struct type
*
21143 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21145 struct dwarf2_per_objfile
*dwarf2_per_objfile
21146 = cu
->per_cu
->dwarf2_per_objfile
;
21147 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21150 std::string message
21151 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21152 objfile_name (objfile
),
21153 sect_offset_str (cu
->header
.sect_off
),
21154 sect_offset_str (die
->sect_off
));
21155 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21157 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21160 /* Look up the type of DIE in CU using its type attribute ATTR.
21161 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21162 DW_AT_containing_type.
21163 If there is no type substitute an error marker. */
21165 static struct type
*
21166 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21167 struct dwarf2_cu
*cu
)
21169 struct dwarf2_per_objfile
*dwarf2_per_objfile
21170 = cu
->per_cu
->dwarf2_per_objfile
;
21171 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21172 struct type
*this_type
;
21174 gdb_assert (attr
->name
== DW_AT_type
21175 || attr
->name
== DW_AT_GNAT_descriptive_type
21176 || attr
->name
== DW_AT_containing_type
);
21178 /* First see if we have it cached. */
21180 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21182 struct dwarf2_per_cu_data
*per_cu
;
21183 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21185 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21186 dwarf2_per_objfile
);
21187 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21189 else if (attr
->form_is_ref ())
21191 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21193 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21195 else if (attr
->form
== DW_FORM_ref_sig8
)
21197 ULONGEST signature
= DW_SIGNATURE (attr
);
21199 return get_signatured_type (die
, signature
, cu
);
21203 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21204 " at %s [in module %s]"),
21205 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21206 objfile_name (objfile
));
21207 return build_error_marker_type (cu
, die
);
21210 /* If not cached we need to read it in. */
21212 if (this_type
== NULL
)
21214 struct die_info
*type_die
= NULL
;
21215 struct dwarf2_cu
*type_cu
= cu
;
21217 if (attr
->form_is_ref ())
21218 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21219 if (type_die
== NULL
)
21220 return build_error_marker_type (cu
, die
);
21221 /* If we find the type now, it's probably because the type came
21222 from an inter-CU reference and the type's CU got expanded before
21224 this_type
= read_type_die (type_die
, type_cu
);
21227 /* If we still don't have a type use an error marker. */
21229 if (this_type
== NULL
)
21230 return build_error_marker_type (cu
, die
);
21235 /* Return the type in DIE, CU.
21236 Returns NULL for invalid types.
21238 This first does a lookup in die_type_hash,
21239 and only reads the die in if necessary.
21241 NOTE: This can be called when reading in partial or full symbols. */
21243 static struct type
*
21244 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21246 struct type
*this_type
;
21248 this_type
= get_die_type (die
, cu
);
21252 return read_type_die_1 (die
, cu
);
21255 /* Read the type in DIE, CU.
21256 Returns NULL for invalid types. */
21258 static struct type
*
21259 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21261 struct type
*this_type
= NULL
;
21265 case DW_TAG_class_type
:
21266 case DW_TAG_interface_type
:
21267 case DW_TAG_structure_type
:
21268 case DW_TAG_union_type
:
21269 this_type
= read_structure_type (die
, cu
);
21271 case DW_TAG_enumeration_type
:
21272 this_type
= read_enumeration_type (die
, cu
);
21274 case DW_TAG_subprogram
:
21275 case DW_TAG_subroutine_type
:
21276 case DW_TAG_inlined_subroutine
:
21277 this_type
= read_subroutine_type (die
, cu
);
21279 case DW_TAG_array_type
:
21280 this_type
= read_array_type (die
, cu
);
21282 case DW_TAG_set_type
:
21283 this_type
= read_set_type (die
, cu
);
21285 case DW_TAG_pointer_type
:
21286 this_type
= read_tag_pointer_type (die
, cu
);
21288 case DW_TAG_ptr_to_member_type
:
21289 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21291 case DW_TAG_reference_type
:
21292 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21294 case DW_TAG_rvalue_reference_type
:
21295 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21297 case DW_TAG_const_type
:
21298 this_type
= read_tag_const_type (die
, cu
);
21300 case DW_TAG_volatile_type
:
21301 this_type
= read_tag_volatile_type (die
, cu
);
21303 case DW_TAG_restrict_type
:
21304 this_type
= read_tag_restrict_type (die
, cu
);
21306 case DW_TAG_string_type
:
21307 this_type
= read_tag_string_type (die
, cu
);
21309 case DW_TAG_typedef
:
21310 this_type
= read_typedef (die
, cu
);
21312 case DW_TAG_subrange_type
:
21313 this_type
= read_subrange_type (die
, cu
);
21315 case DW_TAG_base_type
:
21316 this_type
= read_base_type (die
, cu
);
21318 case DW_TAG_unspecified_type
:
21319 this_type
= read_unspecified_type (die
, cu
);
21321 case DW_TAG_namespace
:
21322 this_type
= read_namespace_type (die
, cu
);
21324 case DW_TAG_module
:
21325 this_type
= read_module_type (die
, cu
);
21327 case DW_TAG_atomic_type
:
21328 this_type
= read_tag_atomic_type (die
, cu
);
21331 complaint (_("unexpected tag in read_type_die: '%s'"),
21332 dwarf_tag_name (die
->tag
));
21339 /* See if we can figure out if the class lives in a namespace. We do
21340 this by looking for a member function; its demangled name will
21341 contain namespace info, if there is any.
21342 Return the computed name or NULL.
21343 Space for the result is allocated on the objfile's obstack.
21344 This is the full-die version of guess_partial_die_structure_name.
21345 In this case we know DIE has no useful parent. */
21347 static const char *
21348 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21350 struct die_info
*spec_die
;
21351 struct dwarf2_cu
*spec_cu
;
21352 struct die_info
*child
;
21353 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21356 spec_die
= die_specification (die
, &spec_cu
);
21357 if (spec_die
!= NULL
)
21363 for (child
= die
->child
;
21365 child
= child
->sibling
)
21367 if (child
->tag
== DW_TAG_subprogram
)
21369 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21371 if (linkage_name
!= NULL
)
21373 gdb::unique_xmalloc_ptr
<char> actual_name
21374 (language_class_name_from_physname (cu
->language_defn
,
21376 const char *name
= NULL
;
21378 if (actual_name
!= NULL
)
21380 const char *die_name
= dwarf2_name (die
, cu
);
21382 if (die_name
!= NULL
21383 && strcmp (die_name
, actual_name
.get ()) != 0)
21385 /* Strip off the class name from the full name.
21386 We want the prefix. */
21387 int die_name_len
= strlen (die_name
);
21388 int actual_name_len
= strlen (actual_name
.get ());
21389 const char *ptr
= actual_name
.get ();
21391 /* Test for '::' as a sanity check. */
21392 if (actual_name_len
> die_name_len
+ 2
21393 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21394 name
= obstack_strndup (
21395 &objfile
->per_bfd
->storage_obstack
,
21396 ptr
, actual_name_len
- die_name_len
- 2);
21407 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21408 prefix part in such case. See
21409 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21411 static const char *
21412 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21414 struct attribute
*attr
;
21417 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21418 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21421 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21424 attr
= dw2_linkage_name_attr (die
, cu
);
21425 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21428 /* dwarf2_name had to be already called. */
21429 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21431 /* Strip the base name, keep any leading namespaces/classes. */
21432 base
= strrchr (DW_STRING (attr
), ':');
21433 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21436 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21437 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21439 &base
[-1] - DW_STRING (attr
));
21442 /* Return the name of the namespace/class that DIE is defined within,
21443 or "" if we can't tell. The caller should not xfree the result.
21445 For example, if we're within the method foo() in the following
21455 then determine_prefix on foo's die will return "N::C". */
21457 static const char *
21458 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21460 struct dwarf2_per_objfile
*dwarf2_per_objfile
21461 = cu
->per_cu
->dwarf2_per_objfile
;
21462 struct die_info
*parent
, *spec_die
;
21463 struct dwarf2_cu
*spec_cu
;
21464 struct type
*parent_type
;
21465 const char *retval
;
21467 if (cu
->language
!= language_cplus
21468 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21469 && cu
->language
!= language_rust
)
21472 retval
= anonymous_struct_prefix (die
, cu
);
21476 /* We have to be careful in the presence of DW_AT_specification.
21477 For example, with GCC 3.4, given the code
21481 // Definition of N::foo.
21485 then we'll have a tree of DIEs like this:
21487 1: DW_TAG_compile_unit
21488 2: DW_TAG_namespace // N
21489 3: DW_TAG_subprogram // declaration of N::foo
21490 4: DW_TAG_subprogram // definition of N::foo
21491 DW_AT_specification // refers to die #3
21493 Thus, when processing die #4, we have to pretend that we're in
21494 the context of its DW_AT_specification, namely the contex of die
21497 spec_die
= die_specification (die
, &spec_cu
);
21498 if (spec_die
== NULL
)
21499 parent
= die
->parent
;
21502 parent
= spec_die
->parent
;
21506 if (parent
== NULL
)
21508 else if (parent
->building_fullname
)
21511 const char *parent_name
;
21513 /* It has been seen on RealView 2.2 built binaries,
21514 DW_TAG_template_type_param types actually _defined_ as
21515 children of the parent class:
21518 template class <class Enum> Class{};
21519 Class<enum E> class_e;
21521 1: DW_TAG_class_type (Class)
21522 2: DW_TAG_enumeration_type (E)
21523 3: DW_TAG_enumerator (enum1:0)
21524 3: DW_TAG_enumerator (enum2:1)
21526 2: DW_TAG_template_type_param
21527 DW_AT_type DW_FORM_ref_udata (E)
21529 Besides being broken debug info, it can put GDB into an
21530 infinite loop. Consider:
21532 When we're building the full name for Class<E>, we'll start
21533 at Class, and go look over its template type parameters,
21534 finding E. We'll then try to build the full name of E, and
21535 reach here. We're now trying to build the full name of E,
21536 and look over the parent DIE for containing scope. In the
21537 broken case, if we followed the parent DIE of E, we'd again
21538 find Class, and once again go look at its template type
21539 arguments, etc., etc. Simply don't consider such parent die
21540 as source-level parent of this die (it can't be, the language
21541 doesn't allow it), and break the loop here. */
21542 name
= dwarf2_name (die
, cu
);
21543 parent_name
= dwarf2_name (parent
, cu
);
21544 complaint (_("template param type '%s' defined within parent '%s'"),
21545 name
? name
: "<unknown>",
21546 parent_name
? parent_name
: "<unknown>");
21550 switch (parent
->tag
)
21552 case DW_TAG_namespace
:
21553 parent_type
= read_type_die (parent
, cu
);
21554 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21555 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21556 Work around this problem here. */
21557 if (cu
->language
== language_cplus
21558 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21560 /* We give a name to even anonymous namespaces. */
21561 return TYPE_NAME (parent_type
);
21562 case DW_TAG_class_type
:
21563 case DW_TAG_interface_type
:
21564 case DW_TAG_structure_type
:
21565 case DW_TAG_union_type
:
21566 case DW_TAG_module
:
21567 parent_type
= read_type_die (parent
, cu
);
21568 if (TYPE_NAME (parent_type
) != NULL
)
21569 return TYPE_NAME (parent_type
);
21571 /* An anonymous structure is only allowed non-static data
21572 members; no typedefs, no member functions, et cetera.
21573 So it does not need a prefix. */
21575 case DW_TAG_compile_unit
:
21576 case DW_TAG_partial_unit
:
21577 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21578 if (cu
->language
== language_cplus
21579 && !dwarf2_per_objfile
->types
.empty ()
21580 && die
->child
!= NULL
21581 && (die
->tag
== DW_TAG_class_type
21582 || die
->tag
== DW_TAG_structure_type
21583 || die
->tag
== DW_TAG_union_type
))
21585 const char *name
= guess_full_die_structure_name (die
, cu
);
21590 case DW_TAG_subprogram
:
21591 /* Nested subroutines in Fortran get a prefix with the name
21592 of the parent's subroutine. */
21593 if (cu
->language
== language_fortran
)
21595 if ((die
->tag
== DW_TAG_subprogram
)
21596 && (dwarf2_name (parent
, cu
) != NULL
))
21597 return dwarf2_name (parent
, cu
);
21599 return determine_prefix (parent
, cu
);
21600 case DW_TAG_enumeration_type
:
21601 parent_type
= read_type_die (parent
, cu
);
21602 if (TYPE_DECLARED_CLASS (parent_type
))
21604 if (TYPE_NAME (parent_type
) != NULL
)
21605 return TYPE_NAME (parent_type
);
21608 /* Fall through. */
21610 return determine_prefix (parent
, cu
);
21614 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21615 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21616 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21617 an obconcat, otherwise allocate storage for the result. The CU argument is
21618 used to determine the language and hence, the appropriate separator. */
21620 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21623 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21624 int physname
, struct dwarf2_cu
*cu
)
21626 const char *lead
= "";
21629 if (suffix
== NULL
|| suffix
[0] == '\0'
21630 || prefix
== NULL
|| prefix
[0] == '\0')
21632 else if (cu
->language
== language_d
)
21634 /* For D, the 'main' function could be defined in any module, but it
21635 should never be prefixed. */
21636 if (strcmp (suffix
, "D main") == 0)
21644 else if (cu
->language
== language_fortran
&& physname
)
21646 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21647 DW_AT_MIPS_linkage_name is preferred and used instead. */
21655 if (prefix
== NULL
)
21657 if (suffix
== NULL
)
21664 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21666 strcpy (retval
, lead
);
21667 strcat (retval
, prefix
);
21668 strcat (retval
, sep
);
21669 strcat (retval
, suffix
);
21674 /* We have an obstack. */
21675 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21679 /* Return sibling of die, NULL if no sibling. */
21681 static struct die_info
*
21682 sibling_die (struct die_info
*die
)
21684 return die
->sibling
;
21687 /* Get name of a die, return NULL if not found. */
21689 static const char *
21690 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21691 struct obstack
*obstack
)
21693 if (name
&& cu
->language
== language_cplus
)
21695 std::string canon_name
= cp_canonicalize_string (name
);
21697 if (!canon_name
.empty ())
21699 if (canon_name
!= name
)
21700 name
= obstack_strdup (obstack
, canon_name
);
21707 /* Get name of a die, return NULL if not found.
21708 Anonymous namespaces are converted to their magic string. */
21710 static const char *
21711 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21713 struct attribute
*attr
;
21714 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21716 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21717 if ((!attr
|| !DW_STRING (attr
))
21718 && die
->tag
!= DW_TAG_namespace
21719 && die
->tag
!= DW_TAG_class_type
21720 && die
->tag
!= DW_TAG_interface_type
21721 && die
->tag
!= DW_TAG_structure_type
21722 && die
->tag
!= DW_TAG_union_type
)
21727 case DW_TAG_compile_unit
:
21728 case DW_TAG_partial_unit
:
21729 /* Compilation units have a DW_AT_name that is a filename, not
21730 a source language identifier. */
21731 case DW_TAG_enumeration_type
:
21732 case DW_TAG_enumerator
:
21733 /* These tags always have simple identifiers already; no need
21734 to canonicalize them. */
21735 return DW_STRING (attr
);
21737 case DW_TAG_namespace
:
21738 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21739 return DW_STRING (attr
);
21740 return CP_ANONYMOUS_NAMESPACE_STR
;
21742 case DW_TAG_class_type
:
21743 case DW_TAG_interface_type
:
21744 case DW_TAG_structure_type
:
21745 case DW_TAG_union_type
:
21746 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21747 structures or unions. These were of the form "._%d" in GCC 4.1,
21748 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21749 and GCC 4.4. We work around this problem by ignoring these. */
21750 if (attr
&& DW_STRING (attr
)
21751 && (startswith (DW_STRING (attr
), "._")
21752 || startswith (DW_STRING (attr
), "<anonymous")))
21755 /* GCC might emit a nameless typedef that has a linkage name. See
21756 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21757 if (!attr
|| DW_STRING (attr
) == NULL
)
21759 attr
= dw2_linkage_name_attr (die
, cu
);
21760 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21763 /* Avoid demangling DW_STRING (attr) the second time on a second
21764 call for the same DIE. */
21765 if (!DW_STRING_IS_CANONICAL (attr
))
21767 gdb::unique_xmalloc_ptr
<char> demangled
21768 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21772 /* FIXME: we already did this for the partial symbol... */
21774 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
21776 DW_STRING_IS_CANONICAL (attr
) = 1;
21778 /* Strip any leading namespaces/classes, keep only the base name.
21779 DW_AT_name for named DIEs does not contain the prefixes. */
21780 base
= strrchr (DW_STRING (attr
), ':');
21781 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21784 return DW_STRING (attr
);
21793 if (!DW_STRING_IS_CANONICAL (attr
))
21796 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21797 &objfile
->per_bfd
->storage_obstack
);
21798 DW_STRING_IS_CANONICAL (attr
) = 1;
21800 return DW_STRING (attr
);
21803 /* Return the die that this die in an extension of, or NULL if there
21804 is none. *EXT_CU is the CU containing DIE on input, and the CU
21805 containing the return value on output. */
21807 static struct die_info
*
21808 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21810 struct attribute
*attr
;
21812 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21816 return follow_die_ref (die
, attr
, ext_cu
);
21819 /* A convenience function that returns an "unknown" DWARF name,
21820 including the value of V. STR is the name of the entity being
21821 printed, e.g., "TAG". */
21823 static const char *
21824 dwarf_unknown (const char *str
, unsigned v
)
21826 char *cell
= get_print_cell ();
21827 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
21831 /* Convert a DIE tag into its string name. */
21833 static const char *
21834 dwarf_tag_name (unsigned tag
)
21836 const char *name
= get_DW_TAG_name (tag
);
21839 return dwarf_unknown ("TAG", tag
);
21844 /* Convert a DWARF attribute code into its string name. */
21846 static const char *
21847 dwarf_attr_name (unsigned attr
)
21851 #ifdef MIPS /* collides with DW_AT_HP_block_index */
21852 if (attr
== DW_AT_MIPS_fde
)
21853 return "DW_AT_MIPS_fde";
21855 if (attr
== DW_AT_HP_block_index
)
21856 return "DW_AT_HP_block_index";
21859 name
= get_DW_AT_name (attr
);
21862 return dwarf_unknown ("AT", attr
);
21867 /* Convert a DWARF value form code into its string name. */
21869 static const char *
21870 dwarf_form_name (unsigned form
)
21872 const char *name
= get_DW_FORM_name (form
);
21875 return dwarf_unknown ("FORM", form
);
21880 static const char *
21881 dwarf_bool_name (unsigned mybool
)
21889 /* Convert a DWARF type code into its string name. */
21891 static const char *
21892 dwarf_type_encoding_name (unsigned enc
)
21894 const char *name
= get_DW_ATE_name (enc
);
21897 return dwarf_unknown ("ATE", enc
);
21903 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21907 print_spaces (indent
, f
);
21908 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21909 dwarf_tag_name (die
->tag
), die
->abbrev
,
21910 sect_offset_str (die
->sect_off
));
21912 if (die
->parent
!= NULL
)
21914 print_spaces (indent
, f
);
21915 fprintf_unfiltered (f
, " parent at offset: %s\n",
21916 sect_offset_str (die
->parent
->sect_off
));
21919 print_spaces (indent
, f
);
21920 fprintf_unfiltered (f
, " has children: %s\n",
21921 dwarf_bool_name (die
->child
!= NULL
));
21923 print_spaces (indent
, f
);
21924 fprintf_unfiltered (f
, " attributes:\n");
21926 for (i
= 0; i
< die
->num_attrs
; ++i
)
21928 print_spaces (indent
, f
);
21929 fprintf_unfiltered (f
, " %s (%s) ",
21930 dwarf_attr_name (die
->attrs
[i
].name
),
21931 dwarf_form_name (die
->attrs
[i
].form
));
21933 switch (die
->attrs
[i
].form
)
21936 case DW_FORM_addrx
:
21937 case DW_FORM_GNU_addr_index
:
21938 fprintf_unfiltered (f
, "address: ");
21939 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21941 case DW_FORM_block2
:
21942 case DW_FORM_block4
:
21943 case DW_FORM_block
:
21944 case DW_FORM_block1
:
21945 fprintf_unfiltered (f
, "block: size %s",
21946 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21948 case DW_FORM_exprloc
:
21949 fprintf_unfiltered (f
, "expression: size %s",
21950 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21952 case DW_FORM_data16
:
21953 fprintf_unfiltered (f
, "constant of 16 bytes");
21955 case DW_FORM_ref_addr
:
21956 fprintf_unfiltered (f
, "ref address: ");
21957 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21959 case DW_FORM_GNU_ref_alt
:
21960 fprintf_unfiltered (f
, "alt ref address: ");
21961 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21967 case DW_FORM_ref_udata
:
21968 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21969 (long) (DW_UNSND (&die
->attrs
[i
])));
21971 case DW_FORM_data1
:
21972 case DW_FORM_data2
:
21973 case DW_FORM_data4
:
21974 case DW_FORM_data8
:
21975 case DW_FORM_udata
:
21976 case DW_FORM_sdata
:
21977 fprintf_unfiltered (f
, "constant: %s",
21978 pulongest (DW_UNSND (&die
->attrs
[i
])));
21980 case DW_FORM_sec_offset
:
21981 fprintf_unfiltered (f
, "section offset: %s",
21982 pulongest (DW_UNSND (&die
->attrs
[i
])));
21984 case DW_FORM_ref_sig8
:
21985 fprintf_unfiltered (f
, "signature: %s",
21986 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21988 case DW_FORM_string
:
21990 case DW_FORM_line_strp
:
21992 case DW_FORM_GNU_str_index
:
21993 case DW_FORM_GNU_strp_alt
:
21994 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21995 DW_STRING (&die
->attrs
[i
])
21996 ? DW_STRING (&die
->attrs
[i
]) : "",
21997 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22000 if (DW_UNSND (&die
->attrs
[i
]))
22001 fprintf_unfiltered (f
, "flag: TRUE");
22003 fprintf_unfiltered (f
, "flag: FALSE");
22005 case DW_FORM_flag_present
:
22006 fprintf_unfiltered (f
, "flag: TRUE");
22008 case DW_FORM_indirect
:
22009 /* The reader will have reduced the indirect form to
22010 the "base form" so this form should not occur. */
22011 fprintf_unfiltered (f
,
22012 "unexpected attribute form: DW_FORM_indirect");
22014 case DW_FORM_implicit_const
:
22015 fprintf_unfiltered (f
, "constant: %s",
22016 plongest (DW_SND (&die
->attrs
[i
])));
22019 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22020 die
->attrs
[i
].form
);
22023 fprintf_unfiltered (f
, "\n");
22028 dump_die_for_error (struct die_info
*die
)
22030 dump_die_shallow (gdb_stderr
, 0, die
);
22034 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22036 int indent
= level
* 4;
22038 gdb_assert (die
!= NULL
);
22040 if (level
>= max_level
)
22043 dump_die_shallow (f
, indent
, die
);
22045 if (die
->child
!= NULL
)
22047 print_spaces (indent
, f
);
22048 fprintf_unfiltered (f
, " Children:");
22049 if (level
+ 1 < max_level
)
22051 fprintf_unfiltered (f
, "\n");
22052 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22056 fprintf_unfiltered (f
,
22057 " [not printed, max nesting level reached]\n");
22061 if (die
->sibling
!= NULL
&& level
> 0)
22063 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22067 /* This is called from the pdie macro in gdbinit.in.
22068 It's not static so gcc will keep a copy callable from gdb. */
22071 dump_die (struct die_info
*die
, int max_level
)
22073 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22077 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22081 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22082 to_underlying (die
->sect_off
),
22088 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22092 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22094 if (attr
->form_is_ref ())
22095 return (sect_offset
) DW_UNSND (attr
);
22097 complaint (_("unsupported die ref attribute form: '%s'"),
22098 dwarf_form_name (attr
->form
));
22102 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22103 * the value held by the attribute is not constant. */
22106 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22108 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22109 return DW_SND (attr
);
22110 else if (attr
->form
== DW_FORM_udata
22111 || attr
->form
== DW_FORM_data1
22112 || attr
->form
== DW_FORM_data2
22113 || attr
->form
== DW_FORM_data4
22114 || attr
->form
== DW_FORM_data8
)
22115 return DW_UNSND (attr
);
22118 /* For DW_FORM_data16 see attribute::form_is_constant. */
22119 complaint (_("Attribute value is not a constant (%s)"),
22120 dwarf_form_name (attr
->form
));
22121 return default_value
;
22125 /* Follow reference or signature attribute ATTR of SRC_DIE.
22126 On entry *REF_CU is the CU of SRC_DIE.
22127 On exit *REF_CU is the CU of the result. */
22129 static struct die_info
*
22130 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22131 struct dwarf2_cu
**ref_cu
)
22133 struct die_info
*die
;
22135 if (attr
->form_is_ref ())
22136 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22137 else if (attr
->form
== DW_FORM_ref_sig8
)
22138 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22141 dump_die_for_error (src_die
);
22142 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22143 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22149 /* Follow reference OFFSET.
22150 On entry *REF_CU is the CU of the source die referencing OFFSET.
22151 On exit *REF_CU is the CU of the result.
22152 Returns NULL if OFFSET is invalid. */
22154 static struct die_info
*
22155 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22156 struct dwarf2_cu
**ref_cu
)
22158 struct die_info temp_die
;
22159 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22160 struct dwarf2_per_objfile
*dwarf2_per_objfile
22161 = cu
->per_cu
->dwarf2_per_objfile
;
22163 gdb_assert (cu
->per_cu
!= NULL
);
22167 if (cu
->per_cu
->is_debug_types
)
22169 /* .debug_types CUs cannot reference anything outside their CU.
22170 If they need to, they have to reference a signatured type via
22171 DW_FORM_ref_sig8. */
22172 if (!cu
->header
.offset_in_cu_p (sect_off
))
22175 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22176 || !cu
->header
.offset_in_cu_p (sect_off
))
22178 struct dwarf2_per_cu_data
*per_cu
;
22180 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22181 dwarf2_per_objfile
);
22183 /* If necessary, add it to the queue and load its DIEs. */
22184 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22185 load_full_comp_unit (per_cu
, false, cu
->language
);
22187 target_cu
= per_cu
->cu
;
22189 else if (cu
->dies
== NULL
)
22191 /* We're loading full DIEs during partial symbol reading. */
22192 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22193 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22196 *ref_cu
= target_cu
;
22197 temp_die
.sect_off
= sect_off
;
22199 if (target_cu
!= cu
)
22200 target_cu
->ancestor
= cu
;
22202 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22204 to_underlying (sect_off
));
22207 /* Follow reference attribute ATTR of SRC_DIE.
22208 On entry *REF_CU is the CU of SRC_DIE.
22209 On exit *REF_CU is the CU of the result. */
22211 static struct die_info
*
22212 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22213 struct dwarf2_cu
**ref_cu
)
22215 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22216 struct dwarf2_cu
*cu
= *ref_cu
;
22217 struct die_info
*die
;
22219 die
= follow_die_offset (sect_off
,
22220 (attr
->form
== DW_FORM_GNU_ref_alt
22221 || cu
->per_cu
->is_dwz
),
22224 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22225 "at %s [in module %s]"),
22226 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22227 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22232 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22233 Returned value is intended for DW_OP_call*. Returned
22234 dwarf2_locexpr_baton->data has lifetime of
22235 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22237 struct dwarf2_locexpr_baton
22238 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22239 struct dwarf2_per_cu_data
*per_cu
,
22240 CORE_ADDR (*get_frame_pc
) (void *baton
),
22241 void *baton
, bool resolve_abstract_p
)
22243 struct dwarf2_cu
*cu
;
22244 struct die_info
*die
;
22245 struct attribute
*attr
;
22246 struct dwarf2_locexpr_baton retval
;
22247 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22248 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22250 if (per_cu
->cu
== NULL
)
22251 load_cu (per_cu
, false);
22255 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22256 Instead just throw an error, not much else we can do. */
22257 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22258 sect_offset_str (sect_off
), objfile_name (objfile
));
22261 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22263 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22264 sect_offset_str (sect_off
), objfile_name (objfile
));
22266 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22267 if (!attr
&& resolve_abstract_p
22268 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
22269 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
22271 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22272 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22273 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
22275 for (const auto &cand_off
22276 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
22278 struct dwarf2_cu
*cand_cu
= cu
;
22279 struct die_info
*cand
22280 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22283 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22286 CORE_ADDR pc_low
, pc_high
;
22287 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22288 if (pc_low
== ((CORE_ADDR
) -1))
22290 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22291 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22292 if (!(pc_low
<= pc
&& pc
< pc_high
))
22296 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22303 /* DWARF: "If there is no such attribute, then there is no effect.".
22304 DATA is ignored if SIZE is 0. */
22306 retval
.data
= NULL
;
22309 else if (attr
->form_is_section_offset ())
22311 struct dwarf2_loclist_baton loclist_baton
;
22312 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22315 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22317 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22319 retval
.size
= size
;
22323 if (!attr
->form_is_block ())
22324 error (_("Dwarf Error: DIE at %s referenced in module %s "
22325 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22326 sect_offset_str (sect_off
), objfile_name (objfile
));
22328 retval
.data
= DW_BLOCK (attr
)->data
;
22329 retval
.size
= DW_BLOCK (attr
)->size
;
22331 retval
.per_cu
= cu
->per_cu
;
22333 age_cached_comp_units (dwarf2_per_objfile
);
22338 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
22341 struct dwarf2_locexpr_baton
22342 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22343 struct dwarf2_per_cu_data
*per_cu
,
22344 CORE_ADDR (*get_frame_pc
) (void *baton
),
22347 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22349 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22352 /* Write a constant of a given type as target-ordered bytes into
22355 static const gdb_byte
*
22356 write_constant_as_bytes (struct obstack
*obstack
,
22357 enum bfd_endian byte_order
,
22364 *len
= TYPE_LENGTH (type
);
22365 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22366 store_unsigned_integer (result
, *len
, byte_order
, value
);
22371 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
22372 pointer to the constant bytes and set LEN to the length of the
22373 data. If memory is needed, allocate it on OBSTACK. If the DIE
22374 does not have a DW_AT_const_value, return NULL. */
22377 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22378 struct dwarf2_per_cu_data
*per_cu
,
22379 struct obstack
*obstack
,
22382 struct dwarf2_cu
*cu
;
22383 struct die_info
*die
;
22384 struct attribute
*attr
;
22385 const gdb_byte
*result
= NULL
;
22388 enum bfd_endian byte_order
;
22389 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22391 if (per_cu
->cu
== NULL
)
22392 load_cu (per_cu
, false);
22396 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22397 Instead just throw an error, not much else we can do. */
22398 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22399 sect_offset_str (sect_off
), objfile_name (objfile
));
22402 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22404 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22405 sect_offset_str (sect_off
), objfile_name (objfile
));
22407 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22411 byte_order
= (bfd_big_endian (objfile
->obfd
)
22412 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22414 switch (attr
->form
)
22417 case DW_FORM_addrx
:
22418 case DW_FORM_GNU_addr_index
:
22422 *len
= cu
->header
.addr_size
;
22423 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22424 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22428 case DW_FORM_string
:
22431 case DW_FORM_GNU_str_index
:
22432 case DW_FORM_GNU_strp_alt
:
22433 /* DW_STRING is already allocated on the objfile obstack, point
22435 result
= (const gdb_byte
*) DW_STRING (attr
);
22436 *len
= strlen (DW_STRING (attr
));
22438 case DW_FORM_block1
:
22439 case DW_FORM_block2
:
22440 case DW_FORM_block4
:
22441 case DW_FORM_block
:
22442 case DW_FORM_exprloc
:
22443 case DW_FORM_data16
:
22444 result
= DW_BLOCK (attr
)->data
;
22445 *len
= DW_BLOCK (attr
)->size
;
22448 /* The DW_AT_const_value attributes are supposed to carry the
22449 symbol's value "represented as it would be on the target
22450 architecture." By the time we get here, it's already been
22451 converted to host endianness, so we just need to sign- or
22452 zero-extend it as appropriate. */
22453 case DW_FORM_data1
:
22454 type
= die_type (die
, cu
);
22455 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22456 if (result
== NULL
)
22457 result
= write_constant_as_bytes (obstack
, byte_order
,
22460 case DW_FORM_data2
:
22461 type
= die_type (die
, cu
);
22462 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22463 if (result
== NULL
)
22464 result
= write_constant_as_bytes (obstack
, byte_order
,
22467 case DW_FORM_data4
:
22468 type
= die_type (die
, cu
);
22469 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22470 if (result
== NULL
)
22471 result
= write_constant_as_bytes (obstack
, byte_order
,
22474 case DW_FORM_data8
:
22475 type
= die_type (die
, cu
);
22476 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22477 if (result
== NULL
)
22478 result
= write_constant_as_bytes (obstack
, byte_order
,
22482 case DW_FORM_sdata
:
22483 case DW_FORM_implicit_const
:
22484 type
= die_type (die
, cu
);
22485 result
= write_constant_as_bytes (obstack
, byte_order
,
22486 type
, DW_SND (attr
), len
);
22489 case DW_FORM_udata
:
22490 type
= die_type (die
, cu
);
22491 result
= write_constant_as_bytes (obstack
, byte_order
,
22492 type
, DW_UNSND (attr
), len
);
22496 complaint (_("unsupported const value attribute form: '%s'"),
22497 dwarf_form_name (attr
->form
));
22504 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
22505 valid type for this die is found. */
22508 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22509 struct dwarf2_per_cu_data
*per_cu
)
22511 struct dwarf2_cu
*cu
;
22512 struct die_info
*die
;
22514 if (per_cu
->cu
== NULL
)
22515 load_cu (per_cu
, false);
22520 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22524 return die_type (die
, cu
);
22527 /* Return the type of the DIE at DIE_OFFSET in the CU named by
22531 dwarf2_get_die_type (cu_offset die_offset
,
22532 struct dwarf2_per_cu_data
*per_cu
)
22534 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22535 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22538 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22539 On entry *REF_CU is the CU of SRC_DIE.
22540 On exit *REF_CU is the CU of the result.
22541 Returns NULL if the referenced DIE isn't found. */
22543 static struct die_info
*
22544 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22545 struct dwarf2_cu
**ref_cu
)
22547 struct die_info temp_die
;
22548 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22549 struct die_info
*die
;
22551 /* While it might be nice to assert sig_type->type == NULL here,
22552 we can get here for DW_AT_imported_declaration where we need
22553 the DIE not the type. */
22555 /* If necessary, add it to the queue and load its DIEs. */
22557 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22558 read_signatured_type (sig_type
);
22560 sig_cu
= sig_type
->per_cu
.cu
;
22561 gdb_assert (sig_cu
!= NULL
);
22562 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22563 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22564 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22565 to_underlying (temp_die
.sect_off
));
22568 struct dwarf2_per_objfile
*dwarf2_per_objfile
22569 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22571 /* For .gdb_index version 7 keep track of included TUs.
22572 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22573 if (dwarf2_per_objfile
->index_table
!= NULL
22574 && dwarf2_per_objfile
->index_table
->version
<= 7)
22576 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22581 sig_cu
->ancestor
= cu
;
22589 /* Follow signatured type referenced by ATTR in SRC_DIE.
22590 On entry *REF_CU is the CU of SRC_DIE.
22591 On exit *REF_CU is the CU of the result.
22592 The result is the DIE of the type.
22593 If the referenced type cannot be found an error is thrown. */
22595 static struct die_info
*
22596 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22597 struct dwarf2_cu
**ref_cu
)
22599 ULONGEST signature
= DW_SIGNATURE (attr
);
22600 struct signatured_type
*sig_type
;
22601 struct die_info
*die
;
22603 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22605 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22606 /* sig_type will be NULL if the signatured type is missing from
22608 if (sig_type
== NULL
)
22610 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22611 " from DIE at %s [in module %s]"),
22612 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22613 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22616 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22619 dump_die_for_error (src_die
);
22620 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22621 " from DIE at %s [in module %s]"),
22622 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22623 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22629 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22630 reading in and processing the type unit if necessary. */
22632 static struct type
*
22633 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22634 struct dwarf2_cu
*cu
)
22636 struct dwarf2_per_objfile
*dwarf2_per_objfile
22637 = cu
->per_cu
->dwarf2_per_objfile
;
22638 struct signatured_type
*sig_type
;
22639 struct dwarf2_cu
*type_cu
;
22640 struct die_info
*type_die
;
22643 sig_type
= lookup_signatured_type (cu
, signature
);
22644 /* sig_type will be NULL if the signatured type is missing from
22646 if (sig_type
== NULL
)
22648 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22649 " from DIE at %s [in module %s]"),
22650 hex_string (signature
), sect_offset_str (die
->sect_off
),
22651 objfile_name (dwarf2_per_objfile
->objfile
));
22652 return build_error_marker_type (cu
, die
);
22655 /* If we already know the type we're done. */
22656 if (sig_type
->type
!= NULL
)
22657 return sig_type
->type
;
22660 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22661 if (type_die
!= NULL
)
22663 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22664 is created. This is important, for example, because for c++ classes
22665 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22666 type
= read_type_die (type_die
, type_cu
);
22669 complaint (_("Dwarf Error: Cannot build signatured type %s"
22670 " referenced from DIE at %s [in module %s]"),
22671 hex_string (signature
), sect_offset_str (die
->sect_off
),
22672 objfile_name (dwarf2_per_objfile
->objfile
));
22673 type
= build_error_marker_type (cu
, die
);
22678 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22679 " from DIE at %s [in module %s]"),
22680 hex_string (signature
), sect_offset_str (die
->sect_off
),
22681 objfile_name (dwarf2_per_objfile
->objfile
));
22682 type
= build_error_marker_type (cu
, die
);
22684 sig_type
->type
= type
;
22689 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22690 reading in and processing the type unit if necessary. */
22692 static struct type
*
22693 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22694 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22696 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22697 if (attr
->form_is_ref ())
22699 struct dwarf2_cu
*type_cu
= cu
;
22700 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22702 return read_type_die (type_die
, type_cu
);
22704 else if (attr
->form
== DW_FORM_ref_sig8
)
22706 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22710 struct dwarf2_per_objfile
*dwarf2_per_objfile
22711 = cu
->per_cu
->dwarf2_per_objfile
;
22713 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22714 " at %s [in module %s]"),
22715 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22716 objfile_name (dwarf2_per_objfile
->objfile
));
22717 return build_error_marker_type (cu
, die
);
22721 /* Load the DIEs associated with type unit PER_CU into memory. */
22724 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22726 struct signatured_type
*sig_type
;
22728 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22729 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
22731 /* We have the per_cu, but we need the signatured_type.
22732 Fortunately this is an easy translation. */
22733 gdb_assert (per_cu
->is_debug_types
);
22734 sig_type
= (struct signatured_type
*) per_cu
;
22736 gdb_assert (per_cu
->cu
== NULL
);
22738 read_signatured_type (sig_type
);
22740 gdb_assert (per_cu
->cu
!= NULL
);
22743 /* Read in a signatured type and build its CU and DIEs.
22744 If the type is a stub for the real type in a DWO file,
22745 read in the real type from the DWO file as well. */
22748 read_signatured_type (struct signatured_type
*sig_type
)
22750 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22752 gdb_assert (per_cu
->is_debug_types
);
22753 gdb_assert (per_cu
->cu
== NULL
);
22755 cutu_reader
reader (per_cu
, NULL
, 0, 1, false);
22757 if (!reader
.dummy_p
)
22759 struct dwarf2_cu
*cu
= reader
.cu
;
22760 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22762 gdb_assert (cu
->die_hash
== NULL
);
22764 htab_create_alloc_ex (cu
->header
.length
/ 12,
22768 &cu
->comp_unit_obstack
,
22769 hashtab_obstack_allocate
,
22770 dummy_obstack_deallocate
);
22772 if (reader
.comp_unit_die
->has_children
)
22773 reader
.comp_unit_die
->child
22774 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22775 reader
.comp_unit_die
);
22776 cu
->dies
= reader
.comp_unit_die
;
22777 /* comp_unit_die is not stored in die_hash, no need. */
22779 /* We try not to read any attributes in this function, because
22780 not all CUs needed for references have been loaded yet, and
22781 symbol table processing isn't initialized. But we have to
22782 set the CU language, or we won't be able to build types
22783 correctly. Similarly, if we do not read the producer, we can
22784 not apply producer-specific interpretation. */
22785 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22788 sig_type
->per_cu
.tu_read
= 1;
22791 /* Decode simple location descriptions.
22792 Given a pointer to a dwarf block that defines a location, compute
22793 the location and return the value.
22795 NOTE drow/2003-11-18: This function is called in two situations
22796 now: for the address of static or global variables (partial symbols
22797 only) and for offsets into structures which are expected to be
22798 (more or less) constant. The partial symbol case should go away,
22799 and only the constant case should remain. That will let this
22800 function complain more accurately. A few special modes are allowed
22801 without complaint for global variables (for instance, global
22802 register values and thread-local values).
22804 A location description containing no operations indicates that the
22805 object is optimized out. The return value is 0 for that case.
22806 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22807 callers will only want a very basic result and this can become a
22810 Note that stack[0] is unused except as a default error return. */
22813 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22815 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22817 size_t size
= blk
->size
;
22818 const gdb_byte
*data
= blk
->data
;
22819 CORE_ADDR stack
[64];
22821 unsigned int bytes_read
, unsnd
;
22827 stack
[++stacki
] = 0;
22866 stack
[++stacki
] = op
- DW_OP_lit0
;
22901 stack
[++stacki
] = op
- DW_OP_reg0
;
22903 dwarf2_complex_location_expr_complaint ();
22907 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22909 stack
[++stacki
] = unsnd
;
22911 dwarf2_complex_location_expr_complaint ();
22915 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22920 case DW_OP_const1u
:
22921 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22925 case DW_OP_const1s
:
22926 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22930 case DW_OP_const2u
:
22931 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22935 case DW_OP_const2s
:
22936 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22940 case DW_OP_const4u
:
22941 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22945 case DW_OP_const4s
:
22946 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22950 case DW_OP_const8u
:
22951 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22956 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22962 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22967 stack
[stacki
+ 1] = stack
[stacki
];
22972 stack
[stacki
- 1] += stack
[stacki
];
22976 case DW_OP_plus_uconst
:
22977 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22983 stack
[stacki
- 1] -= stack
[stacki
];
22988 /* If we're not the last op, then we definitely can't encode
22989 this using GDB's address_class enum. This is valid for partial
22990 global symbols, although the variable's address will be bogus
22993 dwarf2_complex_location_expr_complaint ();
22996 case DW_OP_GNU_push_tls_address
:
22997 case DW_OP_form_tls_address
:
22998 /* The top of the stack has the offset from the beginning
22999 of the thread control block at which the variable is located. */
23000 /* Nothing should follow this operator, so the top of stack would
23002 /* This is valid for partial global symbols, but the variable's
23003 address will be bogus in the psymtab. Make it always at least
23004 non-zero to not look as a variable garbage collected by linker
23005 which have DW_OP_addr 0. */
23007 dwarf2_complex_location_expr_complaint ();
23011 case DW_OP_GNU_uninit
:
23015 case DW_OP_GNU_addr_index
:
23016 case DW_OP_GNU_const_index
:
23017 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23024 const char *name
= get_DW_OP_name (op
);
23027 complaint (_("unsupported stack op: '%s'"),
23030 complaint (_("unsupported stack op: '%02x'"),
23034 return (stack
[stacki
]);
23037 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23038 outside of the allocated space. Also enforce minimum>0. */
23039 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23041 complaint (_("location description stack overflow"));
23047 complaint (_("location description stack underflow"));
23051 return (stack
[stacki
]);
23054 /* memory allocation interface */
23056 static struct dwarf_block
*
23057 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23059 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23062 static struct die_info
*
23063 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23065 struct die_info
*die
;
23066 size_t size
= sizeof (struct die_info
);
23069 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23071 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23072 memset (die
, 0, sizeof (struct die_info
));
23077 /* Macro support. */
23079 static struct macro_source_file
*
23080 macro_start_file (struct dwarf2_cu
*cu
,
23081 int file
, int line
,
23082 struct macro_source_file
*current_file
,
23083 struct line_header
*lh
)
23085 /* File name relative to the compilation directory of this source file. */
23086 gdb::unique_xmalloc_ptr
<char> file_name
= lh
->file_file_name (file
);
23088 if (! current_file
)
23090 /* Note: We don't create a macro table for this compilation unit
23091 at all until we actually get a filename. */
23092 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
23094 /* If we have no current file, then this must be the start_file
23095 directive for the compilation unit's main source file. */
23096 current_file
= macro_set_main (macro_table
, file_name
.get ());
23097 macro_define_special (macro_table
);
23100 current_file
= macro_include (current_file
, line
, file_name
.get ());
23102 return current_file
;
23105 static const char *
23106 consume_improper_spaces (const char *p
, const char *body
)
23110 complaint (_("macro definition contains spaces "
23111 "in formal argument list:\n`%s'"),
23123 parse_macro_definition (struct macro_source_file
*file
, int line
,
23128 /* The body string takes one of two forms. For object-like macro
23129 definitions, it should be:
23131 <macro name> " " <definition>
23133 For function-like macro definitions, it should be:
23135 <macro name> "() " <definition>
23137 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23139 Spaces may appear only where explicitly indicated, and in the
23142 The Dwarf 2 spec says that an object-like macro's name is always
23143 followed by a space, but versions of GCC around March 2002 omit
23144 the space when the macro's definition is the empty string.
23146 The Dwarf 2 spec says that there should be no spaces between the
23147 formal arguments in a function-like macro's formal argument list,
23148 but versions of GCC around March 2002 include spaces after the
23152 /* Find the extent of the macro name. The macro name is terminated
23153 by either a space or null character (for an object-like macro) or
23154 an opening paren (for a function-like macro). */
23155 for (p
= body
; *p
; p
++)
23156 if (*p
== ' ' || *p
== '(')
23159 if (*p
== ' ' || *p
== '\0')
23161 /* It's an object-like macro. */
23162 int name_len
= p
- body
;
23163 std::string
name (body
, name_len
);
23164 const char *replacement
;
23167 replacement
= body
+ name_len
+ 1;
23170 dwarf2_macro_malformed_definition_complaint (body
);
23171 replacement
= body
+ name_len
;
23174 macro_define_object (file
, line
, name
.c_str (), replacement
);
23176 else if (*p
== '(')
23178 /* It's a function-like macro. */
23179 std::string
name (body
, p
- body
);
23182 char **argv
= XNEWVEC (char *, argv_size
);
23186 p
= consume_improper_spaces (p
, body
);
23188 /* Parse the formal argument list. */
23189 while (*p
&& *p
!= ')')
23191 /* Find the extent of the current argument name. */
23192 const char *arg_start
= p
;
23194 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23197 if (! *p
|| p
== arg_start
)
23198 dwarf2_macro_malformed_definition_complaint (body
);
23201 /* Make sure argv has room for the new argument. */
23202 if (argc
>= argv_size
)
23205 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23208 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23211 p
= consume_improper_spaces (p
, body
);
23213 /* Consume the comma, if present. */
23218 p
= consume_improper_spaces (p
, body
);
23227 /* Perfectly formed definition, no complaints. */
23228 macro_define_function (file
, line
, name
.c_str (),
23229 argc
, (const char **) argv
,
23231 else if (*p
== '\0')
23233 /* Complain, but do define it. */
23234 dwarf2_macro_malformed_definition_complaint (body
);
23235 macro_define_function (file
, line
, name
.c_str (),
23236 argc
, (const char **) argv
,
23240 /* Just complain. */
23241 dwarf2_macro_malformed_definition_complaint (body
);
23244 /* Just complain. */
23245 dwarf2_macro_malformed_definition_complaint (body
);
23250 for (i
= 0; i
< argc
; i
++)
23256 dwarf2_macro_malformed_definition_complaint (body
);
23259 /* Skip some bytes from BYTES according to the form given in FORM.
23260 Returns the new pointer. */
23262 static const gdb_byte
*
23263 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
23264 enum dwarf_form form
,
23265 unsigned int offset_size
,
23266 struct dwarf2_section_info
*section
)
23268 unsigned int bytes_read
;
23272 case DW_FORM_data1
:
23277 case DW_FORM_data2
:
23281 case DW_FORM_data4
:
23285 case DW_FORM_data8
:
23289 case DW_FORM_data16
:
23293 case DW_FORM_string
:
23294 read_direct_string (abfd
, bytes
, &bytes_read
);
23295 bytes
+= bytes_read
;
23298 case DW_FORM_sec_offset
:
23300 case DW_FORM_GNU_strp_alt
:
23301 bytes
+= offset_size
;
23304 case DW_FORM_block
:
23305 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
23306 bytes
+= bytes_read
;
23309 case DW_FORM_block1
:
23310 bytes
+= 1 + read_1_byte (abfd
, bytes
);
23312 case DW_FORM_block2
:
23313 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
23315 case DW_FORM_block4
:
23316 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
23319 case DW_FORM_addrx
:
23320 case DW_FORM_sdata
:
23322 case DW_FORM_udata
:
23323 case DW_FORM_GNU_addr_index
:
23324 case DW_FORM_GNU_str_index
:
23325 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
23328 dwarf2_section_buffer_overflow_complaint (section
);
23333 case DW_FORM_implicit_const
:
23338 complaint (_("invalid form 0x%x in `%s'"),
23339 form
, section
->get_name ());
23347 /* A helper for dwarf_decode_macros that handles skipping an unknown
23348 opcode. Returns an updated pointer to the macro data buffer; or,
23349 on error, issues a complaint and returns NULL. */
23351 static const gdb_byte
*
23352 skip_unknown_opcode (unsigned int opcode
,
23353 const gdb_byte
**opcode_definitions
,
23354 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23356 unsigned int offset_size
,
23357 struct dwarf2_section_info
*section
)
23359 unsigned int bytes_read
, i
;
23361 const gdb_byte
*defn
;
23363 if (opcode_definitions
[opcode
] == NULL
)
23365 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
23370 defn
= opcode_definitions
[opcode
];
23371 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
23372 defn
+= bytes_read
;
23374 for (i
= 0; i
< arg
; ++i
)
23376 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
23377 (enum dwarf_form
) defn
[i
], offset_size
,
23379 if (mac_ptr
== NULL
)
23381 /* skip_form_bytes already issued the complaint. */
23389 /* A helper function which parses the header of a macro section.
23390 If the macro section is the extended (for now called "GNU") type,
23391 then this updates *OFFSET_SIZE. Returns a pointer to just after
23392 the header, or issues a complaint and returns NULL on error. */
23394 static const gdb_byte
*
23395 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
23397 const gdb_byte
*mac_ptr
,
23398 unsigned int *offset_size
,
23399 int section_is_gnu
)
23401 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
23403 if (section_is_gnu
)
23405 unsigned int version
, flags
;
23407 version
= read_2_bytes (abfd
, mac_ptr
);
23408 if (version
!= 4 && version
!= 5)
23410 complaint (_("unrecognized version `%d' in .debug_macro section"),
23416 flags
= read_1_byte (abfd
, mac_ptr
);
23418 *offset_size
= (flags
& 1) ? 8 : 4;
23420 if ((flags
& 2) != 0)
23421 /* We don't need the line table offset. */
23422 mac_ptr
+= *offset_size
;
23424 /* Vendor opcode descriptions. */
23425 if ((flags
& 4) != 0)
23427 unsigned int i
, count
;
23429 count
= read_1_byte (abfd
, mac_ptr
);
23431 for (i
= 0; i
< count
; ++i
)
23433 unsigned int opcode
, bytes_read
;
23436 opcode
= read_1_byte (abfd
, mac_ptr
);
23438 opcode_definitions
[opcode
] = mac_ptr
;
23439 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23440 mac_ptr
+= bytes_read
;
23449 /* A helper for dwarf_decode_macros that handles the GNU extensions,
23450 including DW_MACRO_import. */
23453 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
23455 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23456 struct macro_source_file
*current_file
,
23457 struct line_header
*lh
,
23458 struct dwarf2_section_info
*section
,
23459 int section_is_gnu
, int section_is_dwz
,
23460 unsigned int offset_size
,
23461 htab_t include_hash
)
23463 struct dwarf2_per_objfile
*dwarf2_per_objfile
23464 = cu
->per_cu
->dwarf2_per_objfile
;
23465 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23466 enum dwarf_macro_record_type macinfo_type
;
23467 int at_commandline
;
23468 const gdb_byte
*opcode_definitions
[256];
23470 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23471 &offset_size
, section_is_gnu
);
23472 if (mac_ptr
== NULL
)
23474 /* We already issued a complaint. */
23478 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
23479 GDB is still reading the definitions from command line. First
23480 DW_MACINFO_start_file will need to be ignored as it was already executed
23481 to create CURRENT_FILE for the main source holding also the command line
23482 definitions. On first met DW_MACINFO_start_file this flag is reset to
23483 normally execute all the remaining DW_MACINFO_start_file macinfos. */
23485 at_commandline
= 1;
23489 /* Do we at least have room for a macinfo type byte? */
23490 if (mac_ptr
>= mac_end
)
23492 dwarf2_section_buffer_overflow_complaint (section
);
23496 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23499 /* Note that we rely on the fact that the corresponding GNU and
23500 DWARF constants are the same. */
23502 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23503 switch (macinfo_type
)
23505 /* A zero macinfo type indicates the end of the macro
23510 case DW_MACRO_define
:
23511 case DW_MACRO_undef
:
23512 case DW_MACRO_define_strp
:
23513 case DW_MACRO_undef_strp
:
23514 case DW_MACRO_define_sup
:
23515 case DW_MACRO_undef_sup
:
23517 unsigned int bytes_read
;
23522 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23523 mac_ptr
+= bytes_read
;
23525 if (macinfo_type
== DW_MACRO_define
23526 || macinfo_type
== DW_MACRO_undef
)
23528 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23529 mac_ptr
+= bytes_read
;
23533 LONGEST str_offset
;
23535 str_offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23536 mac_ptr
+= offset_size
;
23538 if (macinfo_type
== DW_MACRO_define_sup
23539 || macinfo_type
== DW_MACRO_undef_sup
23542 struct dwz_file
*dwz
23543 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
23545 body
= read_indirect_string_from_dwz (objfile
,
23549 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
23553 is_define
= (macinfo_type
== DW_MACRO_define
23554 || macinfo_type
== DW_MACRO_define_strp
23555 || macinfo_type
== DW_MACRO_define_sup
);
23556 if (! current_file
)
23558 /* DWARF violation as no main source is present. */
23559 complaint (_("debug info with no main source gives macro %s "
23561 is_define
? _("definition") : _("undefinition"),
23565 if ((line
== 0 && !at_commandline
)
23566 || (line
!= 0 && at_commandline
))
23567 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
23568 at_commandline
? _("command-line") : _("in-file"),
23569 is_define
? _("definition") : _("undefinition"),
23570 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
23574 /* Fedora's rpm-build's "debugedit" binary
23575 corrupted .debug_macro sections.
23578 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
23579 complaint (_("debug info gives %s invalid macro %s "
23580 "without body (corrupted?) at line %d "
23582 at_commandline
? _("command-line") : _("in-file"),
23583 is_define
? _("definition") : _("undefinition"),
23584 line
, current_file
->filename
);
23586 else if (is_define
)
23587 parse_macro_definition (current_file
, line
, body
);
23590 gdb_assert (macinfo_type
== DW_MACRO_undef
23591 || macinfo_type
== DW_MACRO_undef_strp
23592 || macinfo_type
== DW_MACRO_undef_sup
);
23593 macro_undef (current_file
, line
, body
);
23598 case DW_MACRO_start_file
:
23600 unsigned int bytes_read
;
23603 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23604 mac_ptr
+= bytes_read
;
23605 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23606 mac_ptr
+= bytes_read
;
23608 if ((line
== 0 && !at_commandline
)
23609 || (line
!= 0 && at_commandline
))
23610 complaint (_("debug info gives source %d included "
23611 "from %s at %s line %d"),
23612 file
, at_commandline
? _("command-line") : _("file"),
23613 line
== 0 ? _("zero") : _("non-zero"), line
);
23615 if (at_commandline
)
23617 /* This DW_MACRO_start_file was executed in the
23619 at_commandline
= 0;
23622 current_file
= macro_start_file (cu
, file
, line
, current_file
,
23627 case DW_MACRO_end_file
:
23628 if (! current_file
)
23629 complaint (_("macro debug info has an unmatched "
23630 "`close_file' directive"));
23633 current_file
= current_file
->included_by
;
23634 if (! current_file
)
23636 enum dwarf_macro_record_type next_type
;
23638 /* GCC circa March 2002 doesn't produce the zero
23639 type byte marking the end of the compilation
23640 unit. Complain if it's not there, but exit no
23643 /* Do we at least have room for a macinfo type byte? */
23644 if (mac_ptr
>= mac_end
)
23646 dwarf2_section_buffer_overflow_complaint (section
);
23650 /* We don't increment mac_ptr here, so this is just
23653 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
23655 if (next_type
!= 0)
23656 complaint (_("no terminating 0-type entry for "
23657 "macros in `.debug_macinfo' section"));
23664 case DW_MACRO_import
:
23665 case DW_MACRO_import_sup
:
23669 bfd
*include_bfd
= abfd
;
23670 struct dwarf2_section_info
*include_section
= section
;
23671 const gdb_byte
*include_mac_end
= mac_end
;
23672 int is_dwz
= section_is_dwz
;
23673 const gdb_byte
*new_mac_ptr
;
23675 offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23676 mac_ptr
+= offset_size
;
23678 if (macinfo_type
== DW_MACRO_import_sup
)
23680 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
23682 dwz
->macro
.read (objfile
);
23684 include_section
= &dwz
->macro
;
23685 include_bfd
= include_section
->get_bfd_owner ();
23686 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
23690 new_mac_ptr
= include_section
->buffer
+ offset
;
23691 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
23695 /* This has actually happened; see
23696 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
23697 complaint (_("recursive DW_MACRO_import in "
23698 ".debug_macro section"));
23702 *slot
= (void *) new_mac_ptr
;
23704 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
23705 include_mac_end
, current_file
, lh
,
23706 section
, section_is_gnu
, is_dwz
,
23707 offset_size
, include_hash
);
23709 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
23714 case DW_MACINFO_vendor_ext
:
23715 if (!section_is_gnu
)
23717 unsigned int bytes_read
;
23719 /* This reads the constant, but since we don't recognize
23720 any vendor extensions, we ignore it. */
23721 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23722 mac_ptr
+= bytes_read
;
23723 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23724 mac_ptr
+= bytes_read
;
23726 /* We don't recognize any vendor extensions. */
23732 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23733 mac_ptr
, mac_end
, abfd
, offset_size
,
23735 if (mac_ptr
== NULL
)
23740 } while (macinfo_type
!= 0);
23744 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23745 int section_is_gnu
)
23747 struct dwarf2_per_objfile
*dwarf2_per_objfile
23748 = cu
->per_cu
->dwarf2_per_objfile
;
23749 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23750 struct line_header
*lh
= cu
->line_header
;
23752 const gdb_byte
*mac_ptr
, *mac_end
;
23753 struct macro_source_file
*current_file
= 0;
23754 enum dwarf_macro_record_type macinfo_type
;
23755 unsigned int offset_size
= cu
->header
.offset_size
;
23756 const gdb_byte
*opcode_definitions
[256];
23758 struct dwarf2_section_info
*section
;
23759 const char *section_name
;
23761 if (cu
->dwo_unit
!= NULL
)
23763 if (section_is_gnu
)
23765 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23766 section_name
= ".debug_macro.dwo";
23770 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23771 section_name
= ".debug_macinfo.dwo";
23776 if (section_is_gnu
)
23778 section
= &dwarf2_per_objfile
->macro
;
23779 section_name
= ".debug_macro";
23783 section
= &dwarf2_per_objfile
->macinfo
;
23784 section_name
= ".debug_macinfo";
23788 section
->read (objfile
);
23789 if (section
->buffer
== NULL
)
23791 complaint (_("missing %s section"), section_name
);
23794 abfd
= section
->get_bfd_owner ();
23796 /* First pass: Find the name of the base filename.
23797 This filename is needed in order to process all macros whose definition
23798 (or undefinition) comes from the command line. These macros are defined
23799 before the first DW_MACINFO_start_file entry, and yet still need to be
23800 associated to the base file.
23802 To determine the base file name, we scan the macro definitions until we
23803 reach the first DW_MACINFO_start_file entry. We then initialize
23804 CURRENT_FILE accordingly so that any macro definition found before the
23805 first DW_MACINFO_start_file can still be associated to the base file. */
23807 mac_ptr
= section
->buffer
+ offset
;
23808 mac_end
= section
->buffer
+ section
->size
;
23810 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23811 &offset_size
, section_is_gnu
);
23812 if (mac_ptr
== NULL
)
23814 /* We already issued a complaint. */
23820 /* Do we at least have room for a macinfo type byte? */
23821 if (mac_ptr
>= mac_end
)
23823 /* Complaint is printed during the second pass as GDB will probably
23824 stop the first pass earlier upon finding
23825 DW_MACINFO_start_file. */
23829 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23832 /* Note that we rely on the fact that the corresponding GNU and
23833 DWARF constants are the same. */
23835 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23836 switch (macinfo_type
)
23838 /* A zero macinfo type indicates the end of the macro
23843 case DW_MACRO_define
:
23844 case DW_MACRO_undef
:
23845 /* Only skip the data by MAC_PTR. */
23847 unsigned int bytes_read
;
23849 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23850 mac_ptr
+= bytes_read
;
23851 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23852 mac_ptr
+= bytes_read
;
23856 case DW_MACRO_start_file
:
23858 unsigned int bytes_read
;
23861 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23862 mac_ptr
+= bytes_read
;
23863 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23864 mac_ptr
+= bytes_read
;
23866 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
23870 case DW_MACRO_end_file
:
23871 /* No data to skip by MAC_PTR. */
23874 case DW_MACRO_define_strp
:
23875 case DW_MACRO_undef_strp
:
23876 case DW_MACRO_define_sup
:
23877 case DW_MACRO_undef_sup
:
23879 unsigned int bytes_read
;
23881 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23882 mac_ptr
+= bytes_read
;
23883 mac_ptr
+= offset_size
;
23887 case DW_MACRO_import
:
23888 case DW_MACRO_import_sup
:
23889 /* Note that, according to the spec, a transparent include
23890 chain cannot call DW_MACRO_start_file. So, we can just
23891 skip this opcode. */
23892 mac_ptr
+= offset_size
;
23895 case DW_MACINFO_vendor_ext
:
23896 /* Only skip the data by MAC_PTR. */
23897 if (!section_is_gnu
)
23899 unsigned int bytes_read
;
23901 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23902 mac_ptr
+= bytes_read
;
23903 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23904 mac_ptr
+= bytes_read
;
23909 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23910 mac_ptr
, mac_end
, abfd
, offset_size
,
23912 if (mac_ptr
== NULL
)
23917 } while (macinfo_type
!= 0 && current_file
== NULL
);
23919 /* Second pass: Process all entries.
23921 Use the AT_COMMAND_LINE flag to determine whether we are still processing
23922 command-line macro definitions/undefinitions. This flag is unset when we
23923 reach the first DW_MACINFO_start_file entry. */
23925 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
23927 NULL
, xcalloc
, xfree
));
23928 mac_ptr
= section
->buffer
+ offset
;
23929 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
23930 *slot
= (void *) mac_ptr
;
23931 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
23932 current_file
, lh
, section
,
23933 section_is_gnu
, 0, offset_size
,
23934 include_hash
.get ());
23937 /* Return the .debug_loc section to use for CU.
23938 For DWO files use .debug_loc.dwo. */
23940 static struct dwarf2_section_info
*
23941 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23943 struct dwarf2_per_objfile
*dwarf2_per_objfile
23944 = cu
->per_cu
->dwarf2_per_objfile
;
23948 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23950 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23952 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
23953 : &dwarf2_per_objfile
->loc
);
23956 /* A helper function that fills in a dwarf2_loclist_baton. */
23959 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23960 struct dwarf2_loclist_baton
*baton
,
23961 const struct attribute
*attr
)
23963 struct dwarf2_per_objfile
*dwarf2_per_objfile
23964 = cu
->per_cu
->dwarf2_per_objfile
;
23965 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23967 section
->read (dwarf2_per_objfile
->objfile
);
23969 baton
->per_cu
= cu
->per_cu
;
23970 gdb_assert (baton
->per_cu
);
23971 /* We don't know how long the location list is, but make sure we
23972 don't run off the edge of the section. */
23973 baton
->size
= section
->size
- DW_UNSND (attr
);
23974 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23975 baton
->base_address
= cu
->base_address
;
23976 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23980 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23981 struct dwarf2_cu
*cu
, int is_block
)
23983 struct dwarf2_per_objfile
*dwarf2_per_objfile
23984 = cu
->per_cu
->dwarf2_per_objfile
;
23985 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23986 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23988 if (attr
->form_is_section_offset ()
23989 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23990 the section. If so, fall through to the complaint in the
23992 && DW_UNSND (attr
) < section
->get_size (objfile
))
23994 struct dwarf2_loclist_baton
*baton
;
23996 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23998 fill_in_loclist_baton (cu
, baton
, attr
);
24000 if (cu
->base_known
== 0)
24001 complaint (_("Location list used without "
24002 "specifying the CU base address."));
24004 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24005 ? dwarf2_loclist_block_index
24006 : dwarf2_loclist_index
);
24007 SYMBOL_LOCATION_BATON (sym
) = baton
;
24011 struct dwarf2_locexpr_baton
*baton
;
24013 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24014 baton
->per_cu
= cu
->per_cu
;
24015 gdb_assert (baton
->per_cu
);
24017 if (attr
->form_is_block ())
24019 /* Note that we're just copying the block's data pointer
24020 here, not the actual data. We're still pointing into the
24021 info_buffer for SYM's objfile; right now we never release
24022 that buffer, but when we do clean up properly this may
24024 baton
->size
= DW_BLOCK (attr
)->size
;
24025 baton
->data
= DW_BLOCK (attr
)->data
;
24029 dwarf2_invalid_attrib_class_complaint ("location description",
24030 sym
->natural_name ());
24034 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24035 ? dwarf2_locexpr_block_index
24036 : dwarf2_locexpr_index
);
24037 SYMBOL_LOCATION_BATON (sym
) = baton
;
24044 dwarf2_per_cu_data::objfile () const
24046 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24048 /* Return the master objfile, so that we can report and look up the
24049 correct file containing this variable. */
24050 if (objfile
->separate_debug_objfile_backlink
)
24051 objfile
= objfile
->separate_debug_objfile_backlink
;
24056 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24057 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24058 CU_HEADERP first. */
24060 static const struct comp_unit_head
*
24061 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24062 const struct dwarf2_per_cu_data
*per_cu
)
24064 const gdb_byte
*info_ptr
;
24067 return &per_cu
->cu
->header
;
24069 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24071 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24072 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24073 rcuh_kind::COMPILE
);
24081 dwarf2_per_cu_data::addr_size () const
24083 struct comp_unit_head cu_header_local
;
24084 const struct comp_unit_head
*cu_headerp
;
24086 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24088 return cu_headerp
->addr_size
;
24094 dwarf2_per_cu_data::offset_size () const
24096 struct comp_unit_head cu_header_local
;
24097 const struct comp_unit_head
*cu_headerp
;
24099 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24101 return cu_headerp
->offset_size
;
24107 dwarf2_per_cu_data::ref_addr_size () const
24109 struct comp_unit_head cu_header_local
;
24110 const struct comp_unit_head
*cu_headerp
;
24112 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24114 if (cu_headerp
->version
== 2)
24115 return cu_headerp
->addr_size
;
24117 return cu_headerp
->offset_size
;
24123 dwarf2_per_cu_data::text_offset () const
24125 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24127 return objfile
->text_section_offset ();
24133 dwarf2_per_cu_data::addr_type () const
24135 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24136 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24137 struct type
*addr_type
= lookup_pointer_type (void_type
);
24138 int addr_size
= this->addr_size ();
24140 if (TYPE_LENGTH (addr_type
) == addr_size
)
24143 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
24147 /* Locate the .debug_info compilation unit from CU's objfile which contains
24148 the DIE at OFFSET. Raises an error on failure. */
24150 static struct dwarf2_per_cu_data
*
24151 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24152 unsigned int offset_in_dwz
,
24153 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24155 struct dwarf2_per_cu_data
*this_cu
;
24159 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
24162 struct dwarf2_per_cu_data
*mid_cu
;
24163 int mid
= low
+ (high
- low
) / 2;
24165 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
24166 if (mid_cu
->is_dwz
> offset_in_dwz
24167 || (mid_cu
->is_dwz
== offset_in_dwz
24168 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
24173 gdb_assert (low
== high
);
24174 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
24175 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24177 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24178 error (_("Dwarf Error: could not find partial DIE containing "
24179 "offset %s [in module %s]"),
24180 sect_offset_str (sect_off
),
24181 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
24183 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
24185 return dwarf2_per_objfile
->all_comp_units
[low
-1];
24189 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
24190 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24191 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24192 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24197 /* Initialize dwarf2_cu CU, owned by PER_CU. */
24199 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
24200 : per_cu (per_cu_
),
24202 has_loclist (false),
24203 checked_producer (false),
24204 producer_is_gxx_lt_4_6 (false),
24205 producer_is_gcc_lt_4_3 (false),
24206 producer_is_icc (false),
24207 producer_is_icc_lt_14 (false),
24208 producer_is_codewarrior (false),
24209 processing_has_namespace_info (false)
24214 /* Destroy a dwarf2_cu. */
24216 dwarf2_cu::~dwarf2_cu ()
24221 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24224 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24225 enum language pretend_language
)
24227 struct attribute
*attr
;
24229 /* Set the language we're debugging. */
24230 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24231 if (attr
!= nullptr)
24232 set_cu_language (DW_UNSND (attr
), cu
);
24235 cu
->language
= pretend_language
;
24236 cu
->language_defn
= language_def (cu
->language
);
24239 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24242 /* Increase the age counter on each cached compilation unit, and free
24243 any that are too old. */
24246 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24248 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24250 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
24251 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24252 while (per_cu
!= NULL
)
24254 per_cu
->cu
->last_used
++;
24255 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
24256 dwarf2_mark (per_cu
->cu
);
24257 per_cu
= per_cu
->cu
->read_in_chain
;
24260 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24261 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24262 while (per_cu
!= NULL
)
24264 struct dwarf2_per_cu_data
*next_cu
;
24266 next_cu
= per_cu
->cu
->read_in_chain
;
24268 if (!per_cu
->cu
->mark
)
24271 *last_chain
= next_cu
;
24274 last_chain
= &per_cu
->cu
->read_in_chain
;
24280 /* Remove a single compilation unit from the cache. */
24283 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
24285 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24286 struct dwarf2_per_objfile
*dwarf2_per_objfile
24287 = target_per_cu
->dwarf2_per_objfile
;
24289 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24290 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24291 while (per_cu
!= NULL
)
24293 struct dwarf2_per_cu_data
*next_cu
;
24295 next_cu
= per_cu
->cu
->read_in_chain
;
24297 if (per_cu
== target_per_cu
)
24301 *last_chain
= next_cu
;
24305 last_chain
= &per_cu
->cu
->read_in_chain
;
24311 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24312 We store these in a hash table separate from the DIEs, and preserve them
24313 when the DIEs are flushed out of cache.
24315 The CU "per_cu" pointer is needed because offset alone is not enough to
24316 uniquely identify the type. A file may have multiple .debug_types sections,
24317 or the type may come from a DWO file. Furthermore, while it's more logical
24318 to use per_cu->section+offset, with Fission the section with the data is in
24319 the DWO file but we don't know that section at the point we need it.
24320 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24321 because we can enter the lookup routine, get_die_type_at_offset, from
24322 outside this file, and thus won't necessarily have PER_CU->cu.
24323 Fortunately, PER_CU is stable for the life of the objfile. */
24325 struct dwarf2_per_cu_offset_and_type
24327 const struct dwarf2_per_cu_data
*per_cu
;
24328 sect_offset sect_off
;
24332 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24335 per_cu_offset_and_type_hash (const void *item
)
24337 const struct dwarf2_per_cu_offset_and_type
*ofs
24338 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24340 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24343 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24346 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24348 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24349 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24350 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24351 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24353 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24354 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24357 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24358 table if necessary. For convenience, return TYPE.
24360 The DIEs reading must have careful ordering to:
24361 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24362 reading current DIE.
24363 * Not trying to dereference contents of still incompletely read in types
24364 while reading in other DIEs.
24365 * Enable referencing still incompletely read in types just by a pointer to
24366 the type without accessing its fields.
24368 Therefore caller should follow these rules:
24369 * Try to fetch any prerequisite types we may need to build this DIE type
24370 before building the type and calling set_die_type.
24371 * After building type call set_die_type for current DIE as soon as
24372 possible before fetching more types to complete the current type.
24373 * Make the type as complete as possible before fetching more types. */
24375 static struct type
*
24376 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
24378 struct dwarf2_per_objfile
*dwarf2_per_objfile
24379 = cu
->per_cu
->dwarf2_per_objfile
;
24380 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24381 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24382 struct attribute
*attr
;
24383 struct dynamic_prop prop
;
24385 /* For Ada types, make sure that the gnat-specific data is always
24386 initialized (if not already set). There are a few types where
24387 we should not be doing so, because the type-specific area is
24388 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24389 where the type-specific area is used to store the floatformat).
24390 But this is not a problem, because the gnat-specific information
24391 is actually not needed for these types. */
24392 if (need_gnat_info (cu
)
24393 && TYPE_CODE (type
) != TYPE_CODE_FUNC
24394 && TYPE_CODE (type
) != TYPE_CODE_FLT
24395 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
24396 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
24397 && TYPE_CODE (type
) != TYPE_CODE_METHOD
24398 && !HAVE_GNAT_AUX_INFO (type
))
24399 INIT_GNAT_SPECIFIC (type
);
24401 /* Read DW_AT_allocated and set in type. */
24402 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24403 if (attr
!= NULL
&& attr
->form_is_block ())
24405 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24406 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24407 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
24409 else if (attr
!= NULL
)
24411 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
24412 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24413 sect_offset_str (die
->sect_off
));
24416 /* Read DW_AT_associated and set in type. */
24417 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24418 if (attr
!= NULL
&& attr
->form_is_block ())
24420 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24421 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24422 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
24424 else if (attr
!= NULL
)
24426 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
24427 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24428 sect_offset_str (die
->sect_off
));
24431 /* Read DW_AT_data_location and set in type. */
24432 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24433 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
24434 cu
->per_cu
->addr_type ()))
24435 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
24437 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24438 dwarf2_per_objfile
->die_type_hash
24439 = htab_up (htab_create_alloc (127,
24440 per_cu_offset_and_type_hash
,
24441 per_cu_offset_and_type_eq
,
24442 NULL
, xcalloc
, xfree
));
24444 ofs
.per_cu
= cu
->per_cu
;
24445 ofs
.sect_off
= die
->sect_off
;
24447 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24448 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24450 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24451 sect_offset_str (die
->sect_off
));
24452 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24453 struct dwarf2_per_cu_offset_and_type
);
24458 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24459 or return NULL if the die does not have a saved type. */
24461 static struct type
*
24462 get_die_type_at_offset (sect_offset sect_off
,
24463 struct dwarf2_per_cu_data
*per_cu
)
24465 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24466 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
24468 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24471 ofs
.per_cu
= per_cu
;
24472 ofs
.sect_off
= sect_off
;
24473 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24474 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
24481 /* Look up the type for DIE in CU in die_type_hash,
24482 or return NULL if DIE does not have a saved type. */
24484 static struct type
*
24485 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24487 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
24490 /* Add a dependence relationship from CU to REF_PER_CU. */
24493 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
24494 struct dwarf2_per_cu_data
*ref_per_cu
)
24498 if (cu
->dependencies
== NULL
)
24500 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
24501 NULL
, &cu
->comp_unit_obstack
,
24502 hashtab_obstack_allocate
,
24503 dummy_obstack_deallocate
);
24505 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
24507 *slot
= ref_per_cu
;
24510 /* Subroutine of dwarf2_mark to pass to htab_traverse.
24511 Set the mark field in every compilation unit in the
24512 cache that we must keep because we are keeping CU. */
24515 dwarf2_mark_helper (void **slot
, void *data
)
24517 struct dwarf2_per_cu_data
*per_cu
;
24519 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
24521 /* cu->dependencies references may not yet have been ever read if QUIT aborts
24522 reading of the chain. As such dependencies remain valid it is not much
24523 useful to track and undo them during QUIT cleanups. */
24524 if (per_cu
->cu
== NULL
)
24527 if (per_cu
->cu
->mark
)
24529 per_cu
->cu
->mark
= true;
24531 if (per_cu
->cu
->dependencies
!= NULL
)
24532 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24537 /* Set the mark field in CU and in every other compilation unit in the
24538 cache that we must keep because we are keeping CU. */
24541 dwarf2_mark (struct dwarf2_cu
*cu
)
24546 if (cu
->dependencies
!= NULL
)
24547 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24551 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
24555 per_cu
->cu
->mark
= false;
24556 per_cu
= per_cu
->cu
->read_in_chain
;
24560 /* Trivial hash function for partial_die_info: the hash value of a DIE
24561 is its offset in .debug_info for this objfile. */
24564 partial_die_hash (const void *item
)
24566 const struct partial_die_info
*part_die
24567 = (const struct partial_die_info
*) item
;
24569 return to_underlying (part_die
->sect_off
);
24572 /* Trivial comparison function for partial_die_info structures: two DIEs
24573 are equal if they have the same offset. */
24576 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24578 const struct partial_die_info
*part_die_lhs
24579 = (const struct partial_die_info
*) item_lhs
;
24580 const struct partial_die_info
*part_die_rhs
24581 = (const struct partial_die_info
*) item_rhs
;
24583 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24586 struct cmd_list_element
*set_dwarf_cmdlist
;
24587 struct cmd_list_element
*show_dwarf_cmdlist
;
24590 set_dwarf_cmd (const char *args
, int from_tty
)
24592 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
24597 show_dwarf_cmd (const char *args
, int from_tty
)
24599 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
24603 show_check_physname (struct ui_file
*file
, int from_tty
,
24604 struct cmd_list_element
*c
, const char *value
)
24606 fprintf_filtered (file
,
24607 _("Whether to check \"physname\" is %s.\n"),
24611 void _initialize_dwarf2_read ();
24613 _initialize_dwarf2_read ()
24615 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
24616 Set DWARF specific variables.\n\
24617 Configure DWARF variables such as the cache size."),
24618 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24619 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24621 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
24622 Show DWARF specific variables.\n\
24623 Show DWARF variables such as the cache size."),
24624 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24625 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24627 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24628 &dwarf_max_cache_age
, _("\
24629 Set the upper bound on the age of cached DWARF compilation units."), _("\
24630 Show the upper bound on the age of cached DWARF compilation units."), _("\
24631 A higher limit means that cached compilation units will be stored\n\
24632 in memory longer, and more total memory will be used. Zero disables\n\
24633 caching, which can slow down startup."),
24635 show_dwarf_max_cache_age
,
24636 &set_dwarf_cmdlist
,
24637 &show_dwarf_cmdlist
);
24639 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24640 Set debugging of the DWARF reader."), _("\
24641 Show debugging of the DWARF reader."), _("\
24642 When enabled (non-zero), debugging messages are printed during DWARF\n\
24643 reading and symtab expansion. A value of 1 (one) provides basic\n\
24644 information. A value greater than 1 provides more verbose information."),
24647 &setdebuglist
, &showdebuglist
);
24649 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24650 Set debugging of the DWARF DIE reader."), _("\
24651 Show debugging of the DWARF DIE reader."), _("\
24652 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24653 The value is the maximum depth to print."),
24656 &setdebuglist
, &showdebuglist
);
24658 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24659 Set debugging of the dwarf line reader."), _("\
24660 Show debugging of the dwarf line reader."), _("\
24661 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24662 A value of 1 (one) provides basic information.\n\
24663 A value greater than 1 provides more verbose information."),
24666 &setdebuglist
, &showdebuglist
);
24668 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24669 Set cross-checking of \"physname\" code against demangler."), _("\
24670 Show cross-checking of \"physname\" code against demangler."), _("\
24671 When enabled, GDB's internal \"physname\" code is checked against\n\
24673 NULL
, show_check_physname
,
24674 &setdebuglist
, &showdebuglist
);
24676 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24677 no_class
, &use_deprecated_index_sections
, _("\
24678 Set whether to use deprecated gdb_index sections."), _("\
24679 Show whether to use deprecated gdb_index sections."), _("\
24680 When enabled, deprecated .gdb_index sections are used anyway.\n\
24681 Normally they are ignored either because of a missing feature or\n\
24682 performance issue.\n\
24683 Warning: This option must be enabled before gdb reads the file."),
24686 &setlist
, &showlist
);
24688 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24689 &dwarf2_locexpr_funcs
);
24690 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24691 &dwarf2_loclist_funcs
);
24693 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24694 &dwarf2_block_frame_base_locexpr_funcs
);
24695 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24696 &dwarf2_block_frame_base_loclist_funcs
);
24699 selftests::register_test ("dw2_expand_symtabs_matching",
24700 selftests::dw2_expand_symtabs_matching::run_test
);