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"
40 #include "dwarf2/dwz.h"
41 #include "dwarf2/macro.h"
42 #include "dwarf2/die.h"
43 #include "dwarf2/stringify.h"
52 #include "gdb-demangle.h"
53 #include "filenames.h" /* for DOSish file names */
55 #include "complaints.h"
56 #include "dwarf2/expr.h"
57 #include "dwarf2/loc.h"
58 #include "cp-support.h"
64 #include "typeprint.h"
69 #include "gdbcore.h" /* for gnutarget */
70 #include "gdb/gdb-index.h"
75 #include "namespace.h"
76 #include "gdbsupport/function-view.h"
77 #include "gdbsupport/gdb_optional.h"
78 #include "gdbsupport/underlying.h"
79 #include "gdbsupport/hash_enum.h"
80 #include "filename-seen-cache.h"
84 #include <unordered_map>
85 #include "gdbsupport/selftest.h"
86 #include "rust-lang.h"
87 #include "gdbsupport/pathstuff.h"
88 #include "count-one-bits.h"
89 #include "debuginfod-support.h"
91 /* When == 1, print basic high level tracing messages.
92 When > 1, be more verbose.
93 This is in contrast to the low level DIE reading of dwarf_die_debug. */
94 static unsigned int dwarf_read_debug
= 0;
96 /* When non-zero, dump DIEs after they are read in. */
97 static unsigned int dwarf_die_debug
= 0;
99 /* When non-zero, dump line number entries as they are read in. */
100 unsigned int dwarf_line_debug
= 0;
102 /* When true, cross-check physname against demangler. */
103 static bool check_physname
= false;
105 /* When true, do not reject deprecated .gdb_index sections. */
106 static bool use_deprecated_index_sections
= false;
108 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
110 /* The "aclass" indices for various kinds of computed DWARF symbols. */
112 static int dwarf2_locexpr_index
;
113 static int dwarf2_loclist_index
;
114 static int dwarf2_locexpr_block_index
;
115 static int dwarf2_loclist_block_index
;
117 /* Size of .debug_loclists section header for 32-bit DWARF format. */
118 #define LOCLIST_HEADER_SIZE32 12
120 /* Size of .debug_loclists section header for 64-bit DWARF format. */
121 #define LOCLIST_HEADER_SIZE64 20
123 /* An index into a (C++) symbol name component in a symbol name as
124 recorded in the mapped_index's symbol table. For each C++ symbol
125 in the symbol table, we record one entry for the start of each
126 component in the symbol in a table of name components, and then
127 sort the table, in order to be able to binary search symbol names,
128 ignoring leading namespaces, both completion and regular look up.
129 For example, for symbol "A::B::C", we'll have an entry that points
130 to "A::B::C", another that points to "B::C", and another for "C".
131 Note that function symbols in GDB index have no parameter
132 information, just the function/method names. You can convert a
133 name_component to a "const char *" using the
134 'mapped_index::symbol_name_at(offset_type)' method. */
136 struct name_component
138 /* Offset in the symbol name where the component starts. Stored as
139 a (32-bit) offset instead of a pointer to save memory and improve
140 locality on 64-bit architectures. */
141 offset_type name_offset
;
143 /* The symbol's index in the symbol and constant pool tables of a
148 /* Base class containing bits shared by both .gdb_index and
149 .debug_name indexes. */
151 struct mapped_index_base
153 mapped_index_base () = default;
154 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
156 /* The name_component table (a sorted vector). See name_component's
157 description above. */
158 std::vector
<name_component
> name_components
;
160 /* How NAME_COMPONENTS is sorted. */
161 enum case_sensitivity name_components_casing
;
163 /* Return the number of names in the symbol table. */
164 virtual size_t symbol_name_count () const = 0;
166 /* Get the name of the symbol at IDX in the symbol table. */
167 virtual const char *symbol_name_at (offset_type idx
) const = 0;
169 /* Return whether the name at IDX in the symbol table should be
171 virtual bool symbol_name_slot_invalid (offset_type idx
) const
176 /* Build the symbol name component sorted vector, if we haven't
178 void build_name_components ();
180 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
181 possible matches for LN_NO_PARAMS in the name component
183 std::pair
<std::vector
<name_component
>::const_iterator
,
184 std::vector
<name_component
>::const_iterator
>
185 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
186 enum language lang
) const;
188 /* Prevent deleting/destroying via a base class pointer. */
190 ~mapped_index_base() = default;
193 /* A description of the mapped index. The file format is described in
194 a comment by the code that writes the index. */
195 struct mapped_index final
: public mapped_index_base
197 /* A slot/bucket in the symbol table hash. */
198 struct symbol_table_slot
200 const offset_type name
;
201 const offset_type vec
;
204 /* Index data format version. */
207 /* The address table data. */
208 gdb::array_view
<const gdb_byte
> address_table
;
210 /* The symbol table, implemented as a hash table. */
211 gdb::array_view
<symbol_table_slot
> symbol_table
;
213 /* A pointer to the constant pool. */
214 const char *constant_pool
= nullptr;
216 bool symbol_name_slot_invalid (offset_type idx
) const override
218 const auto &bucket
= this->symbol_table
[idx
];
219 return bucket
.name
== 0 && bucket
.vec
== 0;
222 /* Convenience method to get at the name of the symbol at IDX in the
224 const char *symbol_name_at (offset_type idx
) const override
225 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
227 size_t symbol_name_count () const override
228 { return this->symbol_table
.size (); }
231 /* A description of the mapped .debug_names.
232 Uninitialized map has CU_COUNT 0. */
233 struct mapped_debug_names final
: public mapped_index_base
235 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
236 : dwarf2_per_objfile (dwarf2_per_objfile_
)
239 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
240 bfd_endian dwarf5_byte_order
;
241 bool dwarf5_is_dwarf64
;
242 bool augmentation_is_gdb
;
244 uint32_t cu_count
= 0;
245 uint32_t tu_count
, bucket_count
, name_count
;
246 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
247 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
248 const gdb_byte
*name_table_string_offs_reordered
;
249 const gdb_byte
*name_table_entry_offs_reordered
;
250 const gdb_byte
*entry_pool
;
257 /* Attribute name DW_IDX_*. */
260 /* Attribute form DW_FORM_*. */
263 /* Value if FORM is DW_FORM_implicit_const. */
264 LONGEST implicit_const
;
266 std::vector
<attr
> attr_vec
;
269 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
271 const char *namei_to_name (uint32_t namei
) const;
273 /* Implementation of the mapped_index_base virtual interface, for
274 the name_components cache. */
276 const char *symbol_name_at (offset_type idx
) const override
277 { return namei_to_name (idx
); }
279 size_t symbol_name_count () const override
280 { return this->name_count
; }
283 /* See dwarf2read.h. */
286 get_dwarf2_per_objfile (struct objfile
*objfile
)
288 return dwarf2_objfile_data_key
.get (objfile
);
291 /* Default names of the debugging sections. */
293 /* Note that if the debugging section has been compressed, it might
294 have a name like .zdebug_info. */
296 static const struct dwarf2_debug_sections dwarf2_elf_names
=
298 { ".debug_info", ".zdebug_info" },
299 { ".debug_abbrev", ".zdebug_abbrev" },
300 { ".debug_line", ".zdebug_line" },
301 { ".debug_loc", ".zdebug_loc" },
302 { ".debug_loclists", ".zdebug_loclists" },
303 { ".debug_macinfo", ".zdebug_macinfo" },
304 { ".debug_macro", ".zdebug_macro" },
305 { ".debug_str", ".zdebug_str" },
306 { ".debug_str_offsets", ".zdebug_str_offsets" },
307 { ".debug_line_str", ".zdebug_line_str" },
308 { ".debug_ranges", ".zdebug_ranges" },
309 { ".debug_rnglists", ".zdebug_rnglists" },
310 { ".debug_types", ".zdebug_types" },
311 { ".debug_addr", ".zdebug_addr" },
312 { ".debug_frame", ".zdebug_frame" },
313 { ".eh_frame", NULL
},
314 { ".gdb_index", ".zgdb_index" },
315 { ".debug_names", ".zdebug_names" },
316 { ".debug_aranges", ".zdebug_aranges" },
320 /* List of DWO/DWP sections. */
322 static const struct dwop_section_names
324 struct dwarf2_section_names abbrev_dwo
;
325 struct dwarf2_section_names info_dwo
;
326 struct dwarf2_section_names line_dwo
;
327 struct dwarf2_section_names loc_dwo
;
328 struct dwarf2_section_names loclists_dwo
;
329 struct dwarf2_section_names macinfo_dwo
;
330 struct dwarf2_section_names macro_dwo
;
331 struct dwarf2_section_names str_dwo
;
332 struct dwarf2_section_names str_offsets_dwo
;
333 struct dwarf2_section_names types_dwo
;
334 struct dwarf2_section_names cu_index
;
335 struct dwarf2_section_names tu_index
;
339 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
340 { ".debug_info.dwo", ".zdebug_info.dwo" },
341 { ".debug_line.dwo", ".zdebug_line.dwo" },
342 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
343 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
344 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
345 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
346 { ".debug_str.dwo", ".zdebug_str.dwo" },
347 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
348 { ".debug_types.dwo", ".zdebug_types.dwo" },
349 { ".debug_cu_index", ".zdebug_cu_index" },
350 { ".debug_tu_index", ".zdebug_tu_index" },
353 /* local data types */
355 /* The location list section (.debug_loclists) begins with a header,
356 which contains the following information. */
357 struct loclist_header
359 /* A 4-byte or 12-byte length containing the length of the
360 set of entries for this compilation unit, not including the
361 length field itself. */
364 /* A 2-byte version identifier. */
367 /* A 1-byte unsigned integer containing the size in bytes of an address on
368 the target system. */
369 unsigned char addr_size
;
371 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
372 on the target system. */
373 unsigned char segment_collector_size
;
375 /* A 4-byte count of the number of offsets that follow the header. */
376 unsigned int offset_entry_count
;
379 /* Type used for delaying computation of method physnames.
380 See comments for compute_delayed_physnames. */
381 struct delayed_method_info
383 /* The type to which the method is attached, i.e., its parent class. */
386 /* The index of the method in the type's function fieldlists. */
389 /* The index of the method in the fieldlist. */
392 /* The name of the DIE. */
395 /* The DIE associated with this method. */
396 struct die_info
*die
;
399 /* Internal state when decoding a particular compilation unit. */
402 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
405 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
407 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
408 Create the set of symtabs used by this TU, or if this TU is sharing
409 symtabs with another TU and the symtabs have already been created
410 then restore those symtabs in the line header.
411 We don't need the pc/line-number mapping for type units. */
412 void setup_type_unit_groups (struct die_info
*die
);
414 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
415 buildsym_compunit constructor. */
416 struct compunit_symtab
*start_symtab (const char *name
,
417 const char *comp_dir
,
420 /* Reset the builder. */
421 void reset_builder () { m_builder
.reset (); }
423 /* The header of the compilation unit. */
424 struct comp_unit_head header
{};
426 /* Base address of this compilation unit. */
427 gdb::optional
<CORE_ADDR
> base_address
;
429 /* The language we are debugging. */
430 enum language language
= language_unknown
;
431 const struct language_defn
*language_defn
= nullptr;
433 const char *producer
= nullptr;
436 /* The symtab builder for this CU. This is only non-NULL when full
437 symbols are being read. */
438 std::unique_ptr
<buildsym_compunit
> m_builder
;
441 /* The generic symbol table building routines have separate lists for
442 file scope symbols and all all other scopes (local scopes). So
443 we need to select the right one to pass to add_symbol_to_list().
444 We do it by keeping a pointer to the correct list in list_in_scope.
446 FIXME: The original dwarf code just treated the file scope as the
447 first local scope, and all other local scopes as nested local
448 scopes, and worked fine. Check to see if we really need to
449 distinguish these in buildsym.c. */
450 struct pending
**list_in_scope
= nullptr;
452 /* Hash table holding all the loaded partial DIEs
453 with partial_die->offset.SECT_OFF as hash. */
454 htab_t partial_dies
= nullptr;
456 /* Storage for things with the same lifetime as this read-in compilation
457 unit, including partial DIEs. */
458 auto_obstack comp_unit_obstack
;
460 /* When multiple dwarf2_cu structures are living in memory, this field
461 chains them all together, so that they can be released efficiently.
462 We will probably also want a generation counter so that most-recently-used
463 compilation units are cached... */
464 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
466 /* Backlink to our per_cu entry. */
467 struct dwarf2_per_cu_data
*per_cu
;
469 /* How many compilation units ago was this CU last referenced? */
472 /* A hash table of DIE cu_offset for following references with
473 die_info->offset.sect_off as hash. */
474 htab_t die_hash
= nullptr;
476 /* Full DIEs if read in. */
477 struct die_info
*dies
= nullptr;
479 /* A set of pointers to dwarf2_per_cu_data objects for compilation
480 units referenced by this one. Only set during full symbol processing;
481 partial symbol tables do not have dependencies. */
482 htab_t dependencies
= nullptr;
484 /* Header data from the line table, during full symbol processing. */
485 struct line_header
*line_header
= nullptr;
486 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
487 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
488 this is the DW_TAG_compile_unit die for this CU. We'll hold on
489 to the line header as long as this DIE is being processed. See
490 process_die_scope. */
491 die_info
*line_header_die_owner
= nullptr;
493 /* A list of methods which need to have physnames computed
494 after all type information has been read. */
495 std::vector
<delayed_method_info
> method_list
;
497 /* To be copied to symtab->call_site_htab. */
498 htab_t call_site_htab
= nullptr;
500 /* Non-NULL if this CU came from a DWO file.
501 There is an invariant here that is important to remember:
502 Except for attributes copied from the top level DIE in the "main"
503 (or "stub") file in preparation for reading the DWO file
504 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
505 Either there isn't a DWO file (in which case this is NULL and the point
506 is moot), or there is and either we're not going to read it (in which
507 case this is NULL) or there is and we are reading it (in which case this
509 struct dwo_unit
*dwo_unit
= nullptr;
511 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
512 Note this value comes from the Fission stub CU/TU's DIE. */
513 gdb::optional
<ULONGEST
> addr_base
;
515 /* The DW_AT_rnglists_base attribute if present.
516 Note this value comes from the Fission stub CU/TU's DIE.
517 Also note that the value is zero in the non-DWO case so this value can
518 be used without needing to know whether DWO files are in use or not.
519 N.B. This does not apply to DW_AT_ranges appearing in
520 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
521 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
522 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
523 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
524 ULONGEST ranges_base
= 0;
526 /* The DW_AT_loclists_base attribute if present. */
527 ULONGEST loclist_base
= 0;
529 /* When reading debug info generated by older versions of rustc, we
530 have to rewrite some union types to be struct types with a
531 variant part. This rewriting must be done after the CU is fully
532 read in, because otherwise at the point of rewriting some struct
533 type might not have been fully processed. So, we keep a list of
534 all such types here and process them after expansion. */
535 std::vector
<struct type
*> rust_unions
;
537 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
538 files, the value is implicitly zero. For DWARF 5 version DWO files, the
539 value is often implicit and is the size of the header of
540 .debug_str_offsets section (8 or 4, depending on the address size). */
541 gdb::optional
<ULONGEST
> str_offsets_base
;
543 /* Mark used when releasing cached dies. */
546 /* This CU references .debug_loc. See the symtab->locations_valid field.
547 This test is imperfect as there may exist optimized debug code not using
548 any location list and still facing inlining issues if handled as
549 unoptimized code. For a future better test see GCC PR other/32998. */
550 bool has_loclist
: 1;
552 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
553 if all the producer_is_* fields are valid. This information is cached
554 because profiling CU expansion showed excessive time spent in
555 producer_is_gxx_lt_4_6. */
556 bool checked_producer
: 1;
557 bool producer_is_gxx_lt_4_6
: 1;
558 bool producer_is_gcc_lt_4_3
: 1;
559 bool producer_is_icc
: 1;
560 bool producer_is_icc_lt_14
: 1;
561 bool producer_is_codewarrior
: 1;
563 /* When true, the file that we're processing is known to have
564 debugging info for C++ namespaces. GCC 3.3.x did not produce
565 this information, but later versions do. */
567 bool processing_has_namespace_info
: 1;
569 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
571 /* If this CU was inherited by another CU (via specification,
572 abstract_origin, etc), this is the ancestor CU. */
575 /* Get the buildsym_compunit for this CU. */
576 buildsym_compunit
*get_builder ()
578 /* If this CU has a builder associated with it, use that. */
579 if (m_builder
!= nullptr)
580 return m_builder
.get ();
582 /* Otherwise, search ancestors for a valid builder. */
583 if (ancestor
!= nullptr)
584 return ancestor
->get_builder ();
590 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
591 This includes type_unit_group and quick_file_names. */
593 struct stmt_list_hash
595 /* The DWO unit this table is from or NULL if there is none. */
596 struct dwo_unit
*dwo_unit
;
598 /* Offset in .debug_line or .debug_line.dwo. */
599 sect_offset line_sect_off
;
602 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
603 an object of this type. */
605 struct type_unit_group
607 /* dwarf2read.c's main "handle" on a TU symtab.
608 To simplify things we create an artificial CU that "includes" all the
609 type units using this stmt_list so that the rest of the code still has
610 a "per_cu" handle on the symtab. */
611 struct dwarf2_per_cu_data per_cu
;
613 /* The TUs that share this DW_AT_stmt_list entry.
614 This is added to while parsing type units to build partial symtabs,
615 and is deleted afterwards and not used again. */
616 std::vector
<signatured_type
*> *tus
;
618 /* The compunit symtab.
619 Type units in a group needn't all be defined in the same source file,
620 so we create an essentially anonymous symtab as the compunit symtab. */
621 struct compunit_symtab
*compunit_symtab
;
623 /* The data used to construct the hash key. */
624 struct stmt_list_hash hash
;
626 /* The symbol tables for this TU (obtained from the files listed in
628 WARNING: The order of entries here must match the order of entries
629 in the line header. After the first TU using this type_unit_group, the
630 line header for the subsequent TUs is recreated from this. This is done
631 because we need to use the same symtabs for each TU using the same
632 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
633 there's no guarantee the line header doesn't have duplicate entries. */
634 struct symtab
**symtabs
;
637 /* These sections are what may appear in a (real or virtual) DWO file. */
641 struct dwarf2_section_info abbrev
;
642 struct dwarf2_section_info line
;
643 struct dwarf2_section_info loc
;
644 struct dwarf2_section_info loclists
;
645 struct dwarf2_section_info macinfo
;
646 struct dwarf2_section_info macro
;
647 struct dwarf2_section_info str
;
648 struct dwarf2_section_info str_offsets
;
649 /* In the case of a virtual DWO file, these two are unused. */
650 struct dwarf2_section_info info
;
651 std::vector
<dwarf2_section_info
> types
;
654 /* CUs/TUs in DWP/DWO files. */
658 /* Backlink to the containing struct dwo_file. */
659 struct dwo_file
*dwo_file
;
661 /* The "id" that distinguishes this CU/TU.
662 .debug_info calls this "dwo_id", .debug_types calls this "signature".
663 Since signatures came first, we stick with it for consistency. */
666 /* The section this CU/TU lives in, in the DWO file. */
667 struct dwarf2_section_info
*section
;
669 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
670 sect_offset sect_off
;
673 /* For types, offset in the type's DIE of the type defined by this TU. */
674 cu_offset type_offset_in_tu
;
677 /* include/dwarf2.h defines the DWP section codes.
678 It defines a max value but it doesn't define a min value, which we
679 use for error checking, so provide one. */
681 enum dwp_v2_section_ids
686 /* Data for one DWO file.
688 This includes virtual DWO files (a virtual DWO file is a DWO file as it
689 appears in a DWP file). DWP files don't really have DWO files per se -
690 comdat folding of types "loses" the DWO file they came from, and from
691 a high level view DWP files appear to contain a mass of random types.
692 However, to maintain consistency with the non-DWP case we pretend DWP
693 files contain virtual DWO files, and we assign each TU with one virtual
694 DWO file (generally based on the line and abbrev section offsets -
695 a heuristic that seems to work in practice). */
699 dwo_file () = default;
700 DISABLE_COPY_AND_ASSIGN (dwo_file
);
702 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
703 For virtual DWO files the name is constructed from the section offsets
704 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
705 from related CU+TUs. */
706 const char *dwo_name
= nullptr;
708 /* The DW_AT_comp_dir attribute. */
709 const char *comp_dir
= nullptr;
711 /* The bfd, when the file is open. Otherwise this is NULL.
712 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
713 gdb_bfd_ref_ptr dbfd
;
715 /* The sections that make up this DWO file.
716 Remember that for virtual DWO files in DWP V2, these are virtual
717 sections (for lack of a better name). */
718 struct dwo_sections sections
{};
720 /* The CUs in the file.
721 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
722 an extension to handle LLVM's Link Time Optimization output (where
723 multiple source files may be compiled into a single object/dwo pair). */
726 /* Table of TUs in the file.
727 Each element is a struct dwo_unit. */
731 /* These sections are what may appear in a DWP file. */
735 /* These are used by both DWP version 1 and 2. */
736 struct dwarf2_section_info str
;
737 struct dwarf2_section_info cu_index
;
738 struct dwarf2_section_info tu_index
;
740 /* These are only used by DWP version 2 files.
741 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
742 sections are referenced by section number, and are not recorded here.
743 In DWP version 2 there is at most one copy of all these sections, each
744 section being (effectively) comprised of the concatenation of all of the
745 individual sections that exist in the version 1 format.
746 To keep the code simple we treat each of these concatenated pieces as a
747 section itself (a virtual section?). */
748 struct dwarf2_section_info abbrev
;
749 struct dwarf2_section_info info
;
750 struct dwarf2_section_info line
;
751 struct dwarf2_section_info loc
;
752 struct dwarf2_section_info macinfo
;
753 struct dwarf2_section_info macro
;
754 struct dwarf2_section_info str_offsets
;
755 struct dwarf2_section_info types
;
758 /* These sections are what may appear in a virtual DWO file in DWP version 1.
759 A virtual DWO file is a DWO file as it appears in a DWP file. */
761 struct virtual_v1_dwo_sections
763 struct dwarf2_section_info abbrev
;
764 struct dwarf2_section_info line
;
765 struct dwarf2_section_info loc
;
766 struct dwarf2_section_info macinfo
;
767 struct dwarf2_section_info macro
;
768 struct dwarf2_section_info str_offsets
;
769 /* Each DWP hash table entry records one CU or one TU.
770 That is recorded here, and copied to dwo_unit.section. */
771 struct dwarf2_section_info info_or_types
;
774 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
775 In version 2, the sections of the DWO files are concatenated together
776 and stored in one section of that name. Thus each ELF section contains
777 several "virtual" sections. */
779 struct virtual_v2_dwo_sections
781 bfd_size_type abbrev_offset
;
782 bfd_size_type abbrev_size
;
784 bfd_size_type line_offset
;
785 bfd_size_type line_size
;
787 bfd_size_type loc_offset
;
788 bfd_size_type loc_size
;
790 bfd_size_type macinfo_offset
;
791 bfd_size_type macinfo_size
;
793 bfd_size_type macro_offset
;
794 bfd_size_type macro_size
;
796 bfd_size_type str_offsets_offset
;
797 bfd_size_type str_offsets_size
;
799 /* Each DWP hash table entry records one CU or one TU.
800 That is recorded here, and copied to dwo_unit.section. */
801 bfd_size_type info_or_types_offset
;
802 bfd_size_type info_or_types_size
;
805 /* Contents of DWP hash tables. */
807 struct dwp_hash_table
809 uint32_t version
, nr_columns
;
810 uint32_t nr_units
, nr_slots
;
811 const gdb_byte
*hash_table
, *unit_table
;
816 const gdb_byte
*indices
;
820 /* This is indexed by column number and gives the id of the section
822 #define MAX_NR_V2_DWO_SECTIONS \
823 (1 /* .debug_info or .debug_types */ \
824 + 1 /* .debug_abbrev */ \
825 + 1 /* .debug_line */ \
826 + 1 /* .debug_loc */ \
827 + 1 /* .debug_str_offsets */ \
828 + 1 /* .debug_macro or .debug_macinfo */)
829 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
830 const gdb_byte
*offsets
;
831 const gdb_byte
*sizes
;
836 /* Data for one DWP file. */
840 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
842 dbfd (std::move (abfd
))
846 /* Name of the file. */
849 /* File format version. */
853 gdb_bfd_ref_ptr dbfd
;
855 /* Section info for this file. */
856 struct dwp_sections sections
{};
858 /* Table of CUs in the file. */
859 const struct dwp_hash_table
*cus
= nullptr;
861 /* Table of TUs in the file. */
862 const struct dwp_hash_table
*tus
= nullptr;
864 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
868 /* Table to map ELF section numbers to their sections.
869 This is only needed for the DWP V1 file format. */
870 unsigned int num_sections
= 0;
871 asection
**elf_sections
= nullptr;
874 /* Struct used to pass misc. parameters to read_die_and_children, et
875 al. which are used for both .debug_info and .debug_types dies.
876 All parameters here are unchanging for the life of the call. This
877 struct exists to abstract away the constant parameters of die reading. */
879 struct die_reader_specs
881 /* The bfd of die_section. */
884 /* The CU of the DIE we are parsing. */
885 struct dwarf2_cu
*cu
;
887 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
888 struct dwo_file
*dwo_file
;
890 /* The section the die comes from.
891 This is either .debug_info or .debug_types, or the .dwo variants. */
892 struct dwarf2_section_info
*die_section
;
894 /* die_section->buffer. */
895 const gdb_byte
*buffer
;
897 /* The end of the buffer. */
898 const gdb_byte
*buffer_end
;
900 /* The abbreviation table to use when reading the DIEs. */
901 struct abbrev_table
*abbrev_table
;
904 /* A subclass of die_reader_specs that holds storage and has complex
905 constructor and destructor behavior. */
907 class cutu_reader
: public die_reader_specs
911 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
912 struct abbrev_table
*abbrev_table
,
916 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
917 struct dwarf2_cu
*parent_cu
= nullptr,
918 struct dwo_file
*dwo_file
= nullptr);
920 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
922 const gdb_byte
*info_ptr
= nullptr;
923 struct die_info
*comp_unit_die
= nullptr;
924 bool dummy_p
= false;
926 /* Release the new CU, putting it on the chain. This cannot be done
931 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
932 int use_existing_cu
);
934 struct dwarf2_per_cu_data
*m_this_cu
;
935 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
937 /* The ordinary abbreviation table. */
938 abbrev_table_up m_abbrev_table_holder
;
940 /* The DWO abbreviation table. */
941 abbrev_table_up m_dwo_abbrev_table
;
944 /* When we construct a partial symbol table entry we only
945 need this much information. */
946 struct partial_die_info
: public allocate_on_obstack
948 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
950 /* Disable assign but still keep copy ctor, which is needed
951 load_partial_dies. */
952 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
954 /* Adjust the partial die before generating a symbol for it. This
955 function may set the is_external flag or change the DIE's
957 void fixup (struct dwarf2_cu
*cu
);
959 /* Read a minimal amount of information into the minimal die
961 const gdb_byte
*read (const struct die_reader_specs
*reader
,
962 const struct abbrev_info
&abbrev
,
963 const gdb_byte
*info_ptr
);
965 /* Offset of this DIE. */
966 const sect_offset sect_off
;
968 /* DWARF-2 tag for this DIE. */
969 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
971 /* Assorted flags describing the data found in this DIE. */
972 const unsigned int has_children
: 1;
974 unsigned int is_external
: 1;
975 unsigned int is_declaration
: 1;
976 unsigned int has_type
: 1;
977 unsigned int has_specification
: 1;
978 unsigned int has_pc_info
: 1;
979 unsigned int may_be_inlined
: 1;
981 /* This DIE has been marked DW_AT_main_subprogram. */
982 unsigned int main_subprogram
: 1;
984 /* Flag set if the SCOPE field of this structure has been
986 unsigned int scope_set
: 1;
988 /* Flag set if the DIE has a byte_size attribute. */
989 unsigned int has_byte_size
: 1;
991 /* Flag set if the DIE has a DW_AT_const_value attribute. */
992 unsigned int has_const_value
: 1;
994 /* Flag set if any of the DIE's children are template arguments. */
995 unsigned int has_template_arguments
: 1;
997 /* Flag set if fixup has been called on this die. */
998 unsigned int fixup_called
: 1;
1000 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1001 unsigned int is_dwz
: 1;
1003 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1004 unsigned int spec_is_dwz
: 1;
1006 /* The name of this DIE. Normally the value of DW_AT_name, but
1007 sometimes a default name for unnamed DIEs. */
1008 const char *name
= nullptr;
1010 /* The linkage name, if present. */
1011 const char *linkage_name
= nullptr;
1013 /* The scope to prepend to our children. This is generally
1014 allocated on the comp_unit_obstack, so will disappear
1015 when this compilation unit leaves the cache. */
1016 const char *scope
= nullptr;
1018 /* Some data associated with the partial DIE. The tag determines
1019 which field is live. */
1022 /* The location description associated with this DIE, if any. */
1023 struct dwarf_block
*locdesc
;
1024 /* The offset of an import, for DW_TAG_imported_unit. */
1025 sect_offset sect_off
;
1028 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1029 CORE_ADDR lowpc
= 0;
1030 CORE_ADDR highpc
= 0;
1032 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1033 DW_AT_sibling, if any. */
1034 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1035 could return DW_AT_sibling values to its caller load_partial_dies. */
1036 const gdb_byte
*sibling
= nullptr;
1038 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1039 DW_AT_specification (or DW_AT_abstract_origin or
1040 DW_AT_extension). */
1041 sect_offset spec_offset
{};
1043 /* Pointers to this DIE's parent, first child, and next sibling,
1045 struct partial_die_info
*die_parent
= nullptr;
1046 struct partial_die_info
*die_child
= nullptr;
1047 struct partial_die_info
*die_sibling
= nullptr;
1049 friend struct partial_die_info
*
1050 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1053 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1054 partial_die_info (sect_offset sect_off
)
1055 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1059 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1061 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1066 has_specification
= 0;
1069 main_subprogram
= 0;
1072 has_const_value
= 0;
1073 has_template_arguments
= 0;
1080 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1081 but this would require a corresponding change in unpack_field_as_long
1083 static int bits_per_byte
= 8;
1085 /* When reading a variant or variant part, we track a bit more
1086 information about the field, and store it in an object of this
1089 struct variant_field
1091 /* If we see a DW_TAG_variant, then this will be the discriminant
1093 ULONGEST discriminant_value
;
1094 /* If we see a DW_TAG_variant, then this will be set if this is the
1096 bool default_branch
;
1097 /* While reading a DW_TAG_variant_part, this will be set if this
1098 field is the discriminant. */
1099 bool is_discriminant
;
1104 int accessibility
= 0;
1106 /* Extra information to describe a variant or variant part. */
1107 struct variant_field variant
{};
1108 struct field field
{};
1113 const char *name
= nullptr;
1114 std::vector
<struct fn_field
> fnfields
;
1117 /* The routines that read and process dies for a C struct or C++ class
1118 pass lists of data member fields and lists of member function fields
1119 in an instance of a field_info structure, as defined below. */
1122 /* List of data member and baseclasses fields. */
1123 std::vector
<struct nextfield
> fields
;
1124 std::vector
<struct nextfield
> baseclasses
;
1126 /* Set if the accessibility of one of the fields is not public. */
1127 int non_public_fields
= 0;
1129 /* Member function fieldlist array, contains name of possibly overloaded
1130 member function, number of overloaded member functions and a pointer
1131 to the head of the member function field chain. */
1132 std::vector
<struct fnfieldlist
> fnfieldlists
;
1134 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1135 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1136 std::vector
<struct decl_field
> typedef_field_list
;
1138 /* Nested types defined by this class and the number of elements in this
1140 std::vector
<struct decl_field
> nested_types_list
;
1142 /* Return the total number of fields (including baseclasses). */
1143 int nfields () const
1145 return fields
.size () + baseclasses
.size ();
1149 /* Loaded secondary compilation units are kept in memory until they
1150 have not been referenced for the processing of this many
1151 compilation units. Set this to zero to disable caching. Cache
1152 sizes of up to at least twenty will improve startup time for
1153 typical inter-CU-reference binaries, at an obvious memory cost. */
1154 static int dwarf_max_cache_age
= 5;
1156 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1157 struct cmd_list_element
*c
, const char *value
)
1159 fprintf_filtered (file
, _("The upper bound on the age of cached "
1160 "DWARF compilation units is %s.\n"),
1164 /* local function prototypes */
1166 static void dwarf2_find_base_address (struct die_info
*die
,
1167 struct dwarf2_cu
*cu
);
1169 static dwarf2_psymtab
*create_partial_symtab
1170 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1172 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1173 const gdb_byte
*info_ptr
,
1174 struct die_info
*type_unit_die
);
1176 static void dwarf2_build_psymtabs_hard
1177 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1179 static void scan_partial_symbols (struct partial_die_info
*,
1180 CORE_ADDR
*, CORE_ADDR
*,
1181 int, struct dwarf2_cu
*);
1183 static void add_partial_symbol (struct partial_die_info
*,
1184 struct dwarf2_cu
*);
1186 static void add_partial_namespace (struct partial_die_info
*pdi
,
1187 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1188 int set_addrmap
, struct dwarf2_cu
*cu
);
1190 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1191 CORE_ADDR
*highpc
, int set_addrmap
,
1192 struct dwarf2_cu
*cu
);
1194 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1195 struct dwarf2_cu
*cu
);
1197 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1198 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1199 int need_pc
, struct dwarf2_cu
*cu
);
1201 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1203 static struct partial_die_info
*load_partial_dies
1204 (const struct die_reader_specs
*, const gdb_byte
*, int);
1206 /* A pair of partial_die_info and compilation unit. */
1207 struct cu_partial_die_info
1209 /* The compilation unit of the partial_die_info. */
1210 struct dwarf2_cu
*cu
;
1211 /* A partial_die_info. */
1212 struct partial_die_info
*pdi
;
1214 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1220 cu_partial_die_info () = delete;
1223 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1224 struct dwarf2_cu
*);
1226 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1227 struct attribute
*, struct attr_abbrev
*,
1228 const gdb_byte
*, bool *need_reprocess
);
1230 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1231 struct attribute
*attr
);
1233 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1235 static sect_offset read_abbrev_offset
1236 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1237 struct dwarf2_section_info
*, sect_offset
);
1239 static const char *read_indirect_string
1240 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1241 const struct comp_unit_head
*, unsigned int *);
1243 static const char *read_indirect_string_at_offset
1244 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1246 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1250 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1251 ULONGEST str_index
);
1253 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1254 ULONGEST str_index
);
1256 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1258 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1259 struct dwarf2_cu
*);
1261 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1262 struct dwarf2_cu
*cu
);
1264 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1266 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1267 struct dwarf2_cu
*cu
);
1269 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1271 static struct die_info
*die_specification (struct die_info
*die
,
1272 struct dwarf2_cu
**);
1274 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1275 struct dwarf2_cu
*cu
);
1277 static void dwarf_decode_lines (struct line_header
*, const char *,
1278 struct dwarf2_cu
*, dwarf2_psymtab
*,
1279 CORE_ADDR
, int decode_mapping
);
1281 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1284 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1285 struct dwarf2_cu
*, struct symbol
* = NULL
);
1287 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1288 struct dwarf2_cu
*);
1290 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1293 struct obstack
*obstack
,
1294 struct dwarf2_cu
*cu
, LONGEST
*value
,
1295 const gdb_byte
**bytes
,
1296 struct dwarf2_locexpr_baton
**baton
);
1298 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1300 static int need_gnat_info (struct dwarf2_cu
*);
1302 static struct type
*die_descriptive_type (struct die_info
*,
1303 struct dwarf2_cu
*);
1305 static void set_descriptive_type (struct type
*, struct die_info
*,
1306 struct dwarf2_cu
*);
1308 static struct type
*die_containing_type (struct die_info
*,
1309 struct dwarf2_cu
*);
1311 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1312 struct dwarf2_cu
*);
1314 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1316 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1318 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1320 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1321 const char *suffix
, int physname
,
1322 struct dwarf2_cu
*cu
);
1324 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1326 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1328 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1330 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1332 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1334 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1336 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1337 struct dwarf2_cu
*, dwarf2_psymtab
*);
1339 /* Return the .debug_loclists section to use for cu. */
1340 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1342 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1343 values. Keep the items ordered with increasing constraints compliance. */
1346 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1347 PC_BOUNDS_NOT_PRESENT
,
1349 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1350 were present but they do not form a valid range of PC addresses. */
1353 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1356 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1360 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1361 CORE_ADDR
*, CORE_ADDR
*,
1365 static void get_scope_pc_bounds (struct die_info
*,
1366 CORE_ADDR
*, CORE_ADDR
*,
1367 struct dwarf2_cu
*);
1369 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1370 CORE_ADDR
, struct dwarf2_cu
*);
1372 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1373 struct dwarf2_cu
*);
1375 static void dwarf2_attach_fields_to_type (struct field_info
*,
1376 struct type
*, struct dwarf2_cu
*);
1378 static void dwarf2_add_member_fn (struct field_info
*,
1379 struct die_info
*, struct type
*,
1380 struct dwarf2_cu
*);
1382 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1384 struct dwarf2_cu
*);
1386 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1388 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1390 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1392 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1394 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1396 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1398 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1400 static struct type
*read_module_type (struct die_info
*die
,
1401 struct dwarf2_cu
*cu
);
1403 static const char *namespace_name (struct die_info
*die
,
1404 int *is_anonymous
, struct dwarf2_cu
*);
1406 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1408 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1410 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1411 struct dwarf2_cu
*);
1413 static struct die_info
*read_die_and_siblings_1
1414 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1417 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1418 const gdb_byte
*info_ptr
,
1419 const gdb_byte
**new_info_ptr
,
1420 struct die_info
*parent
);
1422 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1423 struct die_info
**, const gdb_byte
*,
1426 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1427 struct die_info
**, const gdb_byte
*);
1429 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1431 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1434 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1436 static const char *dwarf2_full_name (const char *name
,
1437 struct die_info
*die
,
1438 struct dwarf2_cu
*cu
);
1440 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1441 struct dwarf2_cu
*cu
);
1443 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1444 struct dwarf2_cu
**);
1446 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1448 static void dump_die_for_error (struct die_info
*);
1450 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1453 /*static*/ void dump_die (struct die_info
*, int max_level
);
1455 static void store_in_ref_table (struct die_info
*,
1456 struct dwarf2_cu
*);
1458 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1459 const struct attribute
*,
1460 struct dwarf2_cu
**);
1462 static struct die_info
*follow_die_ref (struct die_info
*,
1463 const struct attribute
*,
1464 struct dwarf2_cu
**);
1466 static struct die_info
*follow_die_sig (struct die_info
*,
1467 const struct attribute
*,
1468 struct dwarf2_cu
**);
1470 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1471 struct dwarf2_cu
*);
1473 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1474 const struct attribute
*,
1475 struct dwarf2_cu
*);
1477 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1479 static void read_signatured_type (struct signatured_type
*);
1481 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1482 struct die_info
*die
, struct dwarf2_cu
*cu
,
1483 struct dynamic_prop
*prop
, struct type
*type
);
1485 /* memory allocation interface */
1487 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1489 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1491 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1493 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1494 struct dwarf2_loclist_baton
*baton
,
1495 const struct attribute
*attr
);
1497 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1499 struct dwarf2_cu
*cu
,
1502 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1503 const gdb_byte
*info_ptr
,
1504 struct abbrev_info
*abbrev
);
1506 static hashval_t
partial_die_hash (const void *item
);
1508 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1510 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1511 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1512 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1514 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1515 struct die_info
*comp_unit_die
,
1516 enum language pretend_language
);
1518 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1520 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1522 static struct type
*set_die_type (struct die_info
*, struct type
*,
1523 struct dwarf2_cu
*);
1525 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1527 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1529 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1532 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1535 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1538 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1539 struct dwarf2_per_cu_data
*);
1541 static void dwarf2_mark (struct dwarf2_cu
*);
1543 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1545 static struct type
*get_die_type_at_offset (sect_offset
,
1546 struct dwarf2_per_cu_data
*);
1548 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1550 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1551 enum language pretend_language
);
1553 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1555 /* Class, the destructor of which frees all allocated queue entries. This
1556 will only have work to do if an error was thrown while processing the
1557 dwarf. If no error was thrown then the queue entries should have all
1558 been processed, and freed, as we went along. */
1560 class dwarf2_queue_guard
1563 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1564 : m_per_objfile (per_objfile
)
1568 /* Free any entries remaining on the queue. There should only be
1569 entries left if we hit an error while processing the dwarf. */
1570 ~dwarf2_queue_guard ()
1572 /* Ensure that no memory is allocated by the queue. */
1573 std::queue
<dwarf2_queue_item
> empty
;
1574 std::swap (m_per_objfile
->queue
, empty
);
1577 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1580 dwarf2_per_objfile
*m_per_objfile
;
1583 dwarf2_queue_item::~dwarf2_queue_item ()
1585 /* Anything still marked queued is likely to be in an
1586 inconsistent state, so discard it. */
1589 if (per_cu
->cu
!= NULL
)
1590 free_one_cached_comp_unit (per_cu
);
1595 /* The return type of find_file_and_directory. Note, the enclosed
1596 string pointers are only valid while this object is valid. */
1598 struct file_and_directory
1600 /* The filename. This is never NULL. */
1603 /* The compilation directory. NULL if not known. If we needed to
1604 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1605 points directly to the DW_AT_comp_dir string attribute owned by
1606 the obstack that owns the DIE. */
1607 const char *comp_dir
;
1609 /* If we needed to build a new string for comp_dir, this is what
1610 owns the storage. */
1611 std::string comp_dir_storage
;
1614 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1615 struct dwarf2_cu
*cu
);
1617 static htab_up
allocate_signatured_type_table ();
1619 static htab_up
allocate_dwo_unit_table ();
1621 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1622 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1623 struct dwp_file
*dwp_file
, const char *comp_dir
,
1624 ULONGEST signature
, int is_debug_types
);
1626 static struct dwp_file
*get_dwp_file
1627 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1629 static struct dwo_unit
*lookup_dwo_comp_unit
1630 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1632 static struct dwo_unit
*lookup_dwo_type_unit
1633 (struct signatured_type
*, const char *, const char *);
1635 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1637 /* A unique pointer to a dwo_file. */
1639 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1641 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1643 static void check_producer (struct dwarf2_cu
*cu
);
1645 static void free_line_header_voidp (void *arg
);
1647 /* Various complaints about symbol reading that don't abort the process. */
1650 dwarf2_debug_line_missing_file_complaint (void)
1652 complaint (_(".debug_line section has line data without a file"));
1656 dwarf2_debug_line_missing_end_sequence_complaint (void)
1658 complaint (_(".debug_line section has line "
1659 "program sequence without an end"));
1663 dwarf2_complex_location_expr_complaint (void)
1665 complaint (_("location expression too complex"));
1669 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1672 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1677 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1679 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1683 /* Hash function for line_header_hash. */
1686 line_header_hash (const struct line_header
*ofs
)
1688 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1691 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1694 line_header_hash_voidp (const void *item
)
1696 const struct line_header
*ofs
= (const struct line_header
*) item
;
1698 return line_header_hash (ofs
);
1701 /* Equality function for line_header_hash. */
1704 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1706 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1707 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1709 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1710 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1715 /* See declaration. */
1717 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1718 const dwarf2_debug_sections
*names
,
1720 : objfile (objfile_
),
1721 can_copy (can_copy_
)
1724 names
= &dwarf2_elf_names
;
1726 bfd
*obfd
= objfile
->obfd
;
1728 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1729 locate_sections (obfd
, sec
, *names
);
1732 dwarf2_per_objfile::~dwarf2_per_objfile ()
1734 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1735 free_cached_comp_units ();
1737 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1738 per_cu
->imported_symtabs_free ();
1740 for (signatured_type
*sig_type
: all_type_units
)
1741 sig_type
->per_cu
.imported_symtabs_free ();
1743 /* Everything else should be on the objfile obstack. */
1746 /* See declaration. */
1749 dwarf2_per_objfile::free_cached_comp_units ()
1751 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1752 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1753 while (per_cu
!= NULL
)
1755 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1758 *last_chain
= next_cu
;
1763 /* A helper class that calls free_cached_comp_units on
1766 class free_cached_comp_units
1770 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1771 : m_per_objfile (per_objfile
)
1775 ~free_cached_comp_units ()
1777 m_per_objfile
->free_cached_comp_units ();
1780 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1784 dwarf2_per_objfile
*m_per_objfile
;
1787 /* Try to locate the sections we need for DWARF 2 debugging
1788 information and return true if we have enough to do something.
1789 NAMES points to the dwarf2 section names, or is NULL if the standard
1790 ELF names are used. CAN_COPY is true for formats where symbol
1791 interposition is possible and so symbol values must follow copy
1792 relocation rules. */
1795 dwarf2_has_info (struct objfile
*objfile
,
1796 const struct dwarf2_debug_sections
*names
,
1799 if (objfile
->flags
& OBJF_READNEVER
)
1802 struct dwarf2_per_objfile
*dwarf2_per_objfile
1803 = get_dwarf2_per_objfile (objfile
);
1805 if (dwarf2_per_objfile
== NULL
)
1806 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1810 return (!dwarf2_per_objfile
->info
.is_virtual
1811 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1812 && !dwarf2_per_objfile
->abbrev
.is_virtual
1813 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1816 /* When loading sections, we look either for uncompressed section or for
1817 compressed section names. */
1820 section_is_p (const char *section_name
,
1821 const struct dwarf2_section_names
*names
)
1823 if (names
->normal
!= NULL
1824 && strcmp (section_name
, names
->normal
) == 0)
1826 if (names
->compressed
!= NULL
1827 && strcmp (section_name
, names
->compressed
) == 0)
1832 /* See declaration. */
1835 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1836 const dwarf2_debug_sections
&names
)
1838 flagword aflag
= bfd_section_flags (sectp
);
1840 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1843 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1844 > bfd_get_file_size (abfd
))
1846 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1847 warning (_("Discarding section %s which has a section size (%s"
1848 ") larger than the file size [in module %s]"),
1849 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1850 bfd_get_filename (abfd
));
1852 else if (section_is_p (sectp
->name
, &names
.info
))
1854 this->info
.s
.section
= sectp
;
1855 this->info
.size
= bfd_section_size (sectp
);
1857 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1859 this->abbrev
.s
.section
= sectp
;
1860 this->abbrev
.size
= bfd_section_size (sectp
);
1862 else if (section_is_p (sectp
->name
, &names
.line
))
1864 this->line
.s
.section
= sectp
;
1865 this->line
.size
= bfd_section_size (sectp
);
1867 else if (section_is_p (sectp
->name
, &names
.loc
))
1869 this->loc
.s
.section
= sectp
;
1870 this->loc
.size
= bfd_section_size (sectp
);
1872 else if (section_is_p (sectp
->name
, &names
.loclists
))
1874 this->loclists
.s
.section
= sectp
;
1875 this->loclists
.size
= bfd_section_size (sectp
);
1877 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1879 this->macinfo
.s
.section
= sectp
;
1880 this->macinfo
.size
= bfd_section_size (sectp
);
1882 else if (section_is_p (sectp
->name
, &names
.macro
))
1884 this->macro
.s
.section
= sectp
;
1885 this->macro
.size
= bfd_section_size (sectp
);
1887 else if (section_is_p (sectp
->name
, &names
.str
))
1889 this->str
.s
.section
= sectp
;
1890 this->str
.size
= bfd_section_size (sectp
);
1892 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1894 this->str_offsets
.s
.section
= sectp
;
1895 this->str_offsets
.size
= bfd_section_size (sectp
);
1897 else if (section_is_p (sectp
->name
, &names
.line_str
))
1899 this->line_str
.s
.section
= sectp
;
1900 this->line_str
.size
= bfd_section_size (sectp
);
1902 else if (section_is_p (sectp
->name
, &names
.addr
))
1904 this->addr
.s
.section
= sectp
;
1905 this->addr
.size
= bfd_section_size (sectp
);
1907 else if (section_is_p (sectp
->name
, &names
.frame
))
1909 this->frame
.s
.section
= sectp
;
1910 this->frame
.size
= bfd_section_size (sectp
);
1912 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1914 this->eh_frame
.s
.section
= sectp
;
1915 this->eh_frame
.size
= bfd_section_size (sectp
);
1917 else if (section_is_p (sectp
->name
, &names
.ranges
))
1919 this->ranges
.s
.section
= sectp
;
1920 this->ranges
.size
= bfd_section_size (sectp
);
1922 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1924 this->rnglists
.s
.section
= sectp
;
1925 this->rnglists
.size
= bfd_section_size (sectp
);
1927 else if (section_is_p (sectp
->name
, &names
.types
))
1929 struct dwarf2_section_info type_section
;
1931 memset (&type_section
, 0, sizeof (type_section
));
1932 type_section
.s
.section
= sectp
;
1933 type_section
.size
= bfd_section_size (sectp
);
1935 this->types
.push_back (type_section
);
1937 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1939 this->gdb_index
.s
.section
= sectp
;
1940 this->gdb_index
.size
= bfd_section_size (sectp
);
1942 else if (section_is_p (sectp
->name
, &names
.debug_names
))
1944 this->debug_names
.s
.section
= sectp
;
1945 this->debug_names
.size
= bfd_section_size (sectp
);
1947 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
1949 this->debug_aranges
.s
.section
= sectp
;
1950 this->debug_aranges
.size
= bfd_section_size (sectp
);
1953 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1954 && bfd_section_vma (sectp
) == 0)
1955 this->has_section_at_zero
= true;
1958 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1962 dwarf2_get_section_info (struct objfile
*objfile
,
1963 enum dwarf2_section_enum sect
,
1964 asection
**sectp
, const gdb_byte
**bufp
,
1965 bfd_size_type
*sizep
)
1967 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
1968 struct dwarf2_section_info
*info
;
1970 /* We may see an objfile without any DWARF, in which case we just
1981 case DWARF2_DEBUG_FRAME
:
1982 info
= &data
->frame
;
1984 case DWARF2_EH_FRAME
:
1985 info
= &data
->eh_frame
;
1988 gdb_assert_not_reached ("unexpected section");
1991 info
->read (objfile
);
1993 *sectp
= info
->get_bfd_section ();
1994 *bufp
= info
->buffer
;
1995 *sizep
= info
->size
;
1998 /* A helper function to find the sections for a .dwz file. */
2001 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2003 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2005 /* Note that we only support the standard ELF names, because .dwz
2006 is ELF-only (at the time of writing). */
2007 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2009 dwz_file
->abbrev
.s
.section
= sectp
;
2010 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2012 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2014 dwz_file
->info
.s
.section
= sectp
;
2015 dwz_file
->info
.size
= bfd_section_size (sectp
);
2017 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2019 dwz_file
->str
.s
.section
= sectp
;
2020 dwz_file
->str
.size
= bfd_section_size (sectp
);
2022 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2024 dwz_file
->line
.s
.section
= sectp
;
2025 dwz_file
->line
.size
= bfd_section_size (sectp
);
2027 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2029 dwz_file
->macro
.s
.section
= sectp
;
2030 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2032 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2034 dwz_file
->gdb_index
.s
.section
= sectp
;
2035 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2037 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2039 dwz_file
->debug_names
.s
.section
= sectp
;
2040 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2044 /* See dwarf2read.h. */
2047 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2049 const char *filename
;
2050 bfd_size_type buildid_len_arg
;
2054 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2055 return dwarf2_per_objfile
->dwz_file
.get ();
2057 bfd_set_error (bfd_error_no_error
);
2058 gdb::unique_xmalloc_ptr
<char> data
2059 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2060 &buildid_len_arg
, &buildid
));
2063 if (bfd_get_error () == bfd_error_no_error
)
2065 error (_("could not read '.gnu_debugaltlink' section: %s"),
2066 bfd_errmsg (bfd_get_error ()));
2069 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2071 buildid_len
= (size_t) buildid_len_arg
;
2073 filename
= data
.get ();
2075 std::string abs_storage
;
2076 if (!IS_ABSOLUTE_PATH (filename
))
2078 gdb::unique_xmalloc_ptr
<char> abs
2079 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2081 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2082 filename
= abs_storage
.c_str ();
2085 /* First try the file name given in the section. If that doesn't
2086 work, try to use the build-id instead. */
2087 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2088 if (dwz_bfd
!= NULL
)
2090 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2091 dwz_bfd
.reset (nullptr);
2094 if (dwz_bfd
== NULL
)
2095 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2097 if (dwz_bfd
== nullptr)
2099 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2100 const char *origname
= dwarf2_per_objfile
->objfile
->original_name
;
2102 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2109 /* File successfully retrieved from server. */
2110 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
, -1);
2112 if (dwz_bfd
== nullptr)
2113 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2114 alt_filename
.get ());
2115 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2116 dwz_bfd
.reset (nullptr);
2120 if (dwz_bfd
== NULL
)
2121 error (_("could not find '.gnu_debugaltlink' file for %s"),
2122 objfile_name (dwarf2_per_objfile
->objfile
));
2124 std::unique_ptr
<struct dwz_file
> result
2125 (new struct dwz_file (std::move (dwz_bfd
)));
2127 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2130 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2131 result
->dwz_bfd
.get ());
2132 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2133 return dwarf2_per_objfile
->dwz_file
.get ();
2136 /* DWARF quick_symbols_functions support. */
2138 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2139 unique line tables, so we maintain a separate table of all .debug_line
2140 derived entries to support the sharing.
2141 All the quick functions need is the list of file names. We discard the
2142 line_header when we're done and don't need to record it here. */
2143 struct quick_file_names
2145 /* The data used to construct the hash key. */
2146 struct stmt_list_hash hash
;
2148 /* The number of entries in file_names, real_names. */
2149 unsigned int num_file_names
;
2151 /* The file names from the line table, after being run through
2153 const char **file_names
;
2155 /* The file names from the line table after being run through
2156 gdb_realpath. These are computed lazily. */
2157 const char **real_names
;
2160 /* When using the index (and thus not using psymtabs), each CU has an
2161 object of this type. This is used to hold information needed by
2162 the various "quick" methods. */
2163 struct dwarf2_per_cu_quick_data
2165 /* The file table. This can be NULL if there was no file table
2166 or it's currently not read in.
2167 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2168 struct quick_file_names
*file_names
;
2170 /* The corresponding symbol table. This is NULL if symbols for this
2171 CU have not yet been read. */
2172 struct compunit_symtab
*compunit_symtab
;
2174 /* A temporary mark bit used when iterating over all CUs in
2175 expand_symtabs_matching. */
2176 unsigned int mark
: 1;
2178 /* True if we've tried to read the file table and found there isn't one.
2179 There will be no point in trying to read it again next time. */
2180 unsigned int no_file_data
: 1;
2183 /* Utility hash function for a stmt_list_hash. */
2186 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2190 if (stmt_list_hash
->dwo_unit
!= NULL
)
2191 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2192 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2196 /* Utility equality function for a stmt_list_hash. */
2199 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2200 const struct stmt_list_hash
*rhs
)
2202 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2204 if (lhs
->dwo_unit
!= NULL
2205 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2208 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2211 /* Hash function for a quick_file_names. */
2214 hash_file_name_entry (const void *e
)
2216 const struct quick_file_names
*file_data
2217 = (const struct quick_file_names
*) e
;
2219 return hash_stmt_list_entry (&file_data
->hash
);
2222 /* Equality function for a quick_file_names. */
2225 eq_file_name_entry (const void *a
, const void *b
)
2227 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2228 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2230 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2233 /* Delete function for a quick_file_names. */
2236 delete_file_name_entry (void *e
)
2238 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2241 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2243 xfree ((void*) file_data
->file_names
[i
]);
2244 if (file_data
->real_names
)
2245 xfree ((void*) file_data
->real_names
[i
]);
2248 /* The space for the struct itself lives on objfile_obstack,
2249 so we don't free it here. */
2252 /* Create a quick_file_names hash table. */
2255 create_quick_file_names_table (unsigned int nr_initial_entries
)
2257 return htab_up (htab_create_alloc (nr_initial_entries
,
2258 hash_file_name_entry
, eq_file_name_entry
,
2259 delete_file_name_entry
, xcalloc
, xfree
));
2262 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2263 have to be created afterwards. You should call age_cached_comp_units after
2264 processing PER_CU->CU. dw2_setup must have been already called. */
2267 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2269 if (per_cu
->is_debug_types
)
2270 load_full_type_unit (per_cu
);
2272 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2274 if (per_cu
->cu
== NULL
)
2275 return; /* Dummy CU. */
2277 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2280 /* Read in the symbols for PER_CU. */
2283 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2285 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2287 /* Skip type_unit_groups, reading the type units they contain
2288 is handled elsewhere. */
2289 if (per_cu
->type_unit_group_p ())
2292 /* The destructor of dwarf2_queue_guard frees any entries left on
2293 the queue. After this point we're guaranteed to leave this function
2294 with the dwarf queue empty. */
2295 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2297 if (dwarf2_per_objfile
->using_index
2298 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2299 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2301 queue_comp_unit (per_cu
, language_minimal
);
2302 load_cu (per_cu
, skip_partial
);
2304 /* If we just loaded a CU from a DWO, and we're working with an index
2305 that may badly handle TUs, load all the TUs in that DWO as well.
2306 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2307 if (!per_cu
->is_debug_types
2308 && per_cu
->cu
!= NULL
2309 && per_cu
->cu
->dwo_unit
!= NULL
2310 && dwarf2_per_objfile
->index_table
!= NULL
2311 && dwarf2_per_objfile
->index_table
->version
<= 7
2312 /* DWP files aren't supported yet. */
2313 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2314 queue_and_load_all_dwo_tus (per_cu
);
2317 process_queue (dwarf2_per_objfile
);
2319 /* Age the cache, releasing compilation units that have not
2320 been used recently. */
2321 age_cached_comp_units (dwarf2_per_objfile
);
2324 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2325 the objfile from which this CU came. Returns the resulting symbol
2328 static struct compunit_symtab
*
2329 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2331 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2333 gdb_assert (dwarf2_per_objfile
->using_index
);
2334 if (!per_cu
->v
.quick
->compunit_symtab
)
2336 free_cached_comp_units
freer (dwarf2_per_objfile
);
2337 scoped_restore decrementer
= increment_reading_symtab ();
2338 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2339 process_cu_includes (dwarf2_per_objfile
);
2342 return per_cu
->v
.quick
->compunit_symtab
;
2345 /* See declaration. */
2347 dwarf2_per_cu_data
*
2348 dwarf2_per_objfile::get_cutu (int index
)
2350 if (index
>= this->all_comp_units
.size ())
2352 index
-= this->all_comp_units
.size ();
2353 gdb_assert (index
< this->all_type_units
.size ());
2354 return &this->all_type_units
[index
]->per_cu
;
2357 return this->all_comp_units
[index
];
2360 /* See declaration. */
2362 dwarf2_per_cu_data
*
2363 dwarf2_per_objfile::get_cu (int index
)
2365 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2367 return this->all_comp_units
[index
];
2370 /* See declaration. */
2373 dwarf2_per_objfile::get_tu (int index
)
2375 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2377 return this->all_type_units
[index
];
2380 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2381 objfile_obstack, and constructed with the specified field
2384 static dwarf2_per_cu_data
*
2385 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2386 struct dwarf2_section_info
*section
,
2388 sect_offset sect_off
, ULONGEST length
)
2390 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2391 dwarf2_per_cu_data
*the_cu
2392 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2393 struct dwarf2_per_cu_data
);
2394 the_cu
->sect_off
= sect_off
;
2395 the_cu
->length
= length
;
2396 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2397 the_cu
->section
= section
;
2398 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2399 struct dwarf2_per_cu_quick_data
);
2400 the_cu
->is_dwz
= is_dwz
;
2404 /* A helper for create_cus_from_index that handles a given list of
2408 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2409 const gdb_byte
*cu_list
, offset_type n_elements
,
2410 struct dwarf2_section_info
*section
,
2413 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2415 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2417 sect_offset sect_off
2418 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2419 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2422 dwarf2_per_cu_data
*per_cu
2423 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2425 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2429 /* Read the CU list from the mapped index, and use it to create all
2430 the CU objects for this objfile. */
2433 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2434 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2435 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2437 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2438 dwarf2_per_objfile
->all_comp_units
.reserve
2439 ((cu_list_elements
+ dwz_elements
) / 2);
2441 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2442 &dwarf2_per_objfile
->info
, 0);
2444 if (dwz_elements
== 0)
2447 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2448 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2452 /* Create the signatured type hash table from the index. */
2455 create_signatured_type_table_from_index
2456 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2457 struct dwarf2_section_info
*section
,
2458 const gdb_byte
*bytes
,
2459 offset_type elements
)
2461 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2463 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2464 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2466 htab_up sig_types_hash
= allocate_signatured_type_table ();
2468 for (offset_type i
= 0; i
< elements
; i
+= 3)
2470 struct signatured_type
*sig_type
;
2473 cu_offset type_offset_in_tu
;
2475 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2476 sect_offset sect_off
2477 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2479 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2481 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2484 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2485 struct signatured_type
);
2486 sig_type
->signature
= signature
;
2487 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2488 sig_type
->per_cu
.is_debug_types
= 1;
2489 sig_type
->per_cu
.section
= section
;
2490 sig_type
->per_cu
.sect_off
= sect_off
;
2491 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2492 sig_type
->per_cu
.v
.quick
2493 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2494 struct dwarf2_per_cu_quick_data
);
2496 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2499 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2502 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2505 /* Create the signatured type hash table from .debug_names. */
2508 create_signatured_type_table_from_debug_names
2509 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2510 const mapped_debug_names
&map
,
2511 struct dwarf2_section_info
*section
,
2512 struct dwarf2_section_info
*abbrev_section
)
2514 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2516 section
->read (objfile
);
2517 abbrev_section
->read (objfile
);
2519 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2520 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2522 htab_up sig_types_hash
= allocate_signatured_type_table ();
2524 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2526 struct signatured_type
*sig_type
;
2529 sect_offset sect_off
2530 = (sect_offset
) (extract_unsigned_integer
2531 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2533 map
.dwarf5_byte_order
));
2535 comp_unit_head cu_header
;
2536 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2538 section
->buffer
+ to_underlying (sect_off
),
2541 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2542 struct signatured_type
);
2543 sig_type
->signature
= cu_header
.signature
;
2544 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2545 sig_type
->per_cu
.is_debug_types
= 1;
2546 sig_type
->per_cu
.section
= section
;
2547 sig_type
->per_cu
.sect_off
= sect_off
;
2548 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2549 sig_type
->per_cu
.v
.quick
2550 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2551 struct dwarf2_per_cu_quick_data
);
2553 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2556 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2559 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2562 /* Read the address map data from the mapped index, and use it to
2563 populate the objfile's psymtabs_addrmap. */
2566 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2567 struct mapped_index
*index
)
2569 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2570 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2571 const gdb_byte
*iter
, *end
;
2572 struct addrmap
*mutable_map
;
2575 auto_obstack temp_obstack
;
2577 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2579 iter
= index
->address_table
.data ();
2580 end
= iter
+ index
->address_table
.size ();
2582 baseaddr
= objfile
->text_section_offset ();
2586 ULONGEST hi
, lo
, cu_index
;
2587 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2589 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2591 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2596 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2597 hex_string (lo
), hex_string (hi
));
2601 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2603 complaint (_(".gdb_index address table has invalid CU number %u"),
2604 (unsigned) cu_index
);
2608 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2609 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2610 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2611 dwarf2_per_objfile
->get_cu (cu_index
));
2614 objfile
->partial_symtabs
->psymtabs_addrmap
2615 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2618 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2619 populate the objfile's psymtabs_addrmap. */
2622 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2623 struct dwarf2_section_info
*section
)
2625 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2626 bfd
*abfd
= objfile
->obfd
;
2627 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2628 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2630 auto_obstack temp_obstack
;
2631 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2633 std::unordered_map
<sect_offset
,
2634 dwarf2_per_cu_data
*,
2635 gdb::hash_enum
<sect_offset
>>
2636 debug_info_offset_to_per_cu
;
2637 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2639 const auto insertpair
2640 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2641 if (!insertpair
.second
)
2643 warning (_("Section .debug_aranges in %s has duplicate "
2644 "debug_info_offset %s, ignoring .debug_aranges."),
2645 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2650 section
->read (objfile
);
2652 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2654 const gdb_byte
*addr
= section
->buffer
;
2656 while (addr
< section
->buffer
+ section
->size
)
2658 const gdb_byte
*const entry_addr
= addr
;
2659 unsigned int bytes_read
;
2661 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2665 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2666 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2667 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2668 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2670 warning (_("Section .debug_aranges in %s entry at offset %s "
2671 "length %s exceeds section length %s, "
2672 "ignoring .debug_aranges."),
2673 objfile_name (objfile
),
2674 plongest (entry_addr
- section
->buffer
),
2675 plongest (bytes_read
+ entry_length
),
2676 pulongest (section
->size
));
2680 /* The version number. */
2681 const uint16_t version
= read_2_bytes (abfd
, addr
);
2685 warning (_("Section .debug_aranges in %s entry at offset %s "
2686 "has unsupported version %d, ignoring .debug_aranges."),
2687 objfile_name (objfile
),
2688 plongest (entry_addr
- section
->buffer
), version
);
2692 const uint64_t debug_info_offset
2693 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2694 addr
+= offset_size
;
2695 const auto per_cu_it
2696 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2697 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2699 warning (_("Section .debug_aranges in %s entry at offset %s "
2700 "debug_info_offset %s does not exists, "
2701 "ignoring .debug_aranges."),
2702 objfile_name (objfile
),
2703 plongest (entry_addr
- section
->buffer
),
2704 pulongest (debug_info_offset
));
2707 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2709 const uint8_t address_size
= *addr
++;
2710 if (address_size
< 1 || address_size
> 8)
2712 warning (_("Section .debug_aranges in %s entry at offset %s "
2713 "address_size %u is invalid, ignoring .debug_aranges."),
2714 objfile_name (objfile
),
2715 plongest (entry_addr
- section
->buffer
), address_size
);
2719 const uint8_t segment_selector_size
= *addr
++;
2720 if (segment_selector_size
!= 0)
2722 warning (_("Section .debug_aranges in %s entry at offset %s "
2723 "segment_selector_size %u is not supported, "
2724 "ignoring .debug_aranges."),
2725 objfile_name (objfile
),
2726 plongest (entry_addr
- section
->buffer
),
2727 segment_selector_size
);
2731 /* Must pad to an alignment boundary that is twice the address
2732 size. It is undocumented by the DWARF standard but GCC does
2734 for (size_t padding
= ((-(addr
- section
->buffer
))
2735 & (2 * address_size
- 1));
2736 padding
> 0; padding
--)
2739 warning (_("Section .debug_aranges in %s entry at offset %s "
2740 "padding is not zero, ignoring .debug_aranges."),
2741 objfile_name (objfile
),
2742 plongest (entry_addr
- section
->buffer
));
2748 if (addr
+ 2 * address_size
> entry_end
)
2750 warning (_("Section .debug_aranges in %s entry at offset %s "
2751 "address list is not properly terminated, "
2752 "ignoring .debug_aranges."),
2753 objfile_name (objfile
),
2754 plongest (entry_addr
- section
->buffer
));
2757 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2759 addr
+= address_size
;
2760 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2762 addr
+= address_size
;
2763 if (start
== 0 && length
== 0)
2765 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2767 /* Symbol was eliminated due to a COMDAT group. */
2770 ULONGEST end
= start
+ length
;
2771 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2773 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2775 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2779 objfile
->partial_symtabs
->psymtabs_addrmap
2780 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2783 /* Find a slot in the mapped index INDEX for the object named NAME.
2784 If NAME is found, set *VEC_OUT to point to the CU vector in the
2785 constant pool and return true. If NAME cannot be found, return
2789 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2790 offset_type
**vec_out
)
2793 offset_type slot
, step
;
2794 int (*cmp
) (const char *, const char *);
2796 gdb::unique_xmalloc_ptr
<char> without_params
;
2797 if (current_language
->la_language
== language_cplus
2798 || current_language
->la_language
== language_fortran
2799 || current_language
->la_language
== language_d
)
2801 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2804 if (strchr (name
, '(') != NULL
)
2806 without_params
= cp_remove_params (name
);
2808 if (without_params
!= NULL
)
2809 name
= without_params
.get ();
2813 /* Index version 4 did not support case insensitive searches. But the
2814 indices for case insensitive languages are built in lowercase, therefore
2815 simulate our NAME being searched is also lowercased. */
2816 hash
= mapped_index_string_hash ((index
->version
== 4
2817 && case_sensitivity
== case_sensitive_off
2818 ? 5 : index
->version
),
2821 slot
= hash
& (index
->symbol_table
.size () - 1);
2822 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2823 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2829 const auto &bucket
= index
->symbol_table
[slot
];
2830 if (bucket
.name
== 0 && bucket
.vec
== 0)
2833 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2834 if (!cmp (name
, str
))
2836 *vec_out
= (offset_type
*) (index
->constant_pool
2837 + MAYBE_SWAP (bucket
.vec
));
2841 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2845 /* A helper function that reads the .gdb_index from BUFFER and fills
2846 in MAP. FILENAME is the name of the file containing the data;
2847 it is used for error reporting. DEPRECATED_OK is true if it is
2848 ok to use deprecated sections.
2850 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2851 out parameters that are filled in with information about the CU and
2852 TU lists in the section.
2854 Returns true if all went well, false otherwise. */
2857 read_gdb_index_from_buffer (struct objfile
*objfile
,
2858 const char *filename
,
2860 gdb::array_view
<const gdb_byte
> buffer
,
2861 struct mapped_index
*map
,
2862 const gdb_byte
**cu_list
,
2863 offset_type
*cu_list_elements
,
2864 const gdb_byte
**types_list
,
2865 offset_type
*types_list_elements
)
2867 const gdb_byte
*addr
= &buffer
[0];
2869 /* Version check. */
2870 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2871 /* Versions earlier than 3 emitted every copy of a psymbol. This
2872 causes the index to behave very poorly for certain requests. Version 3
2873 contained incomplete addrmap. So, it seems better to just ignore such
2877 static int warning_printed
= 0;
2878 if (!warning_printed
)
2880 warning (_("Skipping obsolete .gdb_index section in %s."),
2882 warning_printed
= 1;
2886 /* Index version 4 uses a different hash function than index version
2889 Versions earlier than 6 did not emit psymbols for inlined
2890 functions. Using these files will cause GDB not to be able to
2891 set breakpoints on inlined functions by name, so we ignore these
2892 indices unless the user has done
2893 "set use-deprecated-index-sections on". */
2894 if (version
< 6 && !deprecated_ok
)
2896 static int warning_printed
= 0;
2897 if (!warning_printed
)
2900 Skipping deprecated .gdb_index section in %s.\n\
2901 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2902 to use the section anyway."),
2904 warning_printed
= 1;
2908 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2909 of the TU (for symbols coming from TUs),
2910 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2911 Plus gold-generated indices can have duplicate entries for global symbols,
2912 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2913 These are just performance bugs, and we can't distinguish gdb-generated
2914 indices from gold-generated ones, so issue no warning here. */
2916 /* Indexes with higher version than the one supported by GDB may be no
2917 longer backward compatible. */
2921 map
->version
= version
;
2923 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2926 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2927 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2931 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2932 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2933 - MAYBE_SWAP (metadata
[i
]))
2937 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2938 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2940 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2943 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2944 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2946 = gdb::array_view
<mapped_index::symbol_table_slot
>
2947 ((mapped_index::symbol_table_slot
*) symbol_table
,
2948 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2951 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2956 /* Callback types for dwarf2_read_gdb_index. */
2958 typedef gdb::function_view
2959 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2960 get_gdb_index_contents_ftype
;
2961 typedef gdb::function_view
2962 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2963 get_gdb_index_contents_dwz_ftype
;
2965 /* Read .gdb_index. If everything went ok, initialize the "quick"
2966 elements of all the CUs and return 1. Otherwise, return 0. */
2969 dwarf2_read_gdb_index
2970 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2971 get_gdb_index_contents_ftype get_gdb_index_contents
,
2972 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2974 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2975 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2976 struct dwz_file
*dwz
;
2977 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2979 gdb::array_view
<const gdb_byte
> main_index_contents
2980 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
2982 if (main_index_contents
.empty ())
2985 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2986 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
2987 use_deprecated_index_sections
,
2988 main_index_contents
, map
.get (), &cu_list
,
2989 &cu_list_elements
, &types_list
,
2990 &types_list_elements
))
2993 /* Don't use the index if it's empty. */
2994 if (map
->symbol_table
.empty ())
2997 /* If there is a .dwz file, read it so we can get its CU list as
2999 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3002 struct mapped_index dwz_map
;
3003 const gdb_byte
*dwz_types_ignore
;
3004 offset_type dwz_types_elements_ignore
;
3006 gdb::array_view
<const gdb_byte
> dwz_index_content
3007 = get_gdb_index_contents_dwz (objfile
, dwz
);
3009 if (dwz_index_content
.empty ())
3012 if (!read_gdb_index_from_buffer (objfile
,
3013 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3014 1, dwz_index_content
, &dwz_map
,
3015 &dwz_list
, &dwz_list_elements
,
3017 &dwz_types_elements_ignore
))
3019 warning (_("could not read '.gdb_index' section from %s; skipping"),
3020 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3025 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3026 dwz_list
, dwz_list_elements
);
3028 if (types_list_elements
)
3030 /* We can only handle a single .debug_types when we have an
3032 if (dwarf2_per_objfile
->types
.size () != 1)
3035 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3037 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3038 types_list
, types_list_elements
);
3041 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3043 dwarf2_per_objfile
->index_table
= std::move (map
);
3044 dwarf2_per_objfile
->using_index
= 1;
3045 dwarf2_per_objfile
->quick_file_names_table
=
3046 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3051 /* die_reader_func for dw2_get_file_names. */
3054 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3055 const gdb_byte
*info_ptr
,
3056 struct die_info
*comp_unit_die
)
3058 struct dwarf2_cu
*cu
= reader
->cu
;
3059 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3060 struct dwarf2_per_objfile
*dwarf2_per_objfile
3061 = cu
->per_cu
->dwarf2_per_objfile
;
3062 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3063 struct dwarf2_per_cu_data
*lh_cu
;
3064 struct attribute
*attr
;
3066 struct quick_file_names
*qfn
;
3068 gdb_assert (! this_cu
->is_debug_types
);
3070 /* Our callers never want to match partial units -- instead they
3071 will match the enclosing full CU. */
3072 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3074 this_cu
->v
.quick
->no_file_data
= 1;
3082 sect_offset line_offset
{};
3084 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3085 if (attr
!= nullptr)
3087 struct quick_file_names find_entry
;
3089 line_offset
= (sect_offset
) DW_UNSND (attr
);
3091 /* We may have already read in this line header (TU line header sharing).
3092 If we have we're done. */
3093 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3094 find_entry
.hash
.line_sect_off
= line_offset
;
3095 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3096 &find_entry
, INSERT
);
3099 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3103 lh
= dwarf_decode_line_header (line_offset
, cu
);
3107 lh_cu
->v
.quick
->no_file_data
= 1;
3111 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3112 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3113 qfn
->hash
.line_sect_off
= line_offset
;
3114 gdb_assert (slot
!= NULL
);
3117 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3120 if (strcmp (fnd
.name
, "<unknown>") != 0)
3123 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3125 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3127 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3128 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3129 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3130 fnd
.comp_dir
).release ();
3131 qfn
->real_names
= NULL
;
3133 lh_cu
->v
.quick
->file_names
= qfn
;
3136 /* A helper for the "quick" functions which attempts to read the line
3137 table for THIS_CU. */
3139 static struct quick_file_names
*
3140 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3142 /* This should never be called for TUs. */
3143 gdb_assert (! this_cu
->is_debug_types
);
3144 /* Nor type unit groups. */
3145 gdb_assert (! this_cu
->type_unit_group_p ());
3147 if (this_cu
->v
.quick
->file_names
!= NULL
)
3148 return this_cu
->v
.quick
->file_names
;
3149 /* If we know there is no line data, no point in looking again. */
3150 if (this_cu
->v
.quick
->no_file_data
)
3153 cutu_reader
reader (this_cu
);
3154 if (!reader
.dummy_p
)
3155 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3157 if (this_cu
->v
.quick
->no_file_data
)
3159 return this_cu
->v
.quick
->file_names
;
3162 /* A helper for the "quick" functions which computes and caches the
3163 real path for a given file name from the line table. */
3166 dw2_get_real_path (struct objfile
*objfile
,
3167 struct quick_file_names
*qfn
, int index
)
3169 if (qfn
->real_names
== NULL
)
3170 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3171 qfn
->num_file_names
, const char *);
3173 if (qfn
->real_names
[index
] == NULL
)
3174 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3176 return qfn
->real_names
[index
];
3179 static struct symtab
*
3180 dw2_find_last_source_symtab (struct objfile
*objfile
)
3182 struct dwarf2_per_objfile
*dwarf2_per_objfile
3183 = get_dwarf2_per_objfile (objfile
);
3184 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3185 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3190 return compunit_primary_filetab (cust
);
3193 /* Traversal function for dw2_forget_cached_source_info. */
3196 dw2_free_cached_file_names (void **slot
, void *info
)
3198 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3200 if (file_data
->real_names
)
3204 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3206 xfree ((void*) file_data
->real_names
[i
]);
3207 file_data
->real_names
[i
] = NULL
;
3215 dw2_forget_cached_source_info (struct objfile
*objfile
)
3217 struct dwarf2_per_objfile
*dwarf2_per_objfile
3218 = get_dwarf2_per_objfile (objfile
);
3220 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3221 dw2_free_cached_file_names
, NULL
);
3224 /* Helper function for dw2_map_symtabs_matching_filename that expands
3225 the symtabs and calls the iterator. */
3228 dw2_map_expand_apply (struct objfile
*objfile
,
3229 struct dwarf2_per_cu_data
*per_cu
,
3230 const char *name
, const char *real_path
,
3231 gdb::function_view
<bool (symtab
*)> callback
)
3233 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3235 /* Don't visit already-expanded CUs. */
3236 if (per_cu
->v
.quick
->compunit_symtab
)
3239 /* This may expand more than one symtab, and we want to iterate over
3241 dw2_instantiate_symtab (per_cu
, false);
3243 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3244 last_made
, callback
);
3247 /* Implementation of the map_symtabs_matching_filename method. */
3250 dw2_map_symtabs_matching_filename
3251 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3252 gdb::function_view
<bool (symtab
*)> callback
)
3254 const char *name_basename
= lbasename (name
);
3255 struct dwarf2_per_objfile
*dwarf2_per_objfile
3256 = get_dwarf2_per_objfile (objfile
);
3258 /* The rule is CUs specify all the files, including those used by
3259 any TU, so there's no need to scan TUs here. */
3261 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3263 /* We only need to look at symtabs not already expanded. */
3264 if (per_cu
->v
.quick
->compunit_symtab
)
3267 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3268 if (file_data
== NULL
)
3271 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3273 const char *this_name
= file_data
->file_names
[j
];
3274 const char *this_real_name
;
3276 if (compare_filenames_for_search (this_name
, name
))
3278 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3284 /* Before we invoke realpath, which can get expensive when many
3285 files are involved, do a quick comparison of the basenames. */
3286 if (! basenames_may_differ
3287 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3290 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3291 if (compare_filenames_for_search (this_real_name
, name
))
3293 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3299 if (real_path
!= NULL
)
3301 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3302 gdb_assert (IS_ABSOLUTE_PATH (name
));
3303 if (this_real_name
!= NULL
3304 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3306 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3318 /* Struct used to manage iterating over all CUs looking for a symbol. */
3320 struct dw2_symtab_iterator
3322 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3323 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3324 /* If set, only look for symbols that match that block. Valid values are
3325 GLOBAL_BLOCK and STATIC_BLOCK. */
3326 gdb::optional
<block_enum
> block_index
;
3327 /* The kind of symbol we're looking for. */
3329 /* The list of CUs from the index entry of the symbol,
3330 or NULL if not found. */
3332 /* The next element in VEC to look at. */
3334 /* The number of elements in VEC, or zero if there is no match. */
3336 /* Have we seen a global version of the symbol?
3337 If so we can ignore all further global instances.
3338 This is to work around gold/15646, inefficient gold-generated
3343 /* Initialize the index symtab iterator ITER. */
3346 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3347 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3348 gdb::optional
<block_enum
> block_index
,
3352 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3353 iter
->block_index
= block_index
;
3354 iter
->domain
= domain
;
3356 iter
->global_seen
= 0;
3358 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3360 /* index is NULL if OBJF_READNOW. */
3361 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3362 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3370 /* Return the next matching CU or NULL if there are no more. */
3372 static struct dwarf2_per_cu_data
*
3373 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3375 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3377 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3379 offset_type cu_index_and_attrs
=
3380 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3381 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3382 gdb_index_symbol_kind symbol_kind
=
3383 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3384 /* Only check the symbol attributes if they're present.
3385 Indices prior to version 7 don't record them,
3386 and indices >= 7 may elide them for certain symbols
3387 (gold does this). */
3389 (dwarf2_per_objfile
->index_table
->version
>= 7
3390 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3392 /* Don't crash on bad data. */
3393 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3394 + dwarf2_per_objfile
->all_type_units
.size ()))
3396 complaint (_(".gdb_index entry has bad CU index"
3398 objfile_name (dwarf2_per_objfile
->objfile
));
3402 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3404 /* Skip if already read in. */
3405 if (per_cu
->v
.quick
->compunit_symtab
)
3408 /* Check static vs global. */
3411 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3413 if (iter
->block_index
.has_value ())
3415 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3417 if (is_static
!= want_static
)
3421 /* Work around gold/15646. */
3422 if (!is_static
&& iter
->global_seen
)
3425 iter
->global_seen
= 1;
3428 /* Only check the symbol's kind if it has one. */
3431 switch (iter
->domain
)
3434 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3435 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3436 /* Some types are also in VAR_DOMAIN. */
3437 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3441 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3445 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3449 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3464 static struct compunit_symtab
*
3465 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3466 const char *name
, domain_enum domain
)
3468 struct compunit_symtab
*stab_best
= NULL
;
3469 struct dwarf2_per_objfile
*dwarf2_per_objfile
3470 = get_dwarf2_per_objfile (objfile
);
3472 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3474 struct dw2_symtab_iterator iter
;
3475 struct dwarf2_per_cu_data
*per_cu
;
3477 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3479 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3481 struct symbol
*sym
, *with_opaque
= NULL
;
3482 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3483 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3484 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3486 sym
= block_find_symbol (block
, name
, domain
,
3487 block_find_non_opaque_type_preferred
,
3490 /* Some caution must be observed with overloaded functions
3491 and methods, since the index will not contain any overload
3492 information (but NAME might contain it). */
3495 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3497 if (with_opaque
!= NULL
3498 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3501 /* Keep looking through other CUs. */
3508 dw2_print_stats (struct objfile
*objfile
)
3510 struct dwarf2_per_objfile
*dwarf2_per_objfile
3511 = get_dwarf2_per_objfile (objfile
);
3512 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3513 + dwarf2_per_objfile
->all_type_units
.size ());
3516 for (int i
= 0; i
< total
; ++i
)
3518 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3520 if (!per_cu
->v
.quick
->compunit_symtab
)
3523 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3524 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3527 /* This dumps minimal information about the index.
3528 It is called via "mt print objfiles".
3529 One use is to verify .gdb_index has been loaded by the
3530 gdb.dwarf2/gdb-index.exp testcase. */
3533 dw2_dump (struct objfile
*objfile
)
3535 struct dwarf2_per_objfile
*dwarf2_per_objfile
3536 = get_dwarf2_per_objfile (objfile
);
3538 gdb_assert (dwarf2_per_objfile
->using_index
);
3539 printf_filtered (".gdb_index:");
3540 if (dwarf2_per_objfile
->index_table
!= NULL
)
3542 printf_filtered (" version %d\n",
3543 dwarf2_per_objfile
->index_table
->version
);
3546 printf_filtered (" faked for \"readnow\"\n");
3547 printf_filtered ("\n");
3551 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3552 const char *func_name
)
3554 struct dwarf2_per_objfile
*dwarf2_per_objfile
3555 = get_dwarf2_per_objfile (objfile
);
3557 struct dw2_symtab_iterator iter
;
3558 struct dwarf2_per_cu_data
*per_cu
;
3560 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3562 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3563 dw2_instantiate_symtab (per_cu
, false);
3568 dw2_expand_all_symtabs (struct objfile
*objfile
)
3570 struct dwarf2_per_objfile
*dwarf2_per_objfile
3571 = get_dwarf2_per_objfile (objfile
);
3572 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3573 + dwarf2_per_objfile
->all_type_units
.size ());
3575 for (int i
= 0; i
< total_units
; ++i
)
3577 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3579 /* We don't want to directly expand a partial CU, because if we
3580 read it with the wrong language, then assertion failures can
3581 be triggered later on. See PR symtab/23010. So, tell
3582 dw2_instantiate_symtab to skip partial CUs -- any important
3583 partial CU will be read via DW_TAG_imported_unit anyway. */
3584 dw2_instantiate_symtab (per_cu
, true);
3589 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3590 const char *fullname
)
3592 struct dwarf2_per_objfile
*dwarf2_per_objfile
3593 = get_dwarf2_per_objfile (objfile
);
3595 /* We don't need to consider type units here.
3596 This is only called for examining code, e.g. expand_line_sal.
3597 There can be an order of magnitude (or more) more type units
3598 than comp units, and we avoid them if we can. */
3600 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3602 /* We only need to look at symtabs not already expanded. */
3603 if (per_cu
->v
.quick
->compunit_symtab
)
3606 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3607 if (file_data
== NULL
)
3610 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3612 const char *this_fullname
= file_data
->file_names
[j
];
3614 if (filename_cmp (this_fullname
, fullname
) == 0)
3616 dw2_instantiate_symtab (per_cu
, false);
3624 dw2_map_matching_symbols
3625 (struct objfile
*objfile
,
3626 const lookup_name_info
&name
, domain_enum domain
,
3628 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3629 symbol_compare_ftype
*ordered_compare
)
3632 struct dwarf2_per_objfile
*dwarf2_per_objfile
3633 = get_dwarf2_per_objfile (objfile
);
3635 if (dwarf2_per_objfile
->index_table
!= nullptr)
3637 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3638 here though if the current language is Ada for a non-Ada objfile
3639 using GNU index. As Ada does not look for non-Ada symbols this
3640 function should just return. */
3644 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3645 inline psym_map_matching_symbols here, assuming all partial symtabs have
3647 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3649 for (compunit_symtab
*cust
: objfile
->compunits ())
3651 const struct block
*block
;
3655 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3656 if (!iterate_over_symbols_terminated (block
, name
,
3662 /* Starting from a search name, return the string that finds the upper
3663 bound of all strings that start with SEARCH_NAME in a sorted name
3664 list. Returns the empty string to indicate that the upper bound is
3665 the end of the list. */
3668 make_sort_after_prefix_name (const char *search_name
)
3670 /* When looking to complete "func", we find the upper bound of all
3671 symbols that start with "func" by looking for where we'd insert
3672 the closest string that would follow "func" in lexicographical
3673 order. Usually, that's "func"-with-last-character-incremented,
3674 i.e. "fund". Mind non-ASCII characters, though. Usually those
3675 will be UTF-8 multi-byte sequences, but we can't be certain.
3676 Especially mind the 0xff character, which is a valid character in
3677 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3678 rule out compilers allowing it in identifiers. Note that
3679 conveniently, strcmp/strcasecmp are specified to compare
3680 characters interpreted as unsigned char. So what we do is treat
3681 the whole string as a base 256 number composed of a sequence of
3682 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3683 to 0, and carries 1 to the following more-significant position.
3684 If the very first character in SEARCH_NAME ends up incremented
3685 and carries/overflows, then the upper bound is the end of the
3686 list. The string after the empty string is also the empty
3689 Some examples of this operation:
3691 SEARCH_NAME => "+1" RESULT
3695 "\xff" "a" "\xff" => "\xff" "b"
3700 Then, with these symbols for example:
3706 completing "func" looks for symbols between "func" and
3707 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3708 which finds "func" and "func1", but not "fund".
3712 funcÿ (Latin1 'ÿ' [0xff])
3716 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3717 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3721 ÿÿ (Latin1 'ÿ' [0xff])
3724 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3725 the end of the list.
3727 std::string after
= search_name
;
3728 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3730 if (!after
.empty ())
3731 after
.back () = (unsigned char) after
.back () + 1;
3735 /* See declaration. */
3737 std::pair
<std::vector
<name_component
>::const_iterator
,
3738 std::vector
<name_component
>::const_iterator
>
3739 mapped_index_base::find_name_components_bounds
3740 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3743 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3745 const char *lang_name
3746 = lookup_name_without_params
.language_lookup_name (lang
);
3748 /* Comparison function object for lower_bound that matches against a
3749 given symbol name. */
3750 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3753 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3754 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3755 return name_cmp (elem_name
, name
) < 0;
3758 /* Comparison function object for upper_bound that matches against a
3759 given symbol name. */
3760 auto lookup_compare_upper
= [&] (const char *name
,
3761 const name_component
&elem
)
3763 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3764 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3765 return name_cmp (name
, elem_name
) < 0;
3768 auto begin
= this->name_components
.begin ();
3769 auto end
= this->name_components
.end ();
3771 /* Find the lower bound. */
3774 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3777 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3780 /* Find the upper bound. */
3783 if (lookup_name_without_params
.completion_mode ())
3785 /* In completion mode, we want UPPER to point past all
3786 symbols names that have the same prefix. I.e., with
3787 these symbols, and completing "func":
3789 function << lower bound
3791 other_function << upper bound
3793 We find the upper bound by looking for the insertion
3794 point of "func"-with-last-character-incremented,
3796 std::string after
= make_sort_after_prefix_name (lang_name
);
3799 return std::lower_bound (lower
, end
, after
.c_str (),
3800 lookup_compare_lower
);
3803 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3806 return {lower
, upper
};
3809 /* See declaration. */
3812 mapped_index_base::build_name_components ()
3814 if (!this->name_components
.empty ())
3817 this->name_components_casing
= case_sensitivity
;
3819 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3821 /* The code below only knows how to break apart components of C++
3822 symbol names (and other languages that use '::' as
3823 namespace/module separator) and Ada symbol names. */
3824 auto count
= this->symbol_name_count ();
3825 for (offset_type idx
= 0; idx
< count
; idx
++)
3827 if (this->symbol_name_slot_invalid (idx
))
3830 const char *name
= this->symbol_name_at (idx
);
3832 /* Add each name component to the name component table. */
3833 unsigned int previous_len
= 0;
3835 if (strstr (name
, "::") != nullptr)
3837 for (unsigned int current_len
= cp_find_first_component (name
);
3838 name
[current_len
] != '\0';
3839 current_len
+= cp_find_first_component (name
+ current_len
))
3841 gdb_assert (name
[current_len
] == ':');
3842 this->name_components
.push_back ({previous_len
, idx
});
3843 /* Skip the '::'. */
3845 previous_len
= current_len
;
3850 /* Handle the Ada encoded (aka mangled) form here. */
3851 for (const char *iter
= strstr (name
, "__");
3853 iter
= strstr (iter
, "__"))
3855 this->name_components
.push_back ({previous_len
, idx
});
3857 previous_len
= iter
- name
;
3861 this->name_components
.push_back ({previous_len
, idx
});
3864 /* Sort name_components elements by name. */
3865 auto name_comp_compare
= [&] (const name_component
&left
,
3866 const name_component
&right
)
3868 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3869 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3871 const char *left_name
= left_qualified
+ left
.name_offset
;
3872 const char *right_name
= right_qualified
+ right
.name_offset
;
3874 return name_cmp (left_name
, right_name
) < 0;
3877 std::sort (this->name_components
.begin (),
3878 this->name_components
.end (),
3882 /* Helper for dw2_expand_symtabs_matching that works with a
3883 mapped_index_base instead of the containing objfile. This is split
3884 to a separate function in order to be able to unit test the
3885 name_components matching using a mock mapped_index_base. For each
3886 symbol name that matches, calls MATCH_CALLBACK, passing it the
3887 symbol's index in the mapped_index_base symbol table. */
3890 dw2_expand_symtabs_matching_symbol
3891 (mapped_index_base
&index
,
3892 const lookup_name_info
&lookup_name_in
,
3893 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3894 enum search_domain kind
,
3895 gdb::function_view
<bool (offset_type
)> match_callback
)
3897 lookup_name_info lookup_name_without_params
3898 = lookup_name_in
.make_ignore_params ();
3900 /* Build the symbol name component sorted vector, if we haven't
3902 index
.build_name_components ();
3904 /* The same symbol may appear more than once in the range though.
3905 E.g., if we're looking for symbols that complete "w", and we have
3906 a symbol named "w1::w2", we'll find the two name components for
3907 that same symbol in the range. To be sure we only call the
3908 callback once per symbol, we first collect the symbol name
3909 indexes that matched in a temporary vector and ignore
3911 std::vector
<offset_type
> matches
;
3913 struct name_and_matcher
3915 symbol_name_matcher_ftype
*matcher
;
3916 const std::string
&name
;
3918 bool operator== (const name_and_matcher
&other
) const
3920 return matcher
== other
.matcher
&& name
== other
.name
;
3924 /* A vector holding all the different symbol name matchers, for all
3926 std::vector
<name_and_matcher
> matchers
;
3928 for (int i
= 0; i
< nr_languages
; i
++)
3930 enum language lang_e
= (enum language
) i
;
3932 const language_defn
*lang
= language_def (lang_e
);
3933 symbol_name_matcher_ftype
*name_matcher
3934 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3936 name_and_matcher key
{
3938 lookup_name_without_params
.language_lookup_name (lang_e
)
3941 /* Don't insert the same comparison routine more than once.
3942 Note that we do this linear walk. This is not a problem in
3943 practice because the number of supported languages is
3945 if (std::find (matchers
.begin (), matchers
.end (), key
)
3948 matchers
.push_back (std::move (key
));
3951 = index
.find_name_components_bounds (lookup_name_without_params
,
3954 /* Now for each symbol name in range, check to see if we have a name
3955 match, and if so, call the MATCH_CALLBACK callback. */
3957 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3959 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3961 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3962 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3965 matches
.push_back (bounds
.first
->idx
);
3969 std::sort (matches
.begin (), matches
.end ());
3971 /* Finally call the callback, once per match. */
3973 for (offset_type idx
: matches
)
3977 if (!match_callback (idx
))
3983 /* Above we use a type wider than idx's for 'prev', since 0 and
3984 (offset_type)-1 are both possible values. */
3985 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3990 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3992 /* A mock .gdb_index/.debug_names-like name index table, enough to
3993 exercise dw2_expand_symtabs_matching_symbol, which works with the
3994 mapped_index_base interface. Builds an index from the symbol list
3995 passed as parameter to the constructor. */
3996 class mock_mapped_index
: public mapped_index_base
3999 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4000 : m_symbol_table (symbols
)
4003 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4005 /* Return the number of names in the symbol table. */
4006 size_t symbol_name_count () const override
4008 return m_symbol_table
.size ();
4011 /* Get the name of the symbol at IDX in the symbol table. */
4012 const char *symbol_name_at (offset_type idx
) const override
4014 return m_symbol_table
[idx
];
4018 gdb::array_view
<const char *> m_symbol_table
;
4021 /* Convenience function that converts a NULL pointer to a "<null>"
4022 string, to pass to print routines. */
4025 string_or_null (const char *str
)
4027 return str
!= NULL
? str
: "<null>";
4030 /* Check if a lookup_name_info built from
4031 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4032 index. EXPECTED_LIST is the list of expected matches, in expected
4033 matching order. If no match expected, then an empty list is
4034 specified. Returns true on success. On failure prints a warning
4035 indicating the file:line that failed, and returns false. */
4038 check_match (const char *file
, int line
,
4039 mock_mapped_index
&mock_index
,
4040 const char *name
, symbol_name_match_type match_type
,
4041 bool completion_mode
,
4042 std::initializer_list
<const char *> expected_list
)
4044 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4046 bool matched
= true;
4048 auto mismatch
= [&] (const char *expected_str
,
4051 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4052 "expected=\"%s\", got=\"%s\"\n"),
4054 (match_type
== symbol_name_match_type::FULL
4056 name
, string_or_null (expected_str
), string_or_null (got
));
4060 auto expected_it
= expected_list
.begin ();
4061 auto expected_end
= expected_list
.end ();
4063 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4065 [&] (offset_type idx
)
4067 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4068 const char *expected_str
4069 = expected_it
== expected_end
? NULL
: *expected_it
++;
4071 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4072 mismatch (expected_str
, matched_name
);
4076 const char *expected_str
4077 = expected_it
== expected_end
? NULL
: *expected_it
++;
4078 if (expected_str
!= NULL
)
4079 mismatch (expected_str
, NULL
);
4084 /* The symbols added to the mock mapped_index for testing (in
4086 static const char *test_symbols
[] = {
4095 "ns2::tmpl<int>::foo2",
4096 "(anonymous namespace)::A::B::C",
4098 /* These are used to check that the increment-last-char in the
4099 matching algorithm for completion doesn't match "t1_fund" when
4100 completing "t1_func". */
4106 /* A UTF-8 name with multi-byte sequences to make sure that
4107 cp-name-parser understands this as a single identifier ("função"
4108 is "function" in PT). */
4111 /* \377 (0xff) is Latin1 'ÿ'. */
4114 /* \377 (0xff) is Latin1 'ÿ'. */
4118 /* A name with all sorts of complications. Starts with "z" to make
4119 it easier for the completion tests below. */
4120 #define Z_SYM_NAME \
4121 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4122 "::tuple<(anonymous namespace)::ui*, " \
4123 "std::default_delete<(anonymous namespace)::ui>, void>"
4128 /* Returns true if the mapped_index_base::find_name_component_bounds
4129 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4130 in completion mode. */
4133 check_find_bounds_finds (mapped_index_base
&index
,
4134 const char *search_name
,
4135 gdb::array_view
<const char *> expected_syms
)
4137 lookup_name_info
lookup_name (search_name
,
4138 symbol_name_match_type::FULL
, true);
4140 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4143 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4144 if (distance
!= expected_syms
.size ())
4147 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4149 auto nc_elem
= bounds
.first
+ exp_elem
;
4150 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4151 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4158 /* Test the lower-level mapped_index::find_name_component_bounds
4162 test_mapped_index_find_name_component_bounds ()
4164 mock_mapped_index
mock_index (test_symbols
);
4166 mock_index
.build_name_components ();
4168 /* Test the lower-level mapped_index::find_name_component_bounds
4169 method in completion mode. */
4171 static const char *expected_syms
[] = {
4176 SELF_CHECK (check_find_bounds_finds (mock_index
,
4177 "t1_func", expected_syms
));
4180 /* Check that the increment-last-char in the name matching algorithm
4181 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4183 static const char *expected_syms1
[] = {
4187 SELF_CHECK (check_find_bounds_finds (mock_index
,
4188 "\377", expected_syms1
));
4190 static const char *expected_syms2
[] = {
4193 SELF_CHECK (check_find_bounds_finds (mock_index
,
4194 "\377\377", expected_syms2
));
4198 /* Test dw2_expand_symtabs_matching_symbol. */
4201 test_dw2_expand_symtabs_matching_symbol ()
4203 mock_mapped_index
mock_index (test_symbols
);
4205 /* We let all tests run until the end even if some fails, for debug
4207 bool any_mismatch
= false;
4209 /* Create the expected symbols list (an initializer_list). Needed
4210 because lists have commas, and we need to pass them to CHECK,
4211 which is a macro. */
4212 #define EXPECT(...) { __VA_ARGS__ }
4214 /* Wrapper for check_match that passes down the current
4215 __FILE__/__LINE__. */
4216 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4217 any_mismatch |= !check_match (__FILE__, __LINE__, \
4219 NAME, MATCH_TYPE, COMPLETION_MODE, \
4222 /* Identity checks. */
4223 for (const char *sym
: test_symbols
)
4225 /* Should be able to match all existing symbols. */
4226 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4229 /* Should be able to match all existing symbols with
4231 std::string with_params
= std::string (sym
) + "(int)";
4232 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4235 /* Should be able to match all existing symbols with
4236 parameters and qualifiers. */
4237 with_params
= std::string (sym
) + " ( int ) const";
4238 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4241 /* This should really find sym, but cp-name-parser.y doesn't
4242 know about lvalue/rvalue qualifiers yet. */
4243 with_params
= std::string (sym
) + " ( int ) &&";
4244 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4248 /* Check that the name matching algorithm for completion doesn't get
4249 confused with Latin1 'ÿ' / 0xff. */
4251 static const char str
[] = "\377";
4252 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4253 EXPECT ("\377", "\377\377123"));
4256 /* Check that the increment-last-char in the matching algorithm for
4257 completion doesn't match "t1_fund" when completing "t1_func". */
4259 static const char str
[] = "t1_func";
4260 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4261 EXPECT ("t1_func", "t1_func1"));
4264 /* Check that completion mode works at each prefix of the expected
4267 static const char str
[] = "function(int)";
4268 size_t len
= strlen (str
);
4271 for (size_t i
= 1; i
< len
; i
++)
4273 lookup
.assign (str
, i
);
4274 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4275 EXPECT ("function"));
4279 /* While "w" is a prefix of both components, the match function
4280 should still only be called once. */
4282 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4284 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4288 /* Same, with a "complicated" symbol. */
4290 static const char str
[] = Z_SYM_NAME
;
4291 size_t len
= strlen (str
);
4294 for (size_t i
= 1; i
< len
; i
++)
4296 lookup
.assign (str
, i
);
4297 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4298 EXPECT (Z_SYM_NAME
));
4302 /* In FULL mode, an incomplete symbol doesn't match. */
4304 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4308 /* A complete symbol with parameters matches any overload, since the
4309 index has no overload info. */
4311 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4312 EXPECT ("std::zfunction", "std::zfunction2"));
4313 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4314 EXPECT ("std::zfunction", "std::zfunction2"));
4315 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4316 EXPECT ("std::zfunction", "std::zfunction2"));
4319 /* Check that whitespace is ignored appropriately. A symbol with a
4320 template argument list. */
4322 static const char expected
[] = "ns::foo<int>";
4323 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4325 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4329 /* Check that whitespace is ignored appropriately. A symbol with a
4330 template argument list that includes a pointer. */
4332 static const char expected
[] = "ns::foo<char*>";
4333 /* Try both completion and non-completion modes. */
4334 static const bool completion_mode
[2] = {false, true};
4335 for (size_t i
= 0; i
< 2; i
++)
4337 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4338 completion_mode
[i
], EXPECT (expected
));
4339 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4340 completion_mode
[i
], EXPECT (expected
));
4342 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4343 completion_mode
[i
], EXPECT (expected
));
4344 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4345 completion_mode
[i
], EXPECT (expected
));
4350 /* Check method qualifiers are ignored. */
4351 static const char expected
[] = "ns::foo<char*>";
4352 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4353 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4354 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4355 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4356 CHECK_MATCH ("foo < char * > ( int ) const",
4357 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4358 CHECK_MATCH ("foo < char * > ( int ) &&",
4359 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4362 /* Test lookup names that don't match anything. */
4364 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4367 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4371 /* Some wild matching tests, exercising "(anonymous namespace)",
4372 which should not be confused with a parameter list. */
4374 static const char *syms
[] = {
4378 "A :: B :: C ( int )",
4383 for (const char *s
: syms
)
4385 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4386 EXPECT ("(anonymous namespace)::A::B::C"));
4391 static const char expected
[] = "ns2::tmpl<int>::foo2";
4392 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4394 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4398 SELF_CHECK (!any_mismatch
);
4407 test_mapped_index_find_name_component_bounds ();
4408 test_dw2_expand_symtabs_matching_symbol ();
4411 }} // namespace selftests::dw2_expand_symtabs_matching
4413 #endif /* GDB_SELF_TEST */
4415 /* If FILE_MATCHER is NULL or if PER_CU has
4416 dwarf2_per_cu_quick_data::MARK set (see
4417 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4418 EXPANSION_NOTIFY on it. */
4421 dw2_expand_symtabs_matching_one
4422 (struct dwarf2_per_cu_data
*per_cu
,
4423 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4424 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4426 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4428 bool symtab_was_null
4429 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4431 dw2_instantiate_symtab (per_cu
, false);
4433 if (expansion_notify
!= NULL
4435 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4436 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4440 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4441 matched, to expand corresponding CUs that were marked. IDX is the
4442 index of the symbol name that matched. */
4445 dw2_expand_marked_cus
4446 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4447 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4448 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4451 offset_type
*vec
, vec_len
, vec_idx
;
4452 bool global_seen
= false;
4453 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4455 vec
= (offset_type
*) (index
.constant_pool
4456 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4457 vec_len
= MAYBE_SWAP (vec
[0]);
4458 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4460 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4461 /* This value is only valid for index versions >= 7. */
4462 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4463 gdb_index_symbol_kind symbol_kind
=
4464 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4465 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4466 /* Only check the symbol attributes if they're present.
4467 Indices prior to version 7 don't record them,
4468 and indices >= 7 may elide them for certain symbols
4469 (gold does this). */
4472 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4474 /* Work around gold/15646. */
4477 if (!is_static
&& global_seen
)
4483 /* Only check the symbol's kind if it has one. */
4488 case VARIABLES_DOMAIN
:
4489 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4492 case FUNCTIONS_DOMAIN
:
4493 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4497 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4500 case MODULES_DOMAIN
:
4501 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4509 /* Don't crash on bad data. */
4510 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4511 + dwarf2_per_objfile
->all_type_units
.size ()))
4513 complaint (_(".gdb_index entry has bad CU index"
4515 objfile_name (dwarf2_per_objfile
->objfile
));
4519 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4520 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4525 /* If FILE_MATCHER is non-NULL, set all the
4526 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4527 that match FILE_MATCHER. */
4530 dw_expand_symtabs_matching_file_matcher
4531 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4532 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4534 if (file_matcher
== NULL
)
4537 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4539 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4541 NULL
, xcalloc
, xfree
));
4542 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4544 NULL
, xcalloc
, xfree
));
4546 /* The rule is CUs specify all the files, including those used by
4547 any TU, so there's no need to scan TUs here. */
4549 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4553 per_cu
->v
.quick
->mark
= 0;
4555 /* We only need to look at symtabs not already expanded. */
4556 if (per_cu
->v
.quick
->compunit_symtab
)
4559 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4560 if (file_data
== NULL
)
4563 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4565 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4567 per_cu
->v
.quick
->mark
= 1;
4571 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4573 const char *this_real_name
;
4575 if (file_matcher (file_data
->file_names
[j
], false))
4577 per_cu
->v
.quick
->mark
= 1;
4581 /* Before we invoke realpath, which can get expensive when many
4582 files are involved, do a quick comparison of the basenames. */
4583 if (!basenames_may_differ
4584 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4588 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4589 if (file_matcher (this_real_name
, false))
4591 per_cu
->v
.quick
->mark
= 1;
4596 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4597 ? visited_found
.get ()
4598 : visited_not_found
.get (),
4605 dw2_expand_symtabs_matching
4606 (struct objfile
*objfile
,
4607 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4608 const lookup_name_info
&lookup_name
,
4609 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4610 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4611 enum search_domain kind
)
4613 struct dwarf2_per_objfile
*dwarf2_per_objfile
4614 = get_dwarf2_per_objfile (objfile
);
4616 /* index_table is NULL if OBJF_READNOW. */
4617 if (!dwarf2_per_objfile
->index_table
)
4620 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4622 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4624 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4626 kind
, [&] (offset_type idx
)
4628 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4629 expansion_notify
, kind
);
4634 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4637 static struct compunit_symtab
*
4638 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4643 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4644 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4647 if (cust
->includes
== NULL
)
4650 for (i
= 0; cust
->includes
[i
]; ++i
)
4652 struct compunit_symtab
*s
= cust
->includes
[i
];
4654 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4662 static struct compunit_symtab
*
4663 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4664 struct bound_minimal_symbol msymbol
,
4666 struct obj_section
*section
,
4669 struct dwarf2_per_cu_data
*data
;
4670 struct compunit_symtab
*result
;
4672 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4675 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4676 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4677 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4681 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4682 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4683 paddress (get_objfile_arch (objfile
), pc
));
4686 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4689 gdb_assert (result
!= NULL
);
4694 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4695 void *data
, int need_fullname
)
4697 struct dwarf2_per_objfile
*dwarf2_per_objfile
4698 = get_dwarf2_per_objfile (objfile
);
4700 if (!dwarf2_per_objfile
->filenames_cache
)
4702 dwarf2_per_objfile
->filenames_cache
.emplace ();
4704 htab_up
visited (htab_create_alloc (10,
4705 htab_hash_pointer
, htab_eq_pointer
,
4706 NULL
, xcalloc
, xfree
));
4708 /* The rule is CUs specify all the files, including those used
4709 by any TU, so there's no need to scan TUs here. We can
4710 ignore file names coming from already-expanded CUs. */
4712 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4714 if (per_cu
->v
.quick
->compunit_symtab
)
4716 void **slot
= htab_find_slot (visited
.get (),
4717 per_cu
->v
.quick
->file_names
,
4720 *slot
= per_cu
->v
.quick
->file_names
;
4724 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4726 /* We only need to look at symtabs not already expanded. */
4727 if (per_cu
->v
.quick
->compunit_symtab
)
4730 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4731 if (file_data
== NULL
)
4734 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4737 /* Already visited. */
4742 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4744 const char *filename
= file_data
->file_names
[j
];
4745 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4750 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4752 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4755 this_real_name
= gdb_realpath (filename
);
4756 (*fun
) (filename
, this_real_name
.get (), data
);
4761 dw2_has_symbols (struct objfile
*objfile
)
4766 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4769 dw2_find_last_source_symtab
,
4770 dw2_forget_cached_source_info
,
4771 dw2_map_symtabs_matching_filename
,
4776 dw2_expand_symtabs_for_function
,
4777 dw2_expand_all_symtabs
,
4778 dw2_expand_symtabs_with_fullname
,
4779 dw2_map_matching_symbols
,
4780 dw2_expand_symtabs_matching
,
4781 dw2_find_pc_sect_compunit_symtab
,
4783 dw2_map_symbol_filenames
4786 /* DWARF-5 debug_names reader. */
4788 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4789 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4791 /* A helper function that reads the .debug_names section in SECTION
4792 and fills in MAP. FILENAME is the name of the file containing the
4793 section; it is used for error reporting.
4795 Returns true if all went well, false otherwise. */
4798 read_debug_names_from_section (struct objfile
*objfile
,
4799 const char *filename
,
4800 struct dwarf2_section_info
*section
,
4801 mapped_debug_names
&map
)
4803 if (section
->empty ())
4806 /* Older elfutils strip versions could keep the section in the main
4807 executable while splitting it for the separate debug info file. */
4808 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4811 section
->read (objfile
);
4813 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4815 const gdb_byte
*addr
= section
->buffer
;
4817 bfd
*const abfd
= section
->get_bfd_owner ();
4819 unsigned int bytes_read
;
4820 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4823 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4824 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4825 if (bytes_read
+ length
!= section
->size
)
4827 /* There may be multiple per-CU indices. */
4828 warning (_("Section .debug_names in %s length %s does not match "
4829 "section length %s, ignoring .debug_names."),
4830 filename
, plongest (bytes_read
+ length
),
4831 pulongest (section
->size
));
4835 /* The version number. */
4836 uint16_t version
= read_2_bytes (abfd
, addr
);
4840 warning (_("Section .debug_names in %s has unsupported version %d, "
4841 "ignoring .debug_names."),
4847 uint16_t padding
= read_2_bytes (abfd
, addr
);
4851 warning (_("Section .debug_names in %s has unsupported padding %d, "
4852 "ignoring .debug_names."),
4857 /* comp_unit_count - The number of CUs in the CU list. */
4858 map
.cu_count
= read_4_bytes (abfd
, addr
);
4861 /* local_type_unit_count - The number of TUs in the local TU
4863 map
.tu_count
= read_4_bytes (abfd
, addr
);
4866 /* foreign_type_unit_count - The number of TUs in the foreign TU
4868 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4870 if (foreign_tu_count
!= 0)
4872 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4873 "ignoring .debug_names."),
4874 filename
, static_cast<unsigned long> (foreign_tu_count
));
4878 /* bucket_count - The number of hash buckets in the hash lookup
4880 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4883 /* name_count - The number of unique names in the index. */
4884 map
.name_count
= read_4_bytes (abfd
, addr
);
4887 /* abbrev_table_size - The size in bytes of the abbreviations
4889 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4892 /* augmentation_string_size - The size in bytes of the augmentation
4893 string. This value is rounded up to a multiple of 4. */
4894 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4896 map
.augmentation_is_gdb
= ((augmentation_string_size
4897 == sizeof (dwarf5_augmentation
))
4898 && memcmp (addr
, dwarf5_augmentation
,
4899 sizeof (dwarf5_augmentation
)) == 0);
4900 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4901 addr
+= augmentation_string_size
;
4904 map
.cu_table_reordered
= addr
;
4905 addr
+= map
.cu_count
* map
.offset_size
;
4907 /* List of Local TUs */
4908 map
.tu_table_reordered
= addr
;
4909 addr
+= map
.tu_count
* map
.offset_size
;
4911 /* Hash Lookup Table */
4912 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4913 addr
+= map
.bucket_count
* 4;
4914 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4915 addr
+= map
.name_count
* 4;
4918 map
.name_table_string_offs_reordered
= addr
;
4919 addr
+= map
.name_count
* map
.offset_size
;
4920 map
.name_table_entry_offs_reordered
= addr
;
4921 addr
+= map
.name_count
* map
.offset_size
;
4923 const gdb_byte
*abbrev_table_start
= addr
;
4926 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4931 const auto insertpair
4932 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4933 if (!insertpair
.second
)
4935 warning (_("Section .debug_names in %s has duplicate index %s, "
4936 "ignoring .debug_names."),
4937 filename
, pulongest (index_num
));
4940 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4941 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4946 mapped_debug_names::index_val::attr attr
;
4947 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4949 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4951 if (attr
.form
== DW_FORM_implicit_const
)
4953 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4957 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4959 indexval
.attr_vec
.push_back (std::move (attr
));
4962 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4964 warning (_("Section .debug_names in %s has abbreviation_table "
4965 "of size %s vs. written as %u, ignoring .debug_names."),
4966 filename
, plongest (addr
- abbrev_table_start
),
4970 map
.entry_pool
= addr
;
4975 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4979 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4980 const mapped_debug_names
&map
,
4981 dwarf2_section_info
§ion
,
4984 sect_offset sect_off_prev
;
4985 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4987 sect_offset sect_off_next
;
4988 if (i
< map
.cu_count
)
4991 = (sect_offset
) (extract_unsigned_integer
4992 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4994 map
.dwarf5_byte_order
));
4997 sect_off_next
= (sect_offset
) section
.size
;
5000 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5001 dwarf2_per_cu_data
*per_cu
5002 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5003 sect_off_prev
, length
);
5004 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5006 sect_off_prev
= sect_off_next
;
5010 /* Read the CU list from the mapped index, and use it to create all
5011 the CU objects for this dwarf2_per_objfile. */
5014 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5015 const mapped_debug_names
&map
,
5016 const mapped_debug_names
&dwz_map
)
5018 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5019 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5021 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5022 dwarf2_per_objfile
->info
,
5023 false /* is_dwz */);
5025 if (dwz_map
.cu_count
== 0)
5028 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5029 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5033 /* Read .debug_names. If everything went ok, initialize the "quick"
5034 elements of all the CUs and return true. Otherwise, return false. */
5037 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5039 std::unique_ptr
<mapped_debug_names
> map
5040 (new mapped_debug_names (dwarf2_per_objfile
));
5041 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5042 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5044 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5045 &dwarf2_per_objfile
->debug_names
,
5049 /* Don't use the index if it's empty. */
5050 if (map
->name_count
== 0)
5053 /* If there is a .dwz file, read it so we can get its CU list as
5055 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5058 if (!read_debug_names_from_section (objfile
,
5059 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5060 &dwz
->debug_names
, dwz_map
))
5062 warning (_("could not read '.debug_names' section from %s; skipping"),
5063 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5068 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5070 if (map
->tu_count
!= 0)
5072 /* We can only handle a single .debug_types when we have an
5074 if (dwarf2_per_objfile
->types
.size () != 1)
5077 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5079 create_signatured_type_table_from_debug_names
5080 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5083 create_addrmap_from_aranges (dwarf2_per_objfile
,
5084 &dwarf2_per_objfile
->debug_aranges
);
5086 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5087 dwarf2_per_objfile
->using_index
= 1;
5088 dwarf2_per_objfile
->quick_file_names_table
=
5089 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5094 /* Type used to manage iterating over all CUs looking for a symbol for
5097 class dw2_debug_names_iterator
5100 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5101 gdb::optional
<block_enum
> block_index
,
5104 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5105 m_addr (find_vec_in_debug_names (map
, name
))
5108 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5109 search_domain search
, uint32_t namei
)
5112 m_addr (find_vec_in_debug_names (map
, namei
))
5115 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5116 block_enum block_index
, domain_enum domain
,
5118 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5119 m_addr (find_vec_in_debug_names (map
, namei
))
5122 /* Return the next matching CU or NULL if there are no more. */
5123 dwarf2_per_cu_data
*next ();
5126 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5128 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5131 /* The internalized form of .debug_names. */
5132 const mapped_debug_names
&m_map
;
5134 /* If set, only look for symbols that match that block. Valid values are
5135 GLOBAL_BLOCK and STATIC_BLOCK. */
5136 const gdb::optional
<block_enum
> m_block_index
;
5138 /* The kind of symbol we're looking for. */
5139 const domain_enum m_domain
= UNDEF_DOMAIN
;
5140 const search_domain m_search
= ALL_DOMAIN
;
5142 /* The list of CUs from the index entry of the symbol, or NULL if
5144 const gdb_byte
*m_addr
;
5148 mapped_debug_names::namei_to_name (uint32_t namei
) const
5150 const ULONGEST namei_string_offs
5151 = extract_unsigned_integer ((name_table_string_offs_reordered
5152 + namei
* offset_size
),
5155 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5159 /* Find a slot in .debug_names for the object named NAME. If NAME is
5160 found, return pointer to its pool data. If NAME cannot be found,
5164 dw2_debug_names_iterator::find_vec_in_debug_names
5165 (const mapped_debug_names
&map
, const char *name
)
5167 int (*cmp
) (const char *, const char *);
5169 gdb::unique_xmalloc_ptr
<char> without_params
;
5170 if (current_language
->la_language
== language_cplus
5171 || current_language
->la_language
== language_fortran
5172 || current_language
->la_language
== language_d
)
5174 /* NAME is already canonical. Drop any qualifiers as
5175 .debug_names does not contain any. */
5177 if (strchr (name
, '(') != NULL
)
5179 without_params
= cp_remove_params (name
);
5180 if (without_params
!= NULL
)
5181 name
= without_params
.get ();
5185 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5187 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5189 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5190 (map
.bucket_table_reordered
5191 + (full_hash
% map
.bucket_count
)), 4,
5192 map
.dwarf5_byte_order
);
5196 if (namei
>= map
.name_count
)
5198 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5200 namei
, map
.name_count
,
5201 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5207 const uint32_t namei_full_hash
5208 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5209 (map
.hash_table_reordered
+ namei
), 4,
5210 map
.dwarf5_byte_order
);
5211 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5214 if (full_hash
== namei_full_hash
)
5216 const char *const namei_string
= map
.namei_to_name (namei
);
5218 #if 0 /* An expensive sanity check. */
5219 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5221 complaint (_("Wrong .debug_names hash for string at index %u "
5223 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5228 if (cmp (namei_string
, name
) == 0)
5230 const ULONGEST namei_entry_offs
5231 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5232 + namei
* map
.offset_size
),
5233 map
.offset_size
, map
.dwarf5_byte_order
);
5234 return map
.entry_pool
+ namei_entry_offs
;
5239 if (namei
>= map
.name_count
)
5245 dw2_debug_names_iterator::find_vec_in_debug_names
5246 (const mapped_debug_names
&map
, uint32_t namei
)
5248 if (namei
>= map
.name_count
)
5250 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5252 namei
, map
.name_count
,
5253 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5257 const ULONGEST namei_entry_offs
5258 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5259 + namei
* map
.offset_size
),
5260 map
.offset_size
, map
.dwarf5_byte_order
);
5261 return map
.entry_pool
+ namei_entry_offs
;
5264 /* See dw2_debug_names_iterator. */
5266 dwarf2_per_cu_data
*
5267 dw2_debug_names_iterator::next ()
5272 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5273 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5274 bfd
*const abfd
= objfile
->obfd
;
5278 unsigned int bytes_read
;
5279 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5280 m_addr
+= bytes_read
;
5284 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5285 if (indexval_it
== m_map
.abbrev_map
.cend ())
5287 complaint (_("Wrong .debug_names undefined abbrev code %s "
5289 pulongest (abbrev
), objfile_name (objfile
));
5292 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5293 enum class symbol_linkage
{
5297 } symbol_linkage_
= symbol_linkage::unknown
;
5298 dwarf2_per_cu_data
*per_cu
= NULL
;
5299 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5304 case DW_FORM_implicit_const
:
5305 ull
= attr
.implicit_const
;
5307 case DW_FORM_flag_present
:
5311 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5312 m_addr
+= bytes_read
;
5315 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5316 dwarf_form_name (attr
.form
),
5317 objfile_name (objfile
));
5320 switch (attr
.dw_idx
)
5322 case DW_IDX_compile_unit
:
5323 /* Don't crash on bad data. */
5324 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5326 complaint (_(".debug_names entry has bad CU index %s"
5329 objfile_name (dwarf2_per_objfile
->objfile
));
5332 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5334 case DW_IDX_type_unit
:
5335 /* Don't crash on bad data. */
5336 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5338 complaint (_(".debug_names entry has bad TU index %s"
5341 objfile_name (dwarf2_per_objfile
->objfile
));
5344 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5346 case DW_IDX_GNU_internal
:
5347 if (!m_map
.augmentation_is_gdb
)
5349 symbol_linkage_
= symbol_linkage::static_
;
5351 case DW_IDX_GNU_external
:
5352 if (!m_map
.augmentation_is_gdb
)
5354 symbol_linkage_
= symbol_linkage::extern_
;
5359 /* Skip if already read in. */
5360 if (per_cu
->v
.quick
->compunit_symtab
)
5363 /* Check static vs global. */
5364 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5366 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5367 const bool symbol_is_static
=
5368 symbol_linkage_
== symbol_linkage::static_
;
5369 if (want_static
!= symbol_is_static
)
5373 /* Match dw2_symtab_iter_next, symbol_kind
5374 and debug_names::psymbol_tag. */
5378 switch (indexval
.dwarf_tag
)
5380 case DW_TAG_variable
:
5381 case DW_TAG_subprogram
:
5382 /* Some types are also in VAR_DOMAIN. */
5383 case DW_TAG_typedef
:
5384 case DW_TAG_structure_type
:
5391 switch (indexval
.dwarf_tag
)
5393 case DW_TAG_typedef
:
5394 case DW_TAG_structure_type
:
5401 switch (indexval
.dwarf_tag
)
5404 case DW_TAG_variable
:
5411 switch (indexval
.dwarf_tag
)
5423 /* Match dw2_expand_symtabs_matching, symbol_kind and
5424 debug_names::psymbol_tag. */
5427 case VARIABLES_DOMAIN
:
5428 switch (indexval
.dwarf_tag
)
5430 case DW_TAG_variable
:
5436 case FUNCTIONS_DOMAIN
:
5437 switch (indexval
.dwarf_tag
)
5439 case DW_TAG_subprogram
:
5446 switch (indexval
.dwarf_tag
)
5448 case DW_TAG_typedef
:
5449 case DW_TAG_structure_type
:
5455 case MODULES_DOMAIN
:
5456 switch (indexval
.dwarf_tag
)
5470 static struct compunit_symtab
*
5471 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5472 const char *name
, domain_enum domain
)
5474 struct dwarf2_per_objfile
*dwarf2_per_objfile
5475 = get_dwarf2_per_objfile (objfile
);
5477 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5480 /* index is NULL if OBJF_READNOW. */
5483 const auto &map
= *mapp
;
5485 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5487 struct compunit_symtab
*stab_best
= NULL
;
5488 struct dwarf2_per_cu_data
*per_cu
;
5489 while ((per_cu
= iter
.next ()) != NULL
)
5491 struct symbol
*sym
, *with_opaque
= NULL
;
5492 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5493 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5494 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5496 sym
= block_find_symbol (block
, name
, domain
,
5497 block_find_non_opaque_type_preferred
,
5500 /* Some caution must be observed with overloaded functions and
5501 methods, since the index will not contain any overload
5502 information (but NAME might contain it). */
5505 && strcmp_iw (sym
->search_name (), name
) == 0)
5507 if (with_opaque
!= NULL
5508 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5511 /* Keep looking through other CUs. */
5517 /* This dumps minimal information about .debug_names. It is called
5518 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5519 uses this to verify that .debug_names has been loaded. */
5522 dw2_debug_names_dump (struct objfile
*objfile
)
5524 struct dwarf2_per_objfile
*dwarf2_per_objfile
5525 = get_dwarf2_per_objfile (objfile
);
5527 gdb_assert (dwarf2_per_objfile
->using_index
);
5528 printf_filtered (".debug_names:");
5529 if (dwarf2_per_objfile
->debug_names_table
)
5530 printf_filtered (" exists\n");
5532 printf_filtered (" faked for \"readnow\"\n");
5533 printf_filtered ("\n");
5537 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5538 const char *func_name
)
5540 struct dwarf2_per_objfile
*dwarf2_per_objfile
5541 = get_dwarf2_per_objfile (objfile
);
5543 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5544 if (dwarf2_per_objfile
->debug_names_table
)
5546 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5548 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5550 struct dwarf2_per_cu_data
*per_cu
;
5551 while ((per_cu
= iter
.next ()) != NULL
)
5552 dw2_instantiate_symtab (per_cu
, false);
5557 dw2_debug_names_map_matching_symbols
5558 (struct objfile
*objfile
,
5559 const lookup_name_info
&name
, domain_enum domain
,
5561 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5562 symbol_compare_ftype
*ordered_compare
)
5564 struct dwarf2_per_objfile
*dwarf2_per_objfile
5565 = get_dwarf2_per_objfile (objfile
);
5567 /* debug_names_table is NULL if OBJF_READNOW. */
5568 if (!dwarf2_per_objfile
->debug_names_table
)
5571 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5572 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5574 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5575 auto matcher
= [&] (const char *symname
)
5577 if (ordered_compare
== nullptr)
5579 return ordered_compare (symname
, match_name
) == 0;
5582 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5583 [&] (offset_type namei
)
5585 /* The name was matched, now expand corresponding CUs that were
5587 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5589 struct dwarf2_per_cu_data
*per_cu
;
5590 while ((per_cu
= iter
.next ()) != NULL
)
5591 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5595 /* It's a shame we couldn't do this inside the
5596 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5597 that have already been expanded. Instead, this loop matches what
5598 the psymtab code does. */
5599 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5601 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5602 if (cust
!= nullptr)
5604 const struct block
*block
5605 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5606 if (!iterate_over_symbols_terminated (block
, name
,
5614 dw2_debug_names_expand_symtabs_matching
5615 (struct objfile
*objfile
,
5616 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5617 const lookup_name_info
&lookup_name
,
5618 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5619 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5620 enum search_domain kind
)
5622 struct dwarf2_per_objfile
*dwarf2_per_objfile
5623 = get_dwarf2_per_objfile (objfile
);
5625 /* debug_names_table is NULL if OBJF_READNOW. */
5626 if (!dwarf2_per_objfile
->debug_names_table
)
5629 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5631 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5633 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5635 kind
, [&] (offset_type namei
)
5637 /* The name was matched, now expand corresponding CUs that were
5639 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5641 struct dwarf2_per_cu_data
*per_cu
;
5642 while ((per_cu
= iter
.next ()) != NULL
)
5643 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5649 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5652 dw2_find_last_source_symtab
,
5653 dw2_forget_cached_source_info
,
5654 dw2_map_symtabs_matching_filename
,
5655 dw2_debug_names_lookup_symbol
,
5658 dw2_debug_names_dump
,
5659 dw2_debug_names_expand_symtabs_for_function
,
5660 dw2_expand_all_symtabs
,
5661 dw2_expand_symtabs_with_fullname
,
5662 dw2_debug_names_map_matching_symbols
,
5663 dw2_debug_names_expand_symtabs_matching
,
5664 dw2_find_pc_sect_compunit_symtab
,
5666 dw2_map_symbol_filenames
5669 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5670 to either a dwarf2_per_objfile or dwz_file object. */
5672 template <typename T
>
5673 static gdb::array_view
<const gdb_byte
>
5674 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5676 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5678 if (section
->empty ())
5681 /* Older elfutils strip versions could keep the section in the main
5682 executable while splitting it for the separate debug info file. */
5683 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5686 section
->read (obj
);
5688 /* dwarf2_section_info::size is a bfd_size_type, while
5689 gdb::array_view works with size_t. On 32-bit hosts, with
5690 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5691 is 32-bit. So we need an explicit narrowing conversion here.
5692 This is fine, because it's impossible to allocate or mmap an
5693 array/buffer larger than what size_t can represent. */
5694 return gdb::make_array_view (section
->buffer
, section
->size
);
5697 /* Lookup the index cache for the contents of the index associated to
5700 static gdb::array_view
<const gdb_byte
>
5701 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5703 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5704 if (build_id
== nullptr)
5707 return global_index_cache
.lookup_gdb_index (build_id
,
5708 &dwarf2_obj
->index_cache_res
);
5711 /* Same as the above, but for DWZ. */
5713 static gdb::array_view
<const gdb_byte
>
5714 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5716 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5717 if (build_id
== nullptr)
5720 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5723 /* See symfile.h. */
5726 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5728 struct dwarf2_per_objfile
*dwarf2_per_objfile
5729 = get_dwarf2_per_objfile (objfile
);
5731 /* If we're about to read full symbols, don't bother with the
5732 indices. In this case we also don't care if some other debug
5733 format is making psymtabs, because they are all about to be
5735 if ((objfile
->flags
& OBJF_READNOW
))
5737 dwarf2_per_objfile
->using_index
= 1;
5738 create_all_comp_units (dwarf2_per_objfile
);
5739 create_all_type_units (dwarf2_per_objfile
);
5740 dwarf2_per_objfile
->quick_file_names_table
5741 = create_quick_file_names_table
5742 (dwarf2_per_objfile
->all_comp_units
.size ());
5744 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5745 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5747 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5749 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5750 struct dwarf2_per_cu_quick_data
);
5753 /* Return 1 so that gdb sees the "quick" functions. However,
5754 these functions will be no-ops because we will have expanded
5756 *index_kind
= dw_index_kind::GDB_INDEX
;
5760 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5762 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5766 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5767 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5768 get_gdb_index_contents_from_section
<dwz_file
>))
5770 *index_kind
= dw_index_kind::GDB_INDEX
;
5774 /* ... otherwise, try to find the index in the index cache. */
5775 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5776 get_gdb_index_contents_from_cache
,
5777 get_gdb_index_contents_from_cache_dwz
))
5779 global_index_cache
.hit ();
5780 *index_kind
= dw_index_kind::GDB_INDEX
;
5784 global_index_cache
.miss ();
5790 /* Build a partial symbol table. */
5793 dwarf2_build_psymtabs (struct objfile
*objfile
)
5795 struct dwarf2_per_objfile
*dwarf2_per_objfile
5796 = get_dwarf2_per_objfile (objfile
);
5798 init_psymbol_list (objfile
, 1024);
5802 /* This isn't really ideal: all the data we allocate on the
5803 objfile's obstack is still uselessly kept around. However,
5804 freeing it seems unsafe. */
5805 psymtab_discarder
psymtabs (objfile
);
5806 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5809 /* (maybe) store an index in the cache. */
5810 global_index_cache
.store (dwarf2_per_objfile
);
5812 catch (const gdb_exception_error
&except
)
5814 exception_print (gdb_stderr
, except
);
5818 /* Find the base address of the compilation unit for range lists and
5819 location lists. It will normally be specified by DW_AT_low_pc.
5820 In DWARF-3 draft 4, the base address could be overridden by
5821 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5822 compilation units with discontinuous ranges. */
5825 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5827 struct attribute
*attr
;
5829 cu
->base_address
.reset ();
5831 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5832 if (attr
!= nullptr)
5833 cu
->base_address
= attr
->value_as_address ();
5836 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5837 if (attr
!= nullptr)
5838 cu
->base_address
= attr
->value_as_address ();
5842 /* Helper function that returns the proper abbrev section for
5845 static struct dwarf2_section_info
*
5846 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5848 struct dwarf2_section_info
*abbrev
;
5849 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5851 if (this_cu
->is_dwz
)
5852 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5854 abbrev
= &dwarf2_per_objfile
->abbrev
;
5859 /* Fetch the abbreviation table offset from a comp or type unit header. */
5862 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5863 struct dwarf2_section_info
*section
,
5864 sect_offset sect_off
)
5866 bfd
*abfd
= section
->get_bfd_owner ();
5867 const gdb_byte
*info_ptr
;
5868 unsigned int initial_length_size
, offset_size
;
5871 section
->read (dwarf2_per_objfile
->objfile
);
5872 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5873 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5874 offset_size
= initial_length_size
== 4 ? 4 : 8;
5875 info_ptr
+= initial_length_size
;
5877 version
= read_2_bytes (abfd
, info_ptr
);
5881 /* Skip unit type and address size. */
5885 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5888 /* A partial symtab that is used only for include files. */
5889 struct dwarf2_include_psymtab
: public partial_symtab
5891 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
5892 : partial_symtab (filename
, objfile
)
5896 void read_symtab (struct objfile
*objfile
) override
5898 expand_psymtab (objfile
);
5901 void expand_psymtab (struct objfile
*objfile
) override
5905 /* It's an include file, no symbols to read for it.
5906 Everything is in the parent symtab. */
5907 expand_dependencies (objfile
);
5911 bool readin_p () const override
5916 struct compunit_symtab
*get_compunit_symtab () const override
5923 bool m_readin
= false;
5926 /* Allocate a new partial symtab for file named NAME and mark this new
5927 partial symtab as being an include of PST. */
5930 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5931 struct objfile
*objfile
)
5933 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
5935 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5937 /* It shares objfile->objfile_obstack. */
5938 subpst
->dirname
= pst
->dirname
;
5941 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5942 subpst
->dependencies
[0] = pst
;
5943 subpst
->number_of_dependencies
= 1;
5946 /* Read the Line Number Program data and extract the list of files
5947 included by the source file represented by PST. Build an include
5948 partial symtab for each of these included files. */
5951 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5952 struct die_info
*die
,
5953 dwarf2_psymtab
*pst
)
5956 struct attribute
*attr
;
5958 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5959 if (attr
!= nullptr)
5960 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5962 return; /* No linetable, so no includes. */
5964 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5965 that we pass in the raw text_low here; that is ok because we're
5966 only decoding the line table to make include partial symtabs, and
5967 so the addresses aren't really used. */
5968 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5969 pst
->raw_text_low (), 1);
5973 hash_signatured_type (const void *item
)
5975 const struct signatured_type
*sig_type
5976 = (const struct signatured_type
*) item
;
5978 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5979 return sig_type
->signature
;
5983 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5985 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5986 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5988 return lhs
->signature
== rhs
->signature
;
5991 /* Allocate a hash table for signatured types. */
5994 allocate_signatured_type_table ()
5996 return htab_up (htab_create_alloc (41,
5997 hash_signatured_type
,
5999 NULL
, xcalloc
, xfree
));
6002 /* A helper function to add a signatured type CU to a table. */
6005 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6007 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6008 std::vector
<signatured_type
*> *all_type_units
6009 = (std::vector
<signatured_type
*> *) datum
;
6011 all_type_units
->push_back (sigt
);
6016 /* A helper for create_debug_types_hash_table. Read types from SECTION
6017 and fill them into TYPES_HTAB. It will process only type units,
6018 therefore DW_UT_type. */
6021 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6022 struct dwo_file
*dwo_file
,
6023 dwarf2_section_info
*section
, htab_up
&types_htab
,
6024 rcuh_kind section_kind
)
6026 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6027 struct dwarf2_section_info
*abbrev_section
;
6029 const gdb_byte
*info_ptr
, *end_ptr
;
6031 abbrev_section
= (dwo_file
!= NULL
6032 ? &dwo_file
->sections
.abbrev
6033 : &dwarf2_per_objfile
->abbrev
);
6035 if (dwarf_read_debug
)
6036 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6037 section
->get_name (),
6038 abbrev_section
->get_file_name ());
6040 section
->read (objfile
);
6041 info_ptr
= section
->buffer
;
6043 if (info_ptr
== NULL
)
6046 /* We can't set abfd until now because the section may be empty or
6047 not present, in which case the bfd is unknown. */
6048 abfd
= section
->get_bfd_owner ();
6050 /* We don't use cutu_reader here because we don't need to read
6051 any dies: the signature is in the header. */
6053 end_ptr
= info_ptr
+ section
->size
;
6054 while (info_ptr
< end_ptr
)
6056 struct signatured_type
*sig_type
;
6057 struct dwo_unit
*dwo_tu
;
6059 const gdb_byte
*ptr
= info_ptr
;
6060 struct comp_unit_head header
;
6061 unsigned int length
;
6063 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6065 /* Initialize it due to a false compiler warning. */
6066 header
.signature
= -1;
6067 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6069 /* We need to read the type's signature in order to build the hash
6070 table, but we don't need anything else just yet. */
6072 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6073 abbrev_section
, ptr
, section_kind
);
6075 length
= header
.get_length ();
6077 /* Skip dummy type units. */
6078 if (ptr
>= info_ptr
+ length
6079 || peek_abbrev_code (abfd
, ptr
) == 0
6080 || header
.unit_type
!= DW_UT_type
)
6086 if (types_htab
== NULL
)
6089 types_htab
= allocate_dwo_unit_table ();
6091 types_htab
= allocate_signatured_type_table ();
6097 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6099 dwo_tu
->dwo_file
= dwo_file
;
6100 dwo_tu
->signature
= header
.signature
;
6101 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6102 dwo_tu
->section
= section
;
6103 dwo_tu
->sect_off
= sect_off
;
6104 dwo_tu
->length
= length
;
6108 /* N.B.: type_offset is not usable if this type uses a DWO file.
6109 The real type_offset is in the DWO file. */
6111 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6112 struct signatured_type
);
6113 sig_type
->signature
= header
.signature
;
6114 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6115 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6116 sig_type
->per_cu
.is_debug_types
= 1;
6117 sig_type
->per_cu
.section
= section
;
6118 sig_type
->per_cu
.sect_off
= sect_off
;
6119 sig_type
->per_cu
.length
= length
;
6122 slot
= htab_find_slot (types_htab
.get (),
6123 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6125 gdb_assert (slot
!= NULL
);
6128 sect_offset dup_sect_off
;
6132 const struct dwo_unit
*dup_tu
6133 = (const struct dwo_unit
*) *slot
;
6135 dup_sect_off
= dup_tu
->sect_off
;
6139 const struct signatured_type
*dup_tu
6140 = (const struct signatured_type
*) *slot
;
6142 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6145 complaint (_("debug type entry at offset %s is duplicate to"
6146 " the entry at offset %s, signature %s"),
6147 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6148 hex_string (header
.signature
));
6150 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6152 if (dwarf_read_debug
> 1)
6153 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6154 sect_offset_str (sect_off
),
6155 hex_string (header
.signature
));
6161 /* Create the hash table of all entries in the .debug_types
6162 (or .debug_types.dwo) section(s).
6163 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6164 otherwise it is NULL.
6166 The result is a pointer to the hash table or NULL if there are no types.
6168 Note: This function processes DWO files only, not DWP files. */
6171 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6172 struct dwo_file
*dwo_file
,
6173 gdb::array_view
<dwarf2_section_info
> type_sections
,
6174 htab_up
&types_htab
)
6176 for (dwarf2_section_info
§ion
: type_sections
)
6177 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6178 types_htab
, rcuh_kind::TYPE
);
6181 /* Create the hash table of all entries in the .debug_types section,
6182 and initialize all_type_units.
6183 The result is zero if there is an error (e.g. missing .debug_types section),
6184 otherwise non-zero. */
6187 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6191 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6192 &dwarf2_per_objfile
->info
, types_htab
,
6193 rcuh_kind::COMPILE
);
6194 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6195 dwarf2_per_objfile
->types
, types_htab
);
6196 if (types_htab
== NULL
)
6198 dwarf2_per_objfile
->signatured_types
= NULL
;
6202 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6204 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6205 dwarf2_per_objfile
->all_type_units
.reserve
6206 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6208 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6209 add_signatured_type_cu_to_table
,
6210 &dwarf2_per_objfile
->all_type_units
);
6215 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6216 If SLOT is non-NULL, it is the entry to use in the hash table.
6217 Otherwise we find one. */
6219 static struct signatured_type
*
6220 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6223 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6225 if (dwarf2_per_objfile
->all_type_units
.size ()
6226 == dwarf2_per_objfile
->all_type_units
.capacity ())
6227 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6229 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6230 struct signatured_type
);
6232 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6233 sig_type
->signature
= sig
;
6234 sig_type
->per_cu
.is_debug_types
= 1;
6235 if (dwarf2_per_objfile
->using_index
)
6237 sig_type
->per_cu
.v
.quick
=
6238 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6239 struct dwarf2_per_cu_quick_data
);
6244 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6247 gdb_assert (*slot
== NULL
);
6249 /* The rest of sig_type must be filled in by the caller. */
6253 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6254 Fill in SIG_ENTRY with DWO_ENTRY. */
6257 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6258 struct signatured_type
*sig_entry
,
6259 struct dwo_unit
*dwo_entry
)
6261 /* Make sure we're not clobbering something we don't expect to. */
6262 gdb_assert (! sig_entry
->per_cu
.queued
);
6263 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6264 if (dwarf2_per_objfile
->using_index
)
6266 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6267 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6270 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6271 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6272 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6273 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6274 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6276 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6277 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6278 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6279 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6280 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6281 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6282 sig_entry
->dwo_unit
= dwo_entry
;
6285 /* Subroutine of lookup_signatured_type.
6286 If we haven't read the TU yet, create the signatured_type data structure
6287 for a TU to be read in directly from a DWO file, bypassing the stub.
6288 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6289 using .gdb_index, then when reading a CU we want to stay in the DWO file
6290 containing that CU. Otherwise we could end up reading several other DWO
6291 files (due to comdat folding) to process the transitive closure of all the
6292 mentioned TUs, and that can be slow. The current DWO file will have every
6293 type signature that it needs.
6294 We only do this for .gdb_index because in the psymtab case we already have
6295 to read all the DWOs to build the type unit groups. */
6297 static struct signatured_type
*
6298 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6300 struct dwarf2_per_objfile
*dwarf2_per_objfile
6301 = cu
->per_cu
->dwarf2_per_objfile
;
6302 struct dwo_file
*dwo_file
;
6303 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6304 struct signatured_type find_sig_entry
, *sig_entry
;
6307 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6309 /* If TU skeletons have been removed then we may not have read in any
6311 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6312 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6314 /* We only ever need to read in one copy of a signatured type.
6315 Use the global signatured_types array to do our own comdat-folding
6316 of types. If this is the first time we're reading this TU, and
6317 the TU has an entry in .gdb_index, replace the recorded data from
6318 .gdb_index with this TU. */
6320 find_sig_entry
.signature
= sig
;
6321 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6322 &find_sig_entry
, INSERT
);
6323 sig_entry
= (struct signatured_type
*) *slot
;
6325 /* We can get here with the TU already read, *or* in the process of being
6326 read. Don't reassign the global entry to point to this DWO if that's
6327 the case. Also note that if the TU is already being read, it may not
6328 have come from a DWO, the program may be a mix of Fission-compiled
6329 code and non-Fission-compiled code. */
6331 /* Have we already tried to read this TU?
6332 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6333 needn't exist in the global table yet). */
6334 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6337 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6338 dwo_unit of the TU itself. */
6339 dwo_file
= cu
->dwo_unit
->dwo_file
;
6341 /* Ok, this is the first time we're reading this TU. */
6342 if (dwo_file
->tus
== NULL
)
6344 find_dwo_entry
.signature
= sig
;
6345 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6347 if (dwo_entry
== NULL
)
6350 /* If the global table doesn't have an entry for this TU, add one. */
6351 if (sig_entry
== NULL
)
6352 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6354 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6355 sig_entry
->per_cu
.tu_read
= 1;
6359 /* Subroutine of lookup_signatured_type.
6360 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6361 then try the DWP file. If the TU stub (skeleton) has been removed then
6362 it won't be in .gdb_index. */
6364 static struct signatured_type
*
6365 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6367 struct dwarf2_per_objfile
*dwarf2_per_objfile
6368 = cu
->per_cu
->dwarf2_per_objfile
;
6369 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6370 struct dwo_unit
*dwo_entry
;
6371 struct signatured_type find_sig_entry
, *sig_entry
;
6374 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6375 gdb_assert (dwp_file
!= NULL
);
6377 /* If TU skeletons have been removed then we may not have read in any
6379 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6380 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6382 find_sig_entry
.signature
= sig
;
6383 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6384 &find_sig_entry
, INSERT
);
6385 sig_entry
= (struct signatured_type
*) *slot
;
6387 /* Have we already tried to read this TU?
6388 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6389 needn't exist in the global table yet). */
6390 if (sig_entry
!= NULL
)
6393 if (dwp_file
->tus
== NULL
)
6395 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6396 sig
, 1 /* is_debug_types */);
6397 if (dwo_entry
== NULL
)
6400 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6401 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6406 /* Lookup a signature based type for DW_FORM_ref_sig8.
6407 Returns NULL if signature SIG is not present in the table.
6408 It is up to the caller to complain about this. */
6410 static struct signatured_type
*
6411 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6413 struct dwarf2_per_objfile
*dwarf2_per_objfile
6414 = cu
->per_cu
->dwarf2_per_objfile
;
6417 && dwarf2_per_objfile
->using_index
)
6419 /* We're in a DWO/DWP file, and we're using .gdb_index.
6420 These cases require special processing. */
6421 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6422 return lookup_dwo_signatured_type (cu
, sig
);
6424 return lookup_dwp_signatured_type (cu
, sig
);
6428 struct signatured_type find_entry
, *entry
;
6430 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6432 find_entry
.signature
= sig
;
6433 entry
= ((struct signatured_type
*)
6434 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6440 /* Low level DIE reading support. */
6442 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6445 init_cu_die_reader (struct die_reader_specs
*reader
,
6446 struct dwarf2_cu
*cu
,
6447 struct dwarf2_section_info
*section
,
6448 struct dwo_file
*dwo_file
,
6449 struct abbrev_table
*abbrev_table
)
6451 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6452 reader
->abfd
= section
->get_bfd_owner ();
6454 reader
->dwo_file
= dwo_file
;
6455 reader
->die_section
= section
;
6456 reader
->buffer
= section
->buffer
;
6457 reader
->buffer_end
= section
->buffer
+ section
->size
;
6458 reader
->abbrev_table
= abbrev_table
;
6461 /* Subroutine of cutu_reader to simplify it.
6462 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6463 There's just a lot of work to do, and cutu_reader is big enough
6466 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6467 from it to the DIE in the DWO. If NULL we are skipping the stub.
6468 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6469 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6470 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6471 STUB_COMP_DIR may be non-NULL.
6472 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6473 are filled in with the info of the DIE from the DWO file.
6474 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6475 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6476 kept around for at least as long as *RESULT_READER.
6478 The result is non-zero if a valid (non-dummy) DIE was found. */
6481 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6482 struct dwo_unit
*dwo_unit
,
6483 struct die_info
*stub_comp_unit_die
,
6484 const char *stub_comp_dir
,
6485 struct die_reader_specs
*result_reader
,
6486 const gdb_byte
**result_info_ptr
,
6487 struct die_info
**result_comp_unit_die
,
6488 abbrev_table_up
*result_dwo_abbrev_table
)
6490 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6491 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6492 struct dwarf2_cu
*cu
= this_cu
->cu
;
6494 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6495 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6496 int i
,num_extra_attrs
;
6497 struct dwarf2_section_info
*dwo_abbrev_section
;
6498 struct die_info
*comp_unit_die
;
6500 /* At most one of these may be provided. */
6501 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6503 /* These attributes aren't processed until later:
6504 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6505 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6506 referenced later. However, these attributes are found in the stub
6507 which we won't have later. In order to not impose this complication
6508 on the rest of the code, we read them here and copy them to the
6517 if (stub_comp_unit_die
!= NULL
)
6519 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6521 if (! this_cu
->is_debug_types
)
6522 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6523 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6524 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6525 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6526 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6528 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6530 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6531 here (if needed). We need the value before we can process
6533 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6535 else if (stub_comp_dir
!= NULL
)
6537 /* Reconstruct the comp_dir attribute to simplify the code below. */
6538 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6539 comp_dir
->name
= DW_AT_comp_dir
;
6540 comp_dir
->form
= DW_FORM_string
;
6541 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6542 DW_STRING (comp_dir
) = stub_comp_dir
;
6545 /* Set up for reading the DWO CU/TU. */
6546 cu
->dwo_unit
= dwo_unit
;
6547 dwarf2_section_info
*section
= dwo_unit
->section
;
6548 section
->read (objfile
);
6549 abfd
= section
->get_bfd_owner ();
6550 begin_info_ptr
= info_ptr
= (section
->buffer
6551 + to_underlying (dwo_unit
->sect_off
));
6552 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6554 if (this_cu
->is_debug_types
)
6556 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6558 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6559 &cu
->header
, section
,
6561 info_ptr
, rcuh_kind::TYPE
);
6562 /* This is not an assert because it can be caused by bad debug info. */
6563 if (sig_type
->signature
!= cu
->header
.signature
)
6565 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6566 " TU at offset %s [in module %s]"),
6567 hex_string (sig_type
->signature
),
6568 hex_string (cu
->header
.signature
),
6569 sect_offset_str (dwo_unit
->sect_off
),
6570 bfd_get_filename (abfd
));
6572 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6573 /* For DWOs coming from DWP files, we don't know the CU length
6574 nor the type's offset in the TU until now. */
6575 dwo_unit
->length
= cu
->header
.get_length ();
6576 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6578 /* Establish the type offset that can be used to lookup the type.
6579 For DWO files, we don't know it until now. */
6580 sig_type
->type_offset_in_section
6581 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6585 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6586 &cu
->header
, section
,
6588 info_ptr
, rcuh_kind::COMPILE
);
6589 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6590 /* For DWOs coming from DWP files, we don't know the CU length
6592 dwo_unit
->length
= cu
->header
.get_length ();
6595 *result_dwo_abbrev_table
6596 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6597 cu
->header
.abbrev_sect_off
);
6598 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6599 result_dwo_abbrev_table
->get ());
6601 /* Read in the die, but leave space to copy over the attributes
6602 from the stub. This has the benefit of simplifying the rest of
6603 the code - all the work to maintain the illusion of a single
6604 DW_TAG_{compile,type}_unit DIE is done here. */
6605 num_extra_attrs
= ((stmt_list
!= NULL
)
6609 + (comp_dir
!= NULL
));
6610 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6613 /* Copy over the attributes from the stub to the DIE we just read in. */
6614 comp_unit_die
= *result_comp_unit_die
;
6615 i
= comp_unit_die
->num_attrs
;
6616 if (stmt_list
!= NULL
)
6617 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6619 comp_unit_die
->attrs
[i
++] = *low_pc
;
6620 if (high_pc
!= NULL
)
6621 comp_unit_die
->attrs
[i
++] = *high_pc
;
6623 comp_unit_die
->attrs
[i
++] = *ranges
;
6624 if (comp_dir
!= NULL
)
6625 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6626 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6628 if (dwarf_die_debug
)
6630 fprintf_unfiltered (gdb_stdlog
,
6631 "Read die from %s@0x%x of %s:\n",
6632 section
->get_name (),
6633 (unsigned) (begin_info_ptr
- section
->buffer
),
6634 bfd_get_filename (abfd
));
6635 dump_die (comp_unit_die
, dwarf_die_debug
);
6638 /* Skip dummy compilation units. */
6639 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6640 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6643 *result_info_ptr
= info_ptr
;
6647 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6648 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6649 signature is part of the header. */
6650 static gdb::optional
<ULONGEST
>
6651 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6653 if (cu
->header
.version
>= 5)
6654 return cu
->header
.signature
;
6655 struct attribute
*attr
;
6656 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6657 if (attr
== nullptr)
6658 return gdb::optional
<ULONGEST
> ();
6659 return DW_UNSND (attr
);
6662 /* Subroutine of cutu_reader to simplify it.
6663 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6664 Returns NULL if the specified DWO unit cannot be found. */
6666 static struct dwo_unit
*
6667 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6668 struct die_info
*comp_unit_die
,
6669 const char *dwo_name
)
6671 struct dwarf2_cu
*cu
= this_cu
->cu
;
6672 struct dwo_unit
*dwo_unit
;
6673 const char *comp_dir
;
6675 gdb_assert (cu
!= NULL
);
6677 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6678 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6679 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6681 if (this_cu
->is_debug_types
)
6683 struct signatured_type
*sig_type
;
6685 /* Since this_cu is the first member of struct signatured_type,
6686 we can go from a pointer to one to a pointer to the other. */
6687 sig_type
= (struct signatured_type
*) this_cu
;
6688 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6692 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6693 if (!signature
.has_value ())
6694 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6696 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6697 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6704 /* Subroutine of cutu_reader to simplify it.
6705 See it for a description of the parameters.
6706 Read a TU directly from a DWO file, bypassing the stub. */
6709 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6710 int use_existing_cu
)
6712 struct signatured_type
*sig_type
;
6714 /* Verify we can do the following downcast, and that we have the
6716 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6717 sig_type
= (struct signatured_type
*) this_cu
;
6718 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6720 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6722 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6723 /* There's no need to do the rereading_dwo_cu handling that
6724 cutu_reader does since we don't read the stub. */
6728 /* If !use_existing_cu, this_cu->cu must be NULL. */
6729 gdb_assert (this_cu
->cu
== NULL
);
6730 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6733 /* A future optimization, if needed, would be to use an existing
6734 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6735 could share abbrev tables. */
6737 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6738 NULL
/* stub_comp_unit_die */,
6739 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6742 &m_dwo_abbrev_table
) == 0)
6749 /* Initialize a CU (or TU) and read its DIEs.
6750 If the CU defers to a DWO file, read the DWO file as well.
6752 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6753 Otherwise the table specified in the comp unit header is read in and used.
6754 This is an optimization for when we already have the abbrev table.
6756 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6757 Otherwise, a new CU is allocated with xmalloc. */
6759 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6760 struct abbrev_table
*abbrev_table
,
6761 int use_existing_cu
,
6763 : die_reader_specs
{},
6766 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6767 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6768 struct dwarf2_section_info
*section
= this_cu
->section
;
6769 bfd
*abfd
= section
->get_bfd_owner ();
6770 struct dwarf2_cu
*cu
;
6771 const gdb_byte
*begin_info_ptr
;
6772 struct signatured_type
*sig_type
= NULL
;
6773 struct dwarf2_section_info
*abbrev_section
;
6774 /* Non-zero if CU currently points to a DWO file and we need to
6775 reread it. When this happens we need to reread the skeleton die
6776 before we can reread the DWO file (this only applies to CUs, not TUs). */
6777 int rereading_dwo_cu
= 0;
6779 if (dwarf_die_debug
)
6780 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6781 this_cu
->is_debug_types
? "type" : "comp",
6782 sect_offset_str (this_cu
->sect_off
));
6784 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6785 file (instead of going through the stub), short-circuit all of this. */
6786 if (this_cu
->reading_dwo_directly
)
6788 /* Narrow down the scope of possibilities to have to understand. */
6789 gdb_assert (this_cu
->is_debug_types
);
6790 gdb_assert (abbrev_table
== NULL
);
6791 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6795 /* This is cheap if the section is already read in. */
6796 section
->read (objfile
);
6798 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6800 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6802 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6805 /* If this CU is from a DWO file we need to start over, we need to
6806 refetch the attributes from the skeleton CU.
6807 This could be optimized by retrieving those attributes from when we
6808 were here the first time: the previous comp_unit_die was stored in
6809 comp_unit_obstack. But there's no data yet that we need this
6811 if (cu
->dwo_unit
!= NULL
)
6812 rereading_dwo_cu
= 1;
6816 /* If !use_existing_cu, this_cu->cu must be NULL. */
6817 gdb_assert (this_cu
->cu
== NULL
);
6818 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6819 cu
= m_new_cu
.get ();
6822 /* Get the header. */
6823 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6825 /* We already have the header, there's no need to read it in again. */
6826 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6830 if (this_cu
->is_debug_types
)
6832 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6833 &cu
->header
, section
,
6834 abbrev_section
, info_ptr
,
6837 /* Since per_cu is the first member of struct signatured_type,
6838 we can go from a pointer to one to a pointer to the other. */
6839 sig_type
= (struct signatured_type
*) this_cu
;
6840 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6841 gdb_assert (sig_type
->type_offset_in_tu
6842 == cu
->header
.type_cu_offset_in_tu
);
6843 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6845 /* LENGTH has not been set yet for type units if we're
6846 using .gdb_index. */
6847 this_cu
->length
= cu
->header
.get_length ();
6849 /* Establish the type offset that can be used to lookup the type. */
6850 sig_type
->type_offset_in_section
=
6851 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6853 this_cu
->dwarf_version
= cu
->header
.version
;
6857 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6858 &cu
->header
, section
,
6861 rcuh_kind::COMPILE
);
6863 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6864 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6865 this_cu
->dwarf_version
= cu
->header
.version
;
6869 /* Skip dummy compilation units. */
6870 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6871 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6877 /* If we don't have them yet, read the abbrevs for this compilation unit.
6878 And if we need to read them now, make sure they're freed when we're
6880 if (abbrev_table
!= NULL
)
6881 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6884 m_abbrev_table_holder
6885 = abbrev_table::read (objfile
, abbrev_section
,
6886 cu
->header
.abbrev_sect_off
);
6887 abbrev_table
= m_abbrev_table_holder
.get ();
6890 /* Read the top level CU/TU die. */
6891 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6892 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6894 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6900 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6901 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6902 table from the DWO file and pass the ownership over to us. It will be
6903 referenced from READER, so we must make sure to free it after we're done
6906 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6907 DWO CU, that this test will fail (the attribute will not be present). */
6908 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6909 if (dwo_name
!= nullptr)
6911 struct dwo_unit
*dwo_unit
;
6912 struct die_info
*dwo_comp_unit_die
;
6914 if (comp_unit_die
->has_children
)
6916 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6917 " has children (offset %s) [in module %s]"),
6918 sect_offset_str (this_cu
->sect_off
),
6919 bfd_get_filename (abfd
));
6921 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6922 if (dwo_unit
!= NULL
)
6924 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6925 comp_unit_die
, NULL
,
6928 &m_dwo_abbrev_table
) == 0)
6934 comp_unit_die
= dwo_comp_unit_die
;
6938 /* Yikes, we couldn't find the rest of the DIE, we only have
6939 the stub. A complaint has already been logged. There's
6940 not much more we can do except pass on the stub DIE to
6941 die_reader_func. We don't want to throw an error on bad
6948 cutu_reader::keep ()
6950 /* Done, clean up. */
6951 gdb_assert (!dummy_p
);
6952 if (m_new_cu
!= NULL
)
6954 struct dwarf2_per_objfile
*dwarf2_per_objfile
6955 = m_this_cu
->dwarf2_per_objfile
;
6956 /* Link this CU into read_in_chain. */
6957 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6958 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6959 /* The chain owns it now. */
6960 m_new_cu
.release ();
6964 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6965 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6966 assumed to have already done the lookup to find the DWO file).
6968 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6969 THIS_CU->is_debug_types, but nothing else.
6971 We fill in THIS_CU->length.
6973 THIS_CU->cu is always freed when done.
6974 This is done in order to not leave THIS_CU->cu in a state where we have
6975 to care whether it refers to the "main" CU or the DWO CU.
6977 When parent_cu is passed, it is used to provide a default value for
6978 str_offsets_base and addr_base from the parent. */
6980 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6981 struct dwarf2_cu
*parent_cu
,
6982 struct dwo_file
*dwo_file
)
6983 : die_reader_specs
{},
6986 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6987 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6988 struct dwarf2_section_info
*section
= this_cu
->section
;
6989 bfd
*abfd
= section
->get_bfd_owner ();
6990 struct dwarf2_section_info
*abbrev_section
;
6991 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6993 if (dwarf_die_debug
)
6994 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6995 this_cu
->is_debug_types
? "type" : "comp",
6996 sect_offset_str (this_cu
->sect_off
));
6998 gdb_assert (this_cu
->cu
== NULL
);
7000 abbrev_section
= (dwo_file
!= NULL
7001 ? &dwo_file
->sections
.abbrev
7002 : get_abbrev_section_for_cu (this_cu
));
7004 /* This is cheap if the section is already read in. */
7005 section
->read (objfile
);
7007 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7009 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7010 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7011 &m_new_cu
->header
, section
,
7012 abbrev_section
, info_ptr
,
7013 (this_cu
->is_debug_types
7015 : rcuh_kind::COMPILE
));
7017 if (parent_cu
!= nullptr)
7019 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7020 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7022 this_cu
->length
= m_new_cu
->header
.get_length ();
7024 /* Skip dummy compilation units. */
7025 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7026 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7032 m_abbrev_table_holder
7033 = abbrev_table::read (objfile
, abbrev_section
,
7034 m_new_cu
->header
.abbrev_sect_off
);
7036 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7037 m_abbrev_table_holder
.get ());
7038 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7042 /* Type Unit Groups.
7044 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7045 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7046 so that all types coming from the same compilation (.o file) are grouped
7047 together. A future step could be to put the types in the same symtab as
7048 the CU the types ultimately came from. */
7051 hash_type_unit_group (const void *item
)
7053 const struct type_unit_group
*tu_group
7054 = (const struct type_unit_group
*) item
;
7056 return hash_stmt_list_entry (&tu_group
->hash
);
7060 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7062 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7063 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7065 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7068 /* Allocate a hash table for type unit groups. */
7071 allocate_type_unit_groups_table ()
7073 return htab_up (htab_create_alloc (3,
7074 hash_type_unit_group
,
7076 NULL
, xcalloc
, xfree
));
7079 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7080 partial symtabs. We combine several TUs per psymtab to not let the size
7081 of any one psymtab grow too big. */
7082 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7083 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7085 /* Helper routine for get_type_unit_group.
7086 Create the type_unit_group object used to hold one or more TUs. */
7088 static struct type_unit_group
*
7089 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7091 struct dwarf2_per_objfile
*dwarf2_per_objfile
7092 = cu
->per_cu
->dwarf2_per_objfile
;
7093 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7094 struct dwarf2_per_cu_data
*per_cu
;
7095 struct type_unit_group
*tu_group
;
7097 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7098 struct type_unit_group
);
7099 per_cu
= &tu_group
->per_cu
;
7100 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7102 if (dwarf2_per_objfile
->using_index
)
7104 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7105 struct dwarf2_per_cu_quick_data
);
7109 unsigned int line_offset
= to_underlying (line_offset_struct
);
7110 dwarf2_psymtab
*pst
;
7113 /* Give the symtab a useful name for debug purposes. */
7114 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7115 name
= string_printf ("<type_units_%d>",
7116 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7118 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7120 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7121 pst
->anonymous
= true;
7124 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7125 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7130 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7131 STMT_LIST is a DW_AT_stmt_list attribute. */
7133 static struct type_unit_group
*
7134 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7136 struct dwarf2_per_objfile
*dwarf2_per_objfile
7137 = cu
->per_cu
->dwarf2_per_objfile
;
7138 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7139 struct type_unit_group
*tu_group
;
7141 unsigned int line_offset
;
7142 struct type_unit_group type_unit_group_for_lookup
;
7144 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7145 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7147 /* Do we need to create a new group, or can we use an existing one? */
7151 line_offset
= DW_UNSND (stmt_list
);
7152 ++tu_stats
->nr_symtab_sharers
;
7156 /* Ugh, no stmt_list. Rare, but we have to handle it.
7157 We can do various things here like create one group per TU or
7158 spread them over multiple groups to split up the expansion work.
7159 To avoid worst case scenarios (too many groups or too large groups)
7160 we, umm, group them in bunches. */
7161 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7162 | (tu_stats
->nr_stmt_less_type_units
7163 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7164 ++tu_stats
->nr_stmt_less_type_units
;
7167 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7168 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7169 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7170 &type_unit_group_for_lookup
, INSERT
);
7173 tu_group
= (struct type_unit_group
*) *slot
;
7174 gdb_assert (tu_group
!= NULL
);
7178 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7179 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7181 ++tu_stats
->nr_symtabs
;
7187 /* Partial symbol tables. */
7189 /* Create a psymtab named NAME and assign it to PER_CU.
7191 The caller must fill in the following details:
7192 dirname, textlow, texthigh. */
7194 static dwarf2_psymtab
*
7195 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7197 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7198 dwarf2_psymtab
*pst
;
7200 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7202 pst
->psymtabs_addrmap_supported
= true;
7204 /* This is the glue that links PST into GDB's symbol API. */
7205 per_cu
->v
.psymtab
= pst
;
7210 /* DIE reader function for process_psymtab_comp_unit. */
7213 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7214 const gdb_byte
*info_ptr
,
7215 struct die_info
*comp_unit_die
,
7216 enum language pretend_language
)
7218 struct dwarf2_cu
*cu
= reader
->cu
;
7219 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7220 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7221 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7223 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7224 dwarf2_psymtab
*pst
;
7225 enum pc_bounds_kind cu_bounds_kind
;
7226 const char *filename
;
7228 gdb_assert (! per_cu
->is_debug_types
);
7230 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7232 /* Allocate a new partial symbol table structure. */
7233 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7234 static const char artificial
[] = "<artificial>";
7235 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7236 if (filename
== NULL
)
7238 else if (strcmp (filename
, artificial
) == 0)
7240 debug_filename
.reset (concat (artificial
, "@",
7241 sect_offset_str (per_cu
->sect_off
),
7243 filename
= debug_filename
.get ();
7246 pst
= create_partial_symtab (per_cu
, filename
);
7248 /* This must be done before calling dwarf2_build_include_psymtabs. */
7249 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7251 baseaddr
= objfile
->text_section_offset ();
7253 dwarf2_find_base_address (comp_unit_die
, cu
);
7255 /* Possibly set the default values of LOWPC and HIGHPC from
7257 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7258 &best_highpc
, cu
, pst
);
7259 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7262 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7265 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7267 /* Store the contiguous range if it is not empty; it can be
7268 empty for CUs with no code. */
7269 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7273 /* Check if comp unit has_children.
7274 If so, read the rest of the partial symbols from this comp unit.
7275 If not, there's no more debug_info for this comp unit. */
7276 if (comp_unit_die
->has_children
)
7278 struct partial_die_info
*first_die
;
7279 CORE_ADDR lowpc
, highpc
;
7281 lowpc
= ((CORE_ADDR
) -1);
7282 highpc
= ((CORE_ADDR
) 0);
7284 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7286 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7287 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7289 /* If we didn't find a lowpc, set it to highpc to avoid
7290 complaints from `maint check'. */
7291 if (lowpc
== ((CORE_ADDR
) -1))
7294 /* If the compilation unit didn't have an explicit address range,
7295 then use the information extracted from its child dies. */
7296 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7299 best_highpc
= highpc
;
7302 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7303 best_lowpc
+ baseaddr
)
7305 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7306 best_highpc
+ baseaddr
)
7309 end_psymtab_common (objfile
, pst
);
7311 if (!cu
->per_cu
->imported_symtabs_empty ())
7314 int len
= cu
->per_cu
->imported_symtabs_size ();
7316 /* Fill in 'dependencies' here; we fill in 'users' in a
7318 pst
->number_of_dependencies
= len
;
7320 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7321 for (i
= 0; i
< len
; ++i
)
7323 pst
->dependencies
[i
]
7324 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7327 cu
->per_cu
->imported_symtabs_free ();
7330 /* Get the list of files included in the current compilation unit,
7331 and build a psymtab for each of them. */
7332 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7334 if (dwarf_read_debug
)
7335 fprintf_unfiltered (gdb_stdlog
,
7336 "Psymtab for %s unit @%s: %s - %s"
7337 ", %d global, %d static syms\n",
7338 per_cu
->is_debug_types
? "type" : "comp",
7339 sect_offset_str (per_cu
->sect_off
),
7340 paddress (gdbarch
, pst
->text_low (objfile
)),
7341 paddress (gdbarch
, pst
->text_high (objfile
)),
7342 pst
->n_global_syms
, pst
->n_static_syms
);
7345 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7346 Process compilation unit THIS_CU for a psymtab. */
7349 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7350 bool want_partial_unit
,
7351 enum language pretend_language
)
7353 /* If this compilation unit was already read in, free the
7354 cached copy in order to read it in again. This is
7355 necessary because we skipped some symbols when we first
7356 read in the compilation unit (see load_partial_dies).
7357 This problem could be avoided, but the benefit is unclear. */
7358 if (this_cu
->cu
!= NULL
)
7359 free_one_cached_comp_unit (this_cu
);
7361 cutu_reader
reader (this_cu
, NULL
, 0, false);
7363 switch (reader
.comp_unit_die
->tag
)
7365 case DW_TAG_compile_unit
:
7366 this_cu
->unit_type
= DW_UT_compile
;
7368 case DW_TAG_partial_unit
:
7369 this_cu
->unit_type
= DW_UT_partial
;
7379 else if (this_cu
->is_debug_types
)
7380 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7381 reader
.comp_unit_die
);
7382 else if (want_partial_unit
7383 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7384 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7385 reader
.comp_unit_die
,
7388 this_cu
->lang
= this_cu
->cu
->language
;
7390 /* Age out any secondary CUs. */
7391 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7394 /* Reader function for build_type_psymtabs. */
7397 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7398 const gdb_byte
*info_ptr
,
7399 struct die_info
*type_unit_die
)
7401 struct dwarf2_per_objfile
*dwarf2_per_objfile
7402 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7403 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7404 struct dwarf2_cu
*cu
= reader
->cu
;
7405 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7406 struct signatured_type
*sig_type
;
7407 struct type_unit_group
*tu_group
;
7408 struct attribute
*attr
;
7409 struct partial_die_info
*first_die
;
7410 CORE_ADDR lowpc
, highpc
;
7411 dwarf2_psymtab
*pst
;
7413 gdb_assert (per_cu
->is_debug_types
);
7414 sig_type
= (struct signatured_type
*) per_cu
;
7416 if (! type_unit_die
->has_children
)
7419 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7420 tu_group
= get_type_unit_group (cu
, attr
);
7422 if (tu_group
->tus
== nullptr)
7423 tu_group
->tus
= new std::vector
<signatured_type
*>;
7424 tu_group
->tus
->push_back (sig_type
);
7426 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7427 pst
= create_partial_symtab (per_cu
, "");
7428 pst
->anonymous
= true;
7430 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7432 lowpc
= (CORE_ADDR
) -1;
7433 highpc
= (CORE_ADDR
) 0;
7434 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7436 end_psymtab_common (objfile
, pst
);
7439 /* Struct used to sort TUs by their abbreviation table offset. */
7441 struct tu_abbrev_offset
7443 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7444 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7447 signatured_type
*sig_type
;
7448 sect_offset abbrev_offset
;
7451 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7454 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7455 const struct tu_abbrev_offset
&b
)
7457 return a
.abbrev_offset
< b
.abbrev_offset
;
7460 /* Efficiently read all the type units.
7461 This does the bulk of the work for build_type_psymtabs.
7463 The efficiency is because we sort TUs by the abbrev table they use and
7464 only read each abbrev table once. In one program there are 200K TUs
7465 sharing 8K abbrev tables.
7467 The main purpose of this function is to support building the
7468 dwarf2_per_objfile->type_unit_groups table.
7469 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7470 can collapse the search space by grouping them by stmt_list.
7471 The savings can be significant, in the same program from above the 200K TUs
7472 share 8K stmt_list tables.
7474 FUNC is expected to call get_type_unit_group, which will create the
7475 struct type_unit_group if necessary and add it to
7476 dwarf2_per_objfile->type_unit_groups. */
7479 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7481 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7482 abbrev_table_up abbrev_table
;
7483 sect_offset abbrev_offset
;
7485 /* It's up to the caller to not call us multiple times. */
7486 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7488 if (dwarf2_per_objfile
->all_type_units
.empty ())
7491 /* TUs typically share abbrev tables, and there can be way more TUs than
7492 abbrev tables. Sort by abbrev table to reduce the number of times we
7493 read each abbrev table in.
7494 Alternatives are to punt or to maintain a cache of abbrev tables.
7495 This is simpler and efficient enough for now.
7497 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7498 symtab to use). Typically TUs with the same abbrev offset have the same
7499 stmt_list value too so in practice this should work well.
7501 The basic algorithm here is:
7503 sort TUs by abbrev table
7504 for each TU with same abbrev table:
7505 read abbrev table if first user
7506 read TU top level DIE
7507 [IWBN if DWO skeletons had DW_AT_stmt_list]
7510 if (dwarf_read_debug
)
7511 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7513 /* Sort in a separate table to maintain the order of all_type_units
7514 for .gdb_index: TU indices directly index all_type_units. */
7515 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7516 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7518 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7519 sorted_by_abbrev
.emplace_back
7520 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7521 sig_type
->per_cu
.section
,
7522 sig_type
->per_cu
.sect_off
));
7524 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7525 sort_tu_by_abbrev_offset
);
7527 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7529 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7531 /* Switch to the next abbrev table if necessary. */
7532 if (abbrev_table
== NULL
7533 || tu
.abbrev_offset
!= abbrev_offset
)
7535 abbrev_offset
= tu
.abbrev_offset
;
7537 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7538 &dwarf2_per_objfile
->abbrev
,
7540 ++tu_stats
->nr_uniq_abbrev_tables
;
7543 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7545 if (!reader
.dummy_p
)
7546 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7547 reader
.comp_unit_die
);
7551 /* Print collected type unit statistics. */
7554 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7556 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7558 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7559 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7560 dwarf2_per_objfile
->all_type_units
.size ());
7561 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7562 tu_stats
->nr_uniq_abbrev_tables
);
7563 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7564 tu_stats
->nr_symtabs
);
7565 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7566 tu_stats
->nr_symtab_sharers
);
7567 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7568 tu_stats
->nr_stmt_less_type_units
);
7569 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7570 tu_stats
->nr_all_type_units_reallocs
);
7573 /* Traversal function for build_type_psymtabs. */
7576 build_type_psymtab_dependencies (void **slot
, void *info
)
7578 struct dwarf2_per_objfile
*dwarf2_per_objfile
7579 = (struct dwarf2_per_objfile
*) info
;
7580 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7581 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7582 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7583 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7584 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7587 gdb_assert (len
> 0);
7588 gdb_assert (per_cu
->type_unit_group_p ());
7590 pst
->number_of_dependencies
= len
;
7591 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7592 for (i
= 0; i
< len
; ++i
)
7594 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7595 gdb_assert (iter
->per_cu
.is_debug_types
);
7596 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7597 iter
->type_unit_group
= tu_group
;
7600 delete tu_group
->tus
;
7601 tu_group
->tus
= nullptr;
7606 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7607 Build partial symbol tables for the .debug_types comp-units. */
7610 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7612 if (! create_all_type_units (dwarf2_per_objfile
))
7615 build_type_psymtabs_1 (dwarf2_per_objfile
);
7618 /* Traversal function for process_skeletonless_type_unit.
7619 Read a TU in a DWO file and build partial symbols for it. */
7622 process_skeletonless_type_unit (void **slot
, void *info
)
7624 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7625 struct dwarf2_per_objfile
*dwarf2_per_objfile
7626 = (struct dwarf2_per_objfile
*) info
;
7627 struct signatured_type find_entry
, *entry
;
7629 /* If this TU doesn't exist in the global table, add it and read it in. */
7631 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7632 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7634 find_entry
.signature
= dwo_unit
->signature
;
7635 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7636 &find_entry
, INSERT
);
7637 /* If we've already seen this type there's nothing to do. What's happening
7638 is we're doing our own version of comdat-folding here. */
7642 /* This does the job that create_all_type_units would have done for
7644 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7645 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7648 /* This does the job that build_type_psymtabs_1 would have done. */
7649 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7650 if (!reader
.dummy_p
)
7651 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7652 reader
.comp_unit_die
);
7657 /* Traversal function for process_skeletonless_type_units. */
7660 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7662 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7664 if (dwo_file
->tus
!= NULL
)
7665 htab_traverse_noresize (dwo_file
->tus
.get (),
7666 process_skeletonless_type_unit
, info
);
7671 /* Scan all TUs of DWO files, verifying we've processed them.
7672 This is needed in case a TU was emitted without its skeleton.
7673 Note: This can't be done until we know what all the DWO files are. */
7676 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7678 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7679 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7680 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7682 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7683 process_dwo_file_for_skeletonless_type_units
,
7684 dwarf2_per_objfile
);
7688 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7691 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7693 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7695 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7700 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7702 /* Set the 'user' field only if it is not already set. */
7703 if (pst
->dependencies
[j
]->user
== NULL
)
7704 pst
->dependencies
[j
]->user
= pst
;
7709 /* Build the partial symbol table by doing a quick pass through the
7710 .debug_info and .debug_abbrev sections. */
7713 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7715 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7717 if (dwarf_read_debug
)
7719 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7720 objfile_name (objfile
));
7723 scoped_restore restore_reading_psyms
7724 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7727 dwarf2_per_objfile
->info
.read (objfile
);
7729 /* Any cached compilation units will be linked by the per-objfile
7730 read_in_chain. Make sure to free them when we're done. */
7731 free_cached_comp_units
freer (dwarf2_per_objfile
);
7733 build_type_psymtabs (dwarf2_per_objfile
);
7735 create_all_comp_units (dwarf2_per_objfile
);
7737 /* Create a temporary address map on a temporary obstack. We later
7738 copy this to the final obstack. */
7739 auto_obstack temp_obstack
;
7741 scoped_restore save_psymtabs_addrmap
7742 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7743 addrmap_create_mutable (&temp_obstack
));
7745 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7746 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7748 /* This has to wait until we read the CUs, we need the list of DWOs. */
7749 process_skeletonless_type_units (dwarf2_per_objfile
);
7751 /* Now that all TUs have been processed we can fill in the dependencies. */
7752 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7754 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7755 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7758 if (dwarf_read_debug
)
7759 print_tu_stats (dwarf2_per_objfile
);
7761 set_partial_user (dwarf2_per_objfile
);
7763 objfile
->partial_symtabs
->psymtabs_addrmap
7764 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7765 objfile
->partial_symtabs
->obstack ());
7766 /* At this point we want to keep the address map. */
7767 save_psymtabs_addrmap
.release ();
7769 if (dwarf_read_debug
)
7770 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7771 objfile_name (objfile
));
7774 /* Load the partial DIEs for a secondary CU into memory.
7775 This is also used when rereading a primary CU with load_all_dies. */
7778 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7780 cutu_reader
reader (this_cu
, NULL
, 1, false);
7782 if (!reader
.dummy_p
)
7784 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7787 /* Check if comp unit has_children.
7788 If so, read the rest of the partial symbols from this comp unit.
7789 If not, there's no more debug_info for this comp unit. */
7790 if (reader
.comp_unit_die
->has_children
)
7791 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7798 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7799 struct dwarf2_section_info
*section
,
7800 struct dwarf2_section_info
*abbrev_section
,
7801 unsigned int is_dwz
)
7803 const gdb_byte
*info_ptr
;
7804 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7806 if (dwarf_read_debug
)
7807 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7808 section
->get_name (),
7809 section
->get_file_name ());
7811 section
->read (objfile
);
7813 info_ptr
= section
->buffer
;
7815 while (info_ptr
< section
->buffer
+ section
->size
)
7817 struct dwarf2_per_cu_data
*this_cu
;
7819 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7821 comp_unit_head cu_header
;
7822 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7823 abbrev_section
, info_ptr
,
7824 rcuh_kind::COMPILE
);
7826 /* Save the compilation unit for later lookup. */
7827 if (cu_header
.unit_type
!= DW_UT_type
)
7829 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7830 struct dwarf2_per_cu_data
);
7831 memset (this_cu
, 0, sizeof (*this_cu
));
7835 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7836 struct signatured_type
);
7837 memset (sig_type
, 0, sizeof (*sig_type
));
7838 sig_type
->signature
= cu_header
.signature
;
7839 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7840 this_cu
= &sig_type
->per_cu
;
7842 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7843 this_cu
->sect_off
= sect_off
;
7844 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7845 this_cu
->is_dwz
= is_dwz
;
7846 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7847 this_cu
->section
= section
;
7849 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7851 info_ptr
= info_ptr
+ this_cu
->length
;
7855 /* Create a list of all compilation units in OBJFILE.
7856 This is only done for -readnow and building partial symtabs. */
7859 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7861 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7862 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7863 &dwarf2_per_objfile
->abbrev
, 0);
7865 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7867 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7871 /* Process all loaded DIEs for compilation unit CU, starting at
7872 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7873 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7874 DW_AT_ranges). See the comments of add_partial_subprogram on how
7875 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7878 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7879 CORE_ADDR
*highpc
, int set_addrmap
,
7880 struct dwarf2_cu
*cu
)
7882 struct partial_die_info
*pdi
;
7884 /* Now, march along the PDI's, descending into ones which have
7885 interesting children but skipping the children of the other ones,
7886 until we reach the end of the compilation unit. */
7894 /* Anonymous namespaces or modules have no name but have interesting
7895 children, so we need to look at them. Ditto for anonymous
7898 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7899 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7900 || pdi
->tag
== DW_TAG_imported_unit
7901 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7905 case DW_TAG_subprogram
:
7906 case DW_TAG_inlined_subroutine
:
7907 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7909 case DW_TAG_constant
:
7910 case DW_TAG_variable
:
7911 case DW_TAG_typedef
:
7912 case DW_TAG_union_type
:
7913 if (!pdi
->is_declaration
)
7915 add_partial_symbol (pdi
, cu
);
7918 case DW_TAG_class_type
:
7919 case DW_TAG_interface_type
:
7920 case DW_TAG_structure_type
:
7921 if (!pdi
->is_declaration
)
7923 add_partial_symbol (pdi
, cu
);
7925 if ((cu
->language
== language_rust
7926 || cu
->language
== language_cplus
) && pdi
->has_children
)
7927 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7930 case DW_TAG_enumeration_type
:
7931 if (!pdi
->is_declaration
)
7932 add_partial_enumeration (pdi
, cu
);
7934 case DW_TAG_base_type
:
7935 case DW_TAG_subrange_type
:
7936 /* File scope base type definitions are added to the partial
7938 add_partial_symbol (pdi
, cu
);
7940 case DW_TAG_namespace
:
7941 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7944 if (!pdi
->is_declaration
)
7945 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7947 case DW_TAG_imported_unit
:
7949 struct dwarf2_per_cu_data
*per_cu
;
7951 /* For now we don't handle imported units in type units. */
7952 if (cu
->per_cu
->is_debug_types
)
7954 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7955 " supported in type units [in module %s]"),
7956 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7959 per_cu
= dwarf2_find_containing_comp_unit
7960 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7961 cu
->per_cu
->dwarf2_per_objfile
);
7963 /* Go read the partial unit, if needed. */
7964 if (per_cu
->v
.psymtab
== NULL
)
7965 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
7967 cu
->per_cu
->imported_symtabs_push (per_cu
);
7970 case DW_TAG_imported_declaration
:
7971 add_partial_symbol (pdi
, cu
);
7978 /* If the die has a sibling, skip to the sibling. */
7980 pdi
= pdi
->die_sibling
;
7984 /* Functions used to compute the fully scoped name of a partial DIE.
7986 Normally, this is simple. For C++, the parent DIE's fully scoped
7987 name is concatenated with "::" and the partial DIE's name.
7988 Enumerators are an exception; they use the scope of their parent
7989 enumeration type, i.e. the name of the enumeration type is not
7990 prepended to the enumerator.
7992 There are two complexities. One is DW_AT_specification; in this
7993 case "parent" means the parent of the target of the specification,
7994 instead of the direct parent of the DIE. The other is compilers
7995 which do not emit DW_TAG_namespace; in this case we try to guess
7996 the fully qualified name of structure types from their members'
7997 linkage names. This must be done using the DIE's children rather
7998 than the children of any DW_AT_specification target. We only need
7999 to do this for structures at the top level, i.e. if the target of
8000 any DW_AT_specification (if any; otherwise the DIE itself) does not
8003 /* Compute the scope prefix associated with PDI's parent, in
8004 compilation unit CU. The result will be allocated on CU's
8005 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8006 field. NULL is returned if no prefix is necessary. */
8008 partial_die_parent_scope (struct partial_die_info
*pdi
,
8009 struct dwarf2_cu
*cu
)
8011 const char *grandparent_scope
;
8012 struct partial_die_info
*parent
, *real_pdi
;
8014 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8015 then this means the parent of the specification DIE. */
8018 while (real_pdi
->has_specification
)
8020 auto res
= find_partial_die (real_pdi
->spec_offset
,
8021 real_pdi
->spec_is_dwz
, cu
);
8026 parent
= real_pdi
->die_parent
;
8030 if (parent
->scope_set
)
8031 return parent
->scope
;
8035 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8037 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8038 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8039 Work around this problem here. */
8040 if (cu
->language
== language_cplus
8041 && parent
->tag
== DW_TAG_namespace
8042 && strcmp (parent
->name
, "::") == 0
8043 && grandparent_scope
== NULL
)
8045 parent
->scope
= NULL
;
8046 parent
->scope_set
= 1;
8050 /* Nested subroutines in Fortran get a prefix. */
8051 if (pdi
->tag
== DW_TAG_enumerator
)
8052 /* Enumerators should not get the name of the enumeration as a prefix. */
8053 parent
->scope
= grandparent_scope
;
8054 else if (parent
->tag
== DW_TAG_namespace
8055 || parent
->tag
== DW_TAG_module
8056 || parent
->tag
== DW_TAG_structure_type
8057 || parent
->tag
== DW_TAG_class_type
8058 || parent
->tag
== DW_TAG_interface_type
8059 || parent
->tag
== DW_TAG_union_type
8060 || parent
->tag
== DW_TAG_enumeration_type
8061 || (cu
->language
== language_fortran
8062 && parent
->tag
== DW_TAG_subprogram
8063 && pdi
->tag
== DW_TAG_subprogram
))
8065 if (grandparent_scope
== NULL
)
8066 parent
->scope
= parent
->name
;
8068 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8070 parent
->name
, 0, cu
);
8074 /* FIXME drow/2004-04-01: What should we be doing with
8075 function-local names? For partial symbols, we should probably be
8077 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8078 dwarf_tag_name (parent
->tag
),
8079 sect_offset_str (pdi
->sect_off
));
8080 parent
->scope
= grandparent_scope
;
8083 parent
->scope_set
= 1;
8084 return parent
->scope
;
8087 /* Return the fully scoped name associated with PDI, from compilation unit
8088 CU. The result will be allocated with malloc. */
8090 static gdb::unique_xmalloc_ptr
<char>
8091 partial_die_full_name (struct partial_die_info
*pdi
,
8092 struct dwarf2_cu
*cu
)
8094 const char *parent_scope
;
8096 /* If this is a template instantiation, we can not work out the
8097 template arguments from partial DIEs. So, unfortunately, we have
8098 to go through the full DIEs. At least any work we do building
8099 types here will be reused if full symbols are loaded later. */
8100 if (pdi
->has_template_arguments
)
8104 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8106 struct die_info
*die
;
8107 struct attribute attr
;
8108 struct dwarf2_cu
*ref_cu
= cu
;
8110 /* DW_FORM_ref_addr is using section offset. */
8111 attr
.name
= (enum dwarf_attribute
) 0;
8112 attr
.form
= DW_FORM_ref_addr
;
8113 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8114 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8116 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8120 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8121 if (parent_scope
== NULL
)
8124 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8129 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8131 struct dwarf2_per_objfile
*dwarf2_per_objfile
8132 = cu
->per_cu
->dwarf2_per_objfile
;
8133 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8134 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8136 const char *actual_name
= NULL
;
8139 baseaddr
= objfile
->text_section_offset ();
8141 gdb::unique_xmalloc_ptr
<char> built_actual_name
8142 = partial_die_full_name (pdi
, cu
);
8143 if (built_actual_name
!= NULL
)
8144 actual_name
= built_actual_name
.get ();
8146 if (actual_name
== NULL
)
8147 actual_name
= pdi
->name
;
8151 case DW_TAG_inlined_subroutine
:
8152 case DW_TAG_subprogram
:
8153 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8155 if (pdi
->is_external
8156 || cu
->language
== language_ada
8157 || (cu
->language
== language_fortran
8158 && pdi
->die_parent
!= NULL
8159 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8161 /* Normally, only "external" DIEs are part of the global scope.
8162 But in Ada and Fortran, we want to be able to access nested
8163 procedures globally. So all Ada and Fortran subprograms are
8164 stored in the global scope. */
8165 add_psymbol_to_list (actual_name
,
8166 built_actual_name
!= NULL
,
8167 VAR_DOMAIN
, LOC_BLOCK
,
8168 SECT_OFF_TEXT (objfile
),
8169 psymbol_placement::GLOBAL
,
8171 cu
->language
, objfile
);
8175 add_psymbol_to_list (actual_name
,
8176 built_actual_name
!= NULL
,
8177 VAR_DOMAIN
, LOC_BLOCK
,
8178 SECT_OFF_TEXT (objfile
),
8179 psymbol_placement::STATIC
,
8180 addr
, cu
->language
, objfile
);
8183 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8184 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8186 case DW_TAG_constant
:
8187 add_psymbol_to_list (actual_name
,
8188 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8189 -1, (pdi
->is_external
8190 ? psymbol_placement::GLOBAL
8191 : psymbol_placement::STATIC
),
8192 0, cu
->language
, objfile
);
8194 case DW_TAG_variable
:
8196 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8200 && !dwarf2_per_objfile
->has_section_at_zero
)
8202 /* A global or static variable may also have been stripped
8203 out by the linker if unused, in which case its address
8204 will be nullified; do not add such variables into partial
8205 symbol table then. */
8207 else if (pdi
->is_external
)
8210 Don't enter into the minimal symbol tables as there is
8211 a minimal symbol table entry from the ELF symbols already.
8212 Enter into partial symbol table if it has a location
8213 descriptor or a type.
8214 If the location descriptor is missing, new_symbol will create
8215 a LOC_UNRESOLVED symbol, the address of the variable will then
8216 be determined from the minimal symbol table whenever the variable
8218 The address for the partial symbol table entry is not
8219 used by GDB, but it comes in handy for debugging partial symbol
8222 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8223 add_psymbol_to_list (actual_name
,
8224 built_actual_name
!= NULL
,
8225 VAR_DOMAIN
, LOC_STATIC
,
8226 SECT_OFF_TEXT (objfile
),
8227 psymbol_placement::GLOBAL
,
8228 addr
, cu
->language
, objfile
);
8232 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8234 /* Static Variable. Skip symbols whose value we cannot know (those
8235 without location descriptors or constant values). */
8236 if (!has_loc
&& !pdi
->has_const_value
)
8239 add_psymbol_to_list (actual_name
,
8240 built_actual_name
!= NULL
,
8241 VAR_DOMAIN
, LOC_STATIC
,
8242 SECT_OFF_TEXT (objfile
),
8243 psymbol_placement::STATIC
,
8245 cu
->language
, objfile
);
8248 case DW_TAG_typedef
:
8249 case DW_TAG_base_type
:
8250 case DW_TAG_subrange_type
:
8251 add_psymbol_to_list (actual_name
,
8252 built_actual_name
!= NULL
,
8253 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8254 psymbol_placement::STATIC
,
8255 0, cu
->language
, objfile
);
8257 case DW_TAG_imported_declaration
:
8258 case DW_TAG_namespace
:
8259 add_psymbol_to_list (actual_name
,
8260 built_actual_name
!= NULL
,
8261 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8262 psymbol_placement::GLOBAL
,
8263 0, cu
->language
, objfile
);
8266 /* With Fortran 77 there might be a "BLOCK DATA" module
8267 available without any name. If so, we skip the module as it
8268 doesn't bring any value. */
8269 if (actual_name
!= nullptr)
8270 add_psymbol_to_list (actual_name
,
8271 built_actual_name
!= NULL
,
8272 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8273 psymbol_placement::GLOBAL
,
8274 0, cu
->language
, objfile
);
8276 case DW_TAG_class_type
:
8277 case DW_TAG_interface_type
:
8278 case DW_TAG_structure_type
:
8279 case DW_TAG_union_type
:
8280 case DW_TAG_enumeration_type
:
8281 /* Skip external references. The DWARF standard says in the section
8282 about "Structure, Union, and Class Type Entries": "An incomplete
8283 structure, union or class type is represented by a structure,
8284 union or class entry that does not have a byte size attribute
8285 and that has a DW_AT_declaration attribute." */
8286 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8289 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8290 static vs. global. */
8291 add_psymbol_to_list (actual_name
,
8292 built_actual_name
!= NULL
,
8293 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8294 cu
->language
== language_cplus
8295 ? psymbol_placement::GLOBAL
8296 : psymbol_placement::STATIC
,
8297 0, cu
->language
, objfile
);
8300 case DW_TAG_enumerator
:
8301 add_psymbol_to_list (actual_name
,
8302 built_actual_name
!= NULL
,
8303 VAR_DOMAIN
, LOC_CONST
, -1,
8304 cu
->language
== language_cplus
8305 ? psymbol_placement::GLOBAL
8306 : psymbol_placement::STATIC
,
8307 0, cu
->language
, objfile
);
8314 /* Read a partial die corresponding to a namespace; also, add a symbol
8315 corresponding to that namespace to the symbol table. NAMESPACE is
8316 the name of the enclosing namespace. */
8319 add_partial_namespace (struct partial_die_info
*pdi
,
8320 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8321 int set_addrmap
, struct dwarf2_cu
*cu
)
8323 /* Add a symbol for the namespace. */
8325 add_partial_symbol (pdi
, cu
);
8327 /* Now scan partial symbols in that namespace. */
8329 if (pdi
->has_children
)
8330 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8333 /* Read a partial die corresponding to a Fortran module. */
8336 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8337 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8339 /* Add a symbol for the namespace. */
8341 add_partial_symbol (pdi
, cu
);
8343 /* Now scan partial symbols in that module. */
8345 if (pdi
->has_children
)
8346 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8349 /* Read a partial die corresponding to a subprogram or an inlined
8350 subprogram and create a partial symbol for that subprogram.
8351 When the CU language allows it, this routine also defines a partial
8352 symbol for each nested subprogram that this subprogram contains.
8353 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8354 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8356 PDI may also be a lexical block, in which case we simply search
8357 recursively for subprograms defined inside that lexical block.
8358 Again, this is only performed when the CU language allows this
8359 type of definitions. */
8362 add_partial_subprogram (struct partial_die_info
*pdi
,
8363 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8364 int set_addrmap
, struct dwarf2_cu
*cu
)
8366 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8368 if (pdi
->has_pc_info
)
8370 if (pdi
->lowpc
< *lowpc
)
8371 *lowpc
= pdi
->lowpc
;
8372 if (pdi
->highpc
> *highpc
)
8373 *highpc
= pdi
->highpc
;
8376 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8377 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8379 CORE_ADDR this_highpc
;
8380 CORE_ADDR this_lowpc
;
8382 baseaddr
= objfile
->text_section_offset ();
8384 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8385 pdi
->lowpc
+ baseaddr
)
8388 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8389 pdi
->highpc
+ baseaddr
)
8391 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8392 this_lowpc
, this_highpc
- 1,
8393 cu
->per_cu
->v
.psymtab
);
8397 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8399 if (!pdi
->is_declaration
)
8400 /* Ignore subprogram DIEs that do not have a name, they are
8401 illegal. Do not emit a complaint at this point, we will
8402 do so when we convert this psymtab into a symtab. */
8404 add_partial_symbol (pdi
, cu
);
8408 if (! pdi
->has_children
)
8411 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8413 pdi
= pdi
->die_child
;
8417 if (pdi
->tag
== DW_TAG_subprogram
8418 || pdi
->tag
== DW_TAG_inlined_subroutine
8419 || pdi
->tag
== DW_TAG_lexical_block
)
8420 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8421 pdi
= pdi
->die_sibling
;
8426 /* Read a partial die corresponding to an enumeration type. */
8429 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8430 struct dwarf2_cu
*cu
)
8432 struct partial_die_info
*pdi
;
8434 if (enum_pdi
->name
!= NULL
)
8435 add_partial_symbol (enum_pdi
, cu
);
8437 pdi
= enum_pdi
->die_child
;
8440 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8441 complaint (_("malformed enumerator DIE ignored"));
8443 add_partial_symbol (pdi
, cu
);
8444 pdi
= pdi
->die_sibling
;
8448 /* Return the initial uleb128 in the die at INFO_PTR. */
8451 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8453 unsigned int bytes_read
;
8455 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8458 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8459 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8461 Return the corresponding abbrev, or NULL if the number is zero (indicating
8462 an empty DIE). In either case *BYTES_READ will be set to the length of
8463 the initial number. */
8465 static struct abbrev_info
*
8466 peek_die_abbrev (const die_reader_specs
&reader
,
8467 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8469 dwarf2_cu
*cu
= reader
.cu
;
8470 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8471 unsigned int abbrev_number
8472 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8474 if (abbrev_number
== 0)
8477 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8480 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8481 " at offset %s [in module %s]"),
8482 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8483 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8489 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8490 Returns a pointer to the end of a series of DIEs, terminated by an empty
8491 DIE. Any children of the skipped DIEs will also be skipped. */
8493 static const gdb_byte
*
8494 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8498 unsigned int bytes_read
;
8499 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8502 return info_ptr
+ bytes_read
;
8504 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8508 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8509 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8510 abbrev corresponding to that skipped uleb128 should be passed in
8511 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8514 static const gdb_byte
*
8515 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8516 struct abbrev_info
*abbrev
)
8518 unsigned int bytes_read
;
8519 struct attribute attr
;
8520 bfd
*abfd
= reader
->abfd
;
8521 struct dwarf2_cu
*cu
= reader
->cu
;
8522 const gdb_byte
*buffer
= reader
->buffer
;
8523 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8524 unsigned int form
, i
;
8526 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8528 /* The only abbrev we care about is DW_AT_sibling. */
8529 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8532 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8534 if (attr
.form
== DW_FORM_ref_addr
)
8535 complaint (_("ignoring absolute DW_AT_sibling"));
8538 sect_offset off
= attr
.get_ref_die_offset ();
8539 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8541 if (sibling_ptr
< info_ptr
)
8542 complaint (_("DW_AT_sibling points backwards"));
8543 else if (sibling_ptr
> reader
->buffer_end
)
8544 reader
->die_section
->overflow_complaint ();
8550 /* If it isn't DW_AT_sibling, skip this attribute. */
8551 form
= abbrev
->attrs
[i
].form
;
8555 case DW_FORM_ref_addr
:
8556 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8557 and later it is offset sized. */
8558 if (cu
->header
.version
== 2)
8559 info_ptr
+= cu
->header
.addr_size
;
8561 info_ptr
+= cu
->header
.offset_size
;
8563 case DW_FORM_GNU_ref_alt
:
8564 info_ptr
+= cu
->header
.offset_size
;
8567 info_ptr
+= cu
->header
.addr_size
;
8575 case DW_FORM_flag_present
:
8576 case DW_FORM_implicit_const
:
8593 case DW_FORM_ref_sig8
:
8596 case DW_FORM_data16
:
8599 case DW_FORM_string
:
8600 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8601 info_ptr
+= bytes_read
;
8603 case DW_FORM_sec_offset
:
8605 case DW_FORM_GNU_strp_alt
:
8606 info_ptr
+= cu
->header
.offset_size
;
8608 case DW_FORM_exprloc
:
8610 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8611 info_ptr
+= bytes_read
;
8613 case DW_FORM_block1
:
8614 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8616 case DW_FORM_block2
:
8617 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8619 case DW_FORM_block4
:
8620 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8626 case DW_FORM_ref_udata
:
8627 case DW_FORM_GNU_addr_index
:
8628 case DW_FORM_GNU_str_index
:
8629 case DW_FORM_rnglistx
:
8630 case DW_FORM_loclistx
:
8631 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8633 case DW_FORM_indirect
:
8634 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8635 info_ptr
+= bytes_read
;
8636 /* We need to continue parsing from here, so just go back to
8638 goto skip_attribute
;
8641 error (_("Dwarf Error: Cannot handle %s "
8642 "in DWARF reader [in module %s]"),
8643 dwarf_form_name (form
),
8644 bfd_get_filename (abfd
));
8648 if (abbrev
->has_children
)
8649 return skip_children (reader
, info_ptr
);
8654 /* Locate ORIG_PDI's sibling.
8655 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8657 static const gdb_byte
*
8658 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8659 struct partial_die_info
*orig_pdi
,
8660 const gdb_byte
*info_ptr
)
8662 /* Do we know the sibling already? */
8664 if (orig_pdi
->sibling
)
8665 return orig_pdi
->sibling
;
8667 /* Are there any children to deal with? */
8669 if (!orig_pdi
->has_children
)
8672 /* Skip the children the long way. */
8674 return skip_children (reader
, info_ptr
);
8677 /* Expand this partial symbol table into a full symbol table. SELF is
8681 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8683 struct dwarf2_per_objfile
*dwarf2_per_objfile
8684 = get_dwarf2_per_objfile (objfile
);
8686 gdb_assert (!readin
);
8687 /* If this psymtab is constructed from a debug-only objfile, the
8688 has_section_at_zero flag will not necessarily be correct. We
8689 can get the correct value for this flag by looking at the data
8690 associated with the (presumably stripped) associated objfile. */
8691 if (objfile
->separate_debug_objfile_backlink
)
8693 struct dwarf2_per_objfile
*dpo_backlink
8694 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8696 dwarf2_per_objfile
->has_section_at_zero
8697 = dpo_backlink
->has_section_at_zero
;
8700 expand_psymtab (objfile
);
8702 process_cu_includes (dwarf2_per_objfile
);
8705 /* Reading in full CUs. */
8707 /* Add PER_CU to the queue. */
8710 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8711 enum language pretend_language
)
8714 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8717 /* If PER_CU is not yet queued, add it to the queue.
8718 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8720 The result is non-zero if PER_CU was queued, otherwise the result is zero
8721 meaning either PER_CU is already queued or it is already loaded.
8723 N.B. There is an invariant here that if a CU is queued then it is loaded.
8724 The caller is required to load PER_CU if we return non-zero. */
8727 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8728 struct dwarf2_per_cu_data
*per_cu
,
8729 enum language pretend_language
)
8731 /* We may arrive here during partial symbol reading, if we need full
8732 DIEs to process an unusual case (e.g. template arguments). Do
8733 not queue PER_CU, just tell our caller to load its DIEs. */
8734 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8736 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8741 /* Mark the dependence relation so that we don't flush PER_CU
8743 if (dependent_cu
!= NULL
)
8744 dwarf2_add_dependence (dependent_cu
, per_cu
);
8746 /* If it's already on the queue, we have nothing to do. */
8750 /* If the compilation unit is already loaded, just mark it as
8752 if (per_cu
->cu
!= NULL
)
8754 per_cu
->cu
->last_used
= 0;
8758 /* Add it to the queue. */
8759 queue_comp_unit (per_cu
, pretend_language
);
8764 /* Process the queue. */
8767 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8769 if (dwarf_read_debug
)
8771 fprintf_unfiltered (gdb_stdlog
,
8772 "Expanding one or more symtabs of objfile %s ...\n",
8773 objfile_name (dwarf2_per_objfile
->objfile
));
8776 /* The queue starts out with one item, but following a DIE reference
8777 may load a new CU, adding it to the end of the queue. */
8778 while (!dwarf2_per_objfile
->queue
.empty ())
8780 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8782 if ((dwarf2_per_objfile
->using_index
8783 ? !item
.per_cu
->v
.quick
->compunit_symtab
8784 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8785 /* Skip dummy CUs. */
8786 && item
.per_cu
->cu
!= NULL
)
8788 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8789 unsigned int debug_print_threshold
;
8792 if (per_cu
->is_debug_types
)
8794 struct signatured_type
*sig_type
=
8795 (struct signatured_type
*) per_cu
;
8797 sprintf (buf
, "TU %s at offset %s",
8798 hex_string (sig_type
->signature
),
8799 sect_offset_str (per_cu
->sect_off
));
8800 /* There can be 100s of TUs.
8801 Only print them in verbose mode. */
8802 debug_print_threshold
= 2;
8806 sprintf (buf
, "CU at offset %s",
8807 sect_offset_str (per_cu
->sect_off
));
8808 debug_print_threshold
= 1;
8811 if (dwarf_read_debug
>= debug_print_threshold
)
8812 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8814 if (per_cu
->is_debug_types
)
8815 process_full_type_unit (per_cu
, item
.pretend_language
);
8817 process_full_comp_unit (per_cu
, item
.pretend_language
);
8819 if (dwarf_read_debug
>= debug_print_threshold
)
8820 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8823 item
.per_cu
->queued
= 0;
8824 dwarf2_per_objfile
->queue
.pop ();
8827 if (dwarf_read_debug
)
8829 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8830 objfile_name (dwarf2_per_objfile
->objfile
));
8834 /* Read in full symbols for PST, and anything it depends on. */
8837 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8842 expand_dependencies (objfile
);
8844 dw2_do_instantiate_symtab (per_cu_data
, false);
8845 gdb_assert (get_compunit_symtab () != nullptr);
8848 /* Trivial hash function for die_info: the hash value of a DIE
8849 is its offset in .debug_info for this objfile. */
8852 die_hash (const void *item
)
8854 const struct die_info
*die
= (const struct die_info
*) item
;
8856 return to_underlying (die
->sect_off
);
8859 /* Trivial comparison function for die_info structures: two DIEs
8860 are equal if they have the same offset. */
8863 die_eq (const void *item_lhs
, const void *item_rhs
)
8865 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8866 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8868 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8871 /* Load the DIEs associated with PER_CU into memory. */
8874 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8876 enum language pretend_language
)
8878 gdb_assert (! this_cu
->is_debug_types
);
8880 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8884 struct dwarf2_cu
*cu
= reader
.cu
;
8885 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8887 gdb_assert (cu
->die_hash
== NULL
);
8889 htab_create_alloc_ex (cu
->header
.length
/ 12,
8893 &cu
->comp_unit_obstack
,
8894 hashtab_obstack_allocate
,
8895 dummy_obstack_deallocate
);
8897 if (reader
.comp_unit_die
->has_children
)
8898 reader
.comp_unit_die
->child
8899 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8900 &info_ptr
, reader
.comp_unit_die
);
8901 cu
->dies
= reader
.comp_unit_die
;
8902 /* comp_unit_die is not stored in die_hash, no need. */
8904 /* We try not to read any attributes in this function, because not
8905 all CUs needed for references have been loaded yet, and symbol
8906 table processing isn't initialized. But we have to set the CU language,
8907 or we won't be able to build types correctly.
8908 Similarly, if we do not read the producer, we can not apply
8909 producer-specific interpretation. */
8910 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8915 /* Add a DIE to the delayed physname list. */
8918 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8919 const char *name
, struct die_info
*die
,
8920 struct dwarf2_cu
*cu
)
8922 struct delayed_method_info mi
;
8924 mi
.fnfield_index
= fnfield_index
;
8928 cu
->method_list
.push_back (mi
);
8931 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8932 "const" / "volatile". If so, decrements LEN by the length of the
8933 modifier and return true. Otherwise return false. */
8937 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8939 size_t mod_len
= sizeof (mod
) - 1;
8940 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8948 /* Compute the physnames of any methods on the CU's method list.
8950 The computation of method physnames is delayed in order to avoid the
8951 (bad) condition that one of the method's formal parameters is of an as yet
8955 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8957 /* Only C++ delays computing physnames. */
8958 if (cu
->method_list
.empty ())
8960 gdb_assert (cu
->language
== language_cplus
);
8962 for (const delayed_method_info
&mi
: cu
->method_list
)
8964 const char *physname
;
8965 struct fn_fieldlist
*fn_flp
8966 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8967 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8968 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8969 = physname
? physname
: "";
8971 /* Since there's no tag to indicate whether a method is a
8972 const/volatile overload, extract that information out of the
8974 if (physname
!= NULL
)
8976 size_t len
= strlen (physname
);
8980 if (physname
[len
] == ')') /* shortcut */
8982 else if (check_modifier (physname
, len
, " const"))
8983 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8984 else if (check_modifier (physname
, len
, " volatile"))
8985 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8992 /* The list is no longer needed. */
8993 cu
->method_list
.clear ();
8996 /* Go objects should be embedded in a DW_TAG_module DIE,
8997 and it's not clear if/how imported objects will appear.
8998 To keep Go support simple until that's worked out,
8999 go back through what we've read and create something usable.
9000 We could do this while processing each DIE, and feels kinda cleaner,
9001 but that way is more invasive.
9002 This is to, for example, allow the user to type "p var" or "b main"
9003 without having to specify the package name, and allow lookups
9004 of module.object to work in contexts that use the expression
9008 fixup_go_packaging (struct dwarf2_cu
*cu
)
9010 gdb::unique_xmalloc_ptr
<char> package_name
;
9011 struct pending
*list
;
9014 for (list
= *cu
->get_builder ()->get_global_symbols ();
9018 for (i
= 0; i
< list
->nsyms
; ++i
)
9020 struct symbol
*sym
= list
->symbol
[i
];
9022 if (sym
->language () == language_go
9023 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9025 gdb::unique_xmalloc_ptr
<char> this_package_name
9026 (go_symbol_package_name (sym
));
9028 if (this_package_name
== NULL
)
9030 if (package_name
== NULL
)
9031 package_name
= std::move (this_package_name
);
9034 struct objfile
*objfile
9035 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9036 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9037 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9038 (symbol_symtab (sym
) != NULL
9039 ? symtab_to_filename_for_display
9040 (symbol_symtab (sym
))
9041 : objfile_name (objfile
)),
9042 this_package_name
.get (), package_name
.get ());
9048 if (package_name
!= NULL
)
9050 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9051 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9052 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9053 saved_package_name
);
9056 sym
= allocate_symbol (objfile
);
9057 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9058 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9059 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9060 e.g., "main" finds the "main" module and not C's main(). */
9061 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9062 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9063 SYMBOL_TYPE (sym
) = type
;
9065 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9069 /* Allocate a fully-qualified name consisting of the two parts on the
9073 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9075 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9078 /* A helper that allocates a struct discriminant_info to attach to a
9081 static struct discriminant_info
*
9082 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9085 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9086 gdb_assert (discriminant_index
== -1
9087 || (discriminant_index
>= 0
9088 && discriminant_index
< TYPE_NFIELDS (type
)));
9089 gdb_assert (default_index
== -1
9090 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9092 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9094 struct discriminant_info
*disc
9095 = ((struct discriminant_info
*)
9097 offsetof (struct discriminant_info
, discriminants
)
9098 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9099 disc
->default_index
= default_index
;
9100 disc
->discriminant_index
= discriminant_index
;
9102 struct dynamic_prop prop
;
9103 prop
.kind
= PROP_UNDEFINED
;
9104 prop
.data
.baton
= disc
;
9106 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9111 /* Some versions of rustc emitted enums in an unusual way.
9113 Ordinary enums were emitted as unions. The first element of each
9114 structure in the union was named "RUST$ENUM$DISR". This element
9115 held the discriminant.
9117 These versions of Rust also implemented the "non-zero"
9118 optimization. When the enum had two values, and one is empty and
9119 the other holds a pointer that cannot be zero, the pointer is used
9120 as the discriminant, with a zero value meaning the empty variant.
9121 Here, the union's first member is of the form
9122 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9123 where the fieldnos are the indices of the fields that should be
9124 traversed in order to find the field (which may be several fields deep)
9125 and the variantname is the name of the variant of the case when the
9128 This function recognizes whether TYPE is of one of these forms,
9129 and, if so, smashes it to be a variant type. */
9132 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9134 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9136 /* We don't need to deal with empty enums. */
9137 if (TYPE_NFIELDS (type
) == 0)
9140 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9141 if (TYPE_NFIELDS (type
) == 1
9142 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9144 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9146 /* Decode the field name to find the offset of the
9148 ULONGEST bit_offset
= 0;
9149 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9150 while (name
[0] >= '0' && name
[0] <= '9')
9153 unsigned long index
= strtoul (name
, &tail
, 10);
9156 || index
>= TYPE_NFIELDS (field_type
)
9157 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9158 != FIELD_LOC_KIND_BITPOS
))
9160 complaint (_("Could not parse Rust enum encoding string \"%s\""
9162 TYPE_FIELD_NAME (type
, 0),
9163 objfile_name (objfile
));
9168 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9169 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9172 /* Make a union to hold the variants. */
9173 struct type
*union_type
= alloc_type (objfile
);
9174 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9175 TYPE_NFIELDS (union_type
) = 3;
9176 TYPE_FIELDS (union_type
)
9177 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9178 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9179 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9181 /* Put the discriminant must at index 0. */
9182 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9183 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9184 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9185 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9187 /* The order of fields doesn't really matter, so put the real
9188 field at index 1 and the data-less field at index 2. */
9189 struct discriminant_info
*disc
9190 = alloc_discriminant_info (union_type
, 0, 1);
9191 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9192 TYPE_FIELD_NAME (union_type
, 1)
9193 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9194 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9195 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9196 TYPE_FIELD_NAME (union_type
, 1));
9198 const char *dataless_name
9199 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9201 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9203 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9204 /* NAME points into the original discriminant name, which
9205 already has the correct lifetime. */
9206 TYPE_FIELD_NAME (union_type
, 2) = name
;
9207 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9208 disc
->discriminants
[2] = 0;
9210 /* Smash this type to be a structure type. We have to do this
9211 because the type has already been recorded. */
9212 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9213 TYPE_NFIELDS (type
) = 1;
9215 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9217 /* Install the variant part. */
9218 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9219 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9220 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9222 /* A union with a single anonymous field is probably an old-style
9224 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9226 /* Smash this type to be a structure type. We have to do this
9227 because the type has already been recorded. */
9228 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9230 /* Make a union to hold the variants. */
9231 struct type
*union_type
= alloc_type (objfile
);
9232 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9233 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9234 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9235 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9236 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9238 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9239 const char *variant_name
9240 = rust_last_path_segment (TYPE_NAME (field_type
));
9241 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9242 TYPE_NAME (field_type
)
9243 = rust_fully_qualify (&objfile
->objfile_obstack
,
9244 TYPE_NAME (type
), variant_name
);
9246 /* Install the union in the outer struct type. */
9247 TYPE_NFIELDS (type
) = 1;
9249 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9250 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9251 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9252 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9254 alloc_discriminant_info (union_type
, -1, 0);
9258 struct type
*disr_type
= nullptr;
9259 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9261 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9263 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9265 /* All fields of a true enum will be structs. */
9268 else if (TYPE_NFIELDS (disr_type
) == 0)
9270 /* Could be data-less variant, so keep going. */
9271 disr_type
= nullptr;
9273 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9274 "RUST$ENUM$DISR") != 0)
9276 /* Not a Rust enum. */
9286 /* If we got here without a discriminant, then it's probably
9288 if (disr_type
== nullptr)
9291 /* Smash this type to be a structure type. We have to do this
9292 because the type has already been recorded. */
9293 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9295 /* Make a union to hold the variants. */
9296 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9297 struct type
*union_type
= alloc_type (objfile
);
9298 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9299 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9300 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9301 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9302 TYPE_FIELDS (union_type
)
9303 = (struct field
*) TYPE_ZALLOC (union_type
,
9304 (TYPE_NFIELDS (union_type
)
9305 * sizeof (struct field
)));
9307 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9308 TYPE_NFIELDS (type
) * sizeof (struct field
));
9310 /* Install the discriminant at index 0 in the union. */
9311 TYPE_FIELD (union_type
, 0) = *disr_field
;
9312 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9313 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9315 /* Install the union in the outer struct type. */
9316 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9317 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9318 TYPE_NFIELDS (type
) = 1;
9320 /* Set the size and offset of the union type. */
9321 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9323 /* We need a way to find the correct discriminant given a
9324 variant name. For convenience we build a map here. */
9325 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9326 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9327 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9329 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9332 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9333 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9337 int n_fields
= TYPE_NFIELDS (union_type
);
9338 struct discriminant_info
*disc
9339 = alloc_discriminant_info (union_type
, 0, -1);
9340 /* Skip the discriminant here. */
9341 for (int i
= 1; i
< n_fields
; ++i
)
9343 /* Find the final word in the name of this variant's type.
9344 That name can be used to look up the correct
9346 const char *variant_name
9347 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9350 auto iter
= discriminant_map
.find (variant_name
);
9351 if (iter
!= discriminant_map
.end ())
9352 disc
->discriminants
[i
] = iter
->second
;
9354 /* Remove the discriminant field, if it exists. */
9355 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9356 if (TYPE_NFIELDS (sub_type
) > 0)
9358 --TYPE_NFIELDS (sub_type
);
9359 ++TYPE_FIELDS (sub_type
);
9361 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9362 TYPE_NAME (sub_type
)
9363 = rust_fully_qualify (&objfile
->objfile_obstack
,
9364 TYPE_NAME (type
), variant_name
);
9369 /* Rewrite some Rust unions to be structures with variants parts. */
9372 rust_union_quirks (struct dwarf2_cu
*cu
)
9374 gdb_assert (cu
->language
== language_rust
);
9375 for (type
*type_
: cu
->rust_unions
)
9376 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9377 /* We don't need this any more. */
9378 cu
->rust_unions
.clear ();
9381 /* Return the symtab for PER_CU. This works properly regardless of
9382 whether we're using the index or psymtabs. */
9384 static struct compunit_symtab
*
9385 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9387 return (per_cu
->dwarf2_per_objfile
->using_index
9388 ? per_cu
->v
.quick
->compunit_symtab
9389 : per_cu
->v
.psymtab
->compunit_symtab
);
9392 /* A helper function for computing the list of all symbol tables
9393 included by PER_CU. */
9396 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9397 htab_t all_children
, htab_t all_type_symtabs
,
9398 struct dwarf2_per_cu_data
*per_cu
,
9399 struct compunit_symtab
*immediate_parent
)
9402 struct compunit_symtab
*cust
;
9404 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9407 /* This inclusion and its children have been processed. */
9412 /* Only add a CU if it has a symbol table. */
9413 cust
= get_compunit_symtab (per_cu
);
9416 /* If this is a type unit only add its symbol table if we haven't
9417 seen it yet (type unit per_cu's can share symtabs). */
9418 if (per_cu
->is_debug_types
)
9420 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9424 result
->push_back (cust
);
9425 if (cust
->user
== NULL
)
9426 cust
->user
= immediate_parent
;
9431 result
->push_back (cust
);
9432 if (cust
->user
== NULL
)
9433 cust
->user
= immediate_parent
;
9437 if (!per_cu
->imported_symtabs_empty ())
9438 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9440 recursively_compute_inclusions (result
, all_children
,
9441 all_type_symtabs
, ptr
, cust
);
9445 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9449 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9451 gdb_assert (! per_cu
->is_debug_types
);
9453 if (!per_cu
->imported_symtabs_empty ())
9456 std::vector
<compunit_symtab
*> result_symtabs
;
9457 htab_t all_children
, all_type_symtabs
;
9458 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9460 /* If we don't have a symtab, we can just skip this case. */
9464 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9465 NULL
, xcalloc
, xfree
);
9466 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9467 NULL
, xcalloc
, xfree
);
9469 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9471 recursively_compute_inclusions (&result_symtabs
, all_children
,
9472 all_type_symtabs
, ptr
, cust
);
9475 /* Now we have a transitive closure of all the included symtabs. */
9476 len
= result_symtabs
.size ();
9478 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9479 struct compunit_symtab
*, len
+ 1);
9480 memcpy (cust
->includes
, result_symtabs
.data (),
9481 len
* sizeof (compunit_symtab
*));
9482 cust
->includes
[len
] = NULL
;
9484 htab_delete (all_children
);
9485 htab_delete (all_type_symtabs
);
9489 /* Compute the 'includes' field for the symtabs of all the CUs we just
9493 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9495 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9497 if (! iter
->is_debug_types
)
9498 compute_compunit_symtab_includes (iter
);
9501 dwarf2_per_objfile
->just_read_cus
.clear ();
9504 /* Generate full symbol information for PER_CU, whose DIEs have
9505 already been loaded into memory. */
9508 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9509 enum language pretend_language
)
9511 struct dwarf2_cu
*cu
= per_cu
->cu
;
9512 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9513 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9514 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9515 CORE_ADDR lowpc
, highpc
;
9516 struct compunit_symtab
*cust
;
9518 struct block
*static_block
;
9521 baseaddr
= objfile
->text_section_offset ();
9523 /* Clear the list here in case something was left over. */
9524 cu
->method_list
.clear ();
9526 cu
->language
= pretend_language
;
9527 cu
->language_defn
= language_def (cu
->language
);
9529 /* Do line number decoding in read_file_scope () */
9530 process_die (cu
->dies
, cu
);
9532 /* For now fudge the Go package. */
9533 if (cu
->language
== language_go
)
9534 fixup_go_packaging (cu
);
9536 /* Now that we have processed all the DIEs in the CU, all the types
9537 should be complete, and it should now be safe to compute all of the
9539 compute_delayed_physnames (cu
);
9541 if (cu
->language
== language_rust
)
9542 rust_union_quirks (cu
);
9544 /* Some compilers don't define a DW_AT_high_pc attribute for the
9545 compilation unit. If the DW_AT_high_pc is missing, synthesize
9546 it, by scanning the DIE's below the compilation unit. */
9547 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9549 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9550 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9552 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9553 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9554 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9555 addrmap to help ensure it has an accurate map of pc values belonging to
9557 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9559 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9560 SECT_OFF_TEXT (objfile
),
9565 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9567 /* Set symtab language to language from DW_AT_language. If the
9568 compilation is from a C file generated by language preprocessors, do
9569 not set the language if it was already deduced by start_subfile. */
9570 if (!(cu
->language
== language_c
9571 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9572 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9574 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9575 produce DW_AT_location with location lists but it can be possibly
9576 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9577 there were bugs in prologue debug info, fixed later in GCC-4.5
9578 by "unwind info for epilogues" patch (which is not directly related).
9580 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9581 needed, it would be wrong due to missing DW_AT_producer there.
9583 Still one can confuse GDB by using non-standard GCC compilation
9584 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9586 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9587 cust
->locations_valid
= 1;
9589 if (gcc_4_minor
>= 5)
9590 cust
->epilogue_unwind_valid
= 1;
9592 cust
->call_site_htab
= cu
->call_site_htab
;
9595 if (dwarf2_per_objfile
->using_index
)
9596 per_cu
->v
.quick
->compunit_symtab
= cust
;
9599 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9600 pst
->compunit_symtab
= cust
;
9604 /* Push it for inclusion processing later. */
9605 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9607 /* Not needed any more. */
9608 cu
->reset_builder ();
9611 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9612 already been loaded into memory. */
9615 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9616 enum language pretend_language
)
9618 struct dwarf2_cu
*cu
= per_cu
->cu
;
9619 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9620 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9621 struct compunit_symtab
*cust
;
9622 struct signatured_type
*sig_type
;
9624 gdb_assert (per_cu
->is_debug_types
);
9625 sig_type
= (struct signatured_type
*) per_cu
;
9627 /* Clear the list here in case something was left over. */
9628 cu
->method_list
.clear ();
9630 cu
->language
= pretend_language
;
9631 cu
->language_defn
= language_def (cu
->language
);
9633 /* The symbol tables are set up in read_type_unit_scope. */
9634 process_die (cu
->dies
, cu
);
9636 /* For now fudge the Go package. */
9637 if (cu
->language
== language_go
)
9638 fixup_go_packaging (cu
);
9640 /* Now that we have processed all the DIEs in the CU, all the types
9641 should be complete, and it should now be safe to compute all of the
9643 compute_delayed_physnames (cu
);
9645 if (cu
->language
== language_rust
)
9646 rust_union_quirks (cu
);
9648 /* TUs share symbol tables.
9649 If this is the first TU to use this symtab, complete the construction
9650 of it with end_expandable_symtab. Otherwise, complete the addition of
9651 this TU's symbols to the existing symtab. */
9652 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9654 buildsym_compunit
*builder
= cu
->get_builder ();
9655 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9656 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9660 /* Set symtab language to language from DW_AT_language. If the
9661 compilation is from a C file generated by language preprocessors,
9662 do not set the language if it was already deduced by
9664 if (!(cu
->language
== language_c
9665 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9666 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9671 cu
->get_builder ()->augment_type_symtab ();
9672 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9675 if (dwarf2_per_objfile
->using_index
)
9676 per_cu
->v
.quick
->compunit_symtab
= cust
;
9679 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9680 pst
->compunit_symtab
= cust
;
9684 /* Not needed any more. */
9685 cu
->reset_builder ();
9688 /* Process an imported unit DIE. */
9691 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9693 struct attribute
*attr
;
9695 /* For now we don't handle imported units in type units. */
9696 if (cu
->per_cu
->is_debug_types
)
9698 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9699 " supported in type units [in module %s]"),
9700 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9703 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9706 sect_offset sect_off
= attr
->get_ref_die_offset ();
9707 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9708 dwarf2_per_cu_data
*per_cu
9709 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9710 cu
->per_cu
->dwarf2_per_objfile
);
9712 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9713 into another compilation unit, at root level. Regard this as a hint,
9715 if (die
->parent
&& die
->parent
->parent
== NULL
9716 && per_cu
->unit_type
== DW_UT_compile
9717 && per_cu
->lang
== language_cplus
)
9720 /* If necessary, add it to the queue and load its DIEs. */
9721 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9722 load_full_comp_unit (per_cu
, false, cu
->language
);
9724 cu
->per_cu
->imported_symtabs_push (per_cu
);
9728 /* RAII object that represents a process_die scope: i.e.,
9729 starts/finishes processing a DIE. */
9730 class process_die_scope
9733 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9734 : m_die (die
), m_cu (cu
)
9736 /* We should only be processing DIEs not already in process. */
9737 gdb_assert (!m_die
->in_process
);
9738 m_die
->in_process
= true;
9741 ~process_die_scope ()
9743 m_die
->in_process
= false;
9745 /* If we're done processing the DIE for the CU that owns the line
9746 header, we don't need the line header anymore. */
9747 if (m_cu
->line_header_die_owner
== m_die
)
9749 delete m_cu
->line_header
;
9750 m_cu
->line_header
= NULL
;
9751 m_cu
->line_header_die_owner
= NULL
;
9760 /* Process a die and its children. */
9763 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9765 process_die_scope
scope (die
, cu
);
9769 case DW_TAG_padding
:
9771 case DW_TAG_compile_unit
:
9772 case DW_TAG_partial_unit
:
9773 read_file_scope (die
, cu
);
9775 case DW_TAG_type_unit
:
9776 read_type_unit_scope (die
, cu
);
9778 case DW_TAG_subprogram
:
9779 /* Nested subprograms in Fortran get a prefix. */
9780 if (cu
->language
== language_fortran
9781 && die
->parent
!= NULL
9782 && die
->parent
->tag
== DW_TAG_subprogram
)
9783 cu
->processing_has_namespace_info
= true;
9785 case DW_TAG_inlined_subroutine
:
9786 read_func_scope (die
, cu
);
9788 case DW_TAG_lexical_block
:
9789 case DW_TAG_try_block
:
9790 case DW_TAG_catch_block
:
9791 read_lexical_block_scope (die
, cu
);
9793 case DW_TAG_call_site
:
9794 case DW_TAG_GNU_call_site
:
9795 read_call_site_scope (die
, cu
);
9797 case DW_TAG_class_type
:
9798 case DW_TAG_interface_type
:
9799 case DW_TAG_structure_type
:
9800 case DW_TAG_union_type
:
9801 process_structure_scope (die
, cu
);
9803 case DW_TAG_enumeration_type
:
9804 process_enumeration_scope (die
, cu
);
9807 /* These dies have a type, but processing them does not create
9808 a symbol or recurse to process the children. Therefore we can
9809 read them on-demand through read_type_die. */
9810 case DW_TAG_subroutine_type
:
9811 case DW_TAG_set_type
:
9812 case DW_TAG_array_type
:
9813 case DW_TAG_pointer_type
:
9814 case DW_TAG_ptr_to_member_type
:
9815 case DW_TAG_reference_type
:
9816 case DW_TAG_rvalue_reference_type
:
9817 case DW_TAG_string_type
:
9820 case DW_TAG_base_type
:
9821 case DW_TAG_subrange_type
:
9822 case DW_TAG_typedef
:
9823 /* Add a typedef symbol for the type definition, if it has a
9825 new_symbol (die
, read_type_die (die
, cu
), cu
);
9827 case DW_TAG_common_block
:
9828 read_common_block (die
, cu
);
9830 case DW_TAG_common_inclusion
:
9832 case DW_TAG_namespace
:
9833 cu
->processing_has_namespace_info
= true;
9834 read_namespace (die
, cu
);
9837 cu
->processing_has_namespace_info
= true;
9838 read_module (die
, cu
);
9840 case DW_TAG_imported_declaration
:
9841 cu
->processing_has_namespace_info
= true;
9842 if (read_namespace_alias (die
, cu
))
9844 /* The declaration is not a global namespace alias. */
9846 case DW_TAG_imported_module
:
9847 cu
->processing_has_namespace_info
= true;
9848 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9849 || cu
->language
!= language_fortran
))
9850 complaint (_("Tag '%s' has unexpected children"),
9851 dwarf_tag_name (die
->tag
));
9852 read_import_statement (die
, cu
);
9855 case DW_TAG_imported_unit
:
9856 process_imported_unit_die (die
, cu
);
9859 case DW_TAG_variable
:
9860 read_variable (die
, cu
);
9864 new_symbol (die
, NULL
, cu
);
9869 /* DWARF name computation. */
9871 /* A helper function for dwarf2_compute_name which determines whether DIE
9872 needs to have the name of the scope prepended to the name listed in the
9876 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9878 struct attribute
*attr
;
9882 case DW_TAG_namespace
:
9883 case DW_TAG_typedef
:
9884 case DW_TAG_class_type
:
9885 case DW_TAG_interface_type
:
9886 case DW_TAG_structure_type
:
9887 case DW_TAG_union_type
:
9888 case DW_TAG_enumeration_type
:
9889 case DW_TAG_enumerator
:
9890 case DW_TAG_subprogram
:
9891 case DW_TAG_inlined_subroutine
:
9893 case DW_TAG_imported_declaration
:
9896 case DW_TAG_variable
:
9897 case DW_TAG_constant
:
9898 /* We only need to prefix "globally" visible variables. These include
9899 any variable marked with DW_AT_external or any variable that
9900 lives in a namespace. [Variables in anonymous namespaces
9901 require prefixing, but they are not DW_AT_external.] */
9903 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9905 struct dwarf2_cu
*spec_cu
= cu
;
9907 return die_needs_namespace (die_specification (die
, &spec_cu
),
9911 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9912 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9913 && die
->parent
->tag
!= DW_TAG_module
)
9915 /* A variable in a lexical block of some kind does not need a
9916 namespace, even though in C++ such variables may be external
9917 and have a mangled name. */
9918 if (die
->parent
->tag
== DW_TAG_lexical_block
9919 || die
->parent
->tag
== DW_TAG_try_block
9920 || die
->parent
->tag
== DW_TAG_catch_block
9921 || die
->parent
->tag
== DW_TAG_subprogram
)
9930 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9931 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9932 defined for the given DIE. */
9934 static struct attribute
*
9935 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9937 struct attribute
*attr
;
9939 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9941 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9946 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9947 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9948 defined for the given DIE. */
9951 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9953 const char *linkage_name
;
9955 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9956 if (linkage_name
== NULL
)
9957 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9959 return linkage_name
;
9962 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9963 compute the physname for the object, which include a method's:
9964 - formal parameters (C++),
9965 - receiver type (Go),
9967 The term "physname" is a bit confusing.
9968 For C++, for example, it is the demangled name.
9969 For Go, for example, it's the mangled name.
9971 For Ada, return the DIE's linkage name rather than the fully qualified
9972 name. PHYSNAME is ignored..
9974 The result is allocated on the objfile_obstack and canonicalized. */
9977 dwarf2_compute_name (const char *name
,
9978 struct die_info
*die
, struct dwarf2_cu
*cu
,
9981 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9984 name
= dwarf2_name (die
, cu
);
9986 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9987 but otherwise compute it by typename_concat inside GDB.
9988 FIXME: Actually this is not really true, or at least not always true.
9989 It's all very confusing. compute_and_set_names doesn't try to demangle
9990 Fortran names because there is no mangling standard. So new_symbol
9991 will set the demangled name to the result of dwarf2_full_name, and it is
9992 the demangled name that GDB uses if it exists. */
9993 if (cu
->language
== language_ada
9994 || (cu
->language
== language_fortran
&& physname
))
9996 /* For Ada unit, we prefer the linkage name over the name, as
9997 the former contains the exported name, which the user expects
9998 to be able to reference. Ideally, we want the user to be able
9999 to reference this entity using either natural or linkage name,
10000 but we haven't started looking at this enhancement yet. */
10001 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10003 if (linkage_name
!= NULL
)
10004 return linkage_name
;
10007 /* These are the only languages we know how to qualify names in. */
10009 && (cu
->language
== language_cplus
10010 || cu
->language
== language_fortran
|| cu
->language
== language_d
10011 || cu
->language
== language_rust
))
10013 if (die_needs_namespace (die
, cu
))
10015 const char *prefix
;
10016 const char *canonical_name
= NULL
;
10020 prefix
= determine_prefix (die
, cu
);
10021 if (*prefix
!= '\0')
10023 gdb::unique_xmalloc_ptr
<char> prefixed_name
10024 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10026 buf
.puts (prefixed_name
.get ());
10031 /* Template parameters may be specified in the DIE's DW_AT_name, or
10032 as children with DW_TAG_template_type_param or
10033 DW_TAG_value_type_param. If the latter, add them to the name
10034 here. If the name already has template parameters, then
10035 skip this step; some versions of GCC emit both, and
10036 it is more efficient to use the pre-computed name.
10038 Something to keep in mind about this process: it is very
10039 unlikely, or in some cases downright impossible, to produce
10040 something that will match the mangled name of a function.
10041 If the definition of the function has the same debug info,
10042 we should be able to match up with it anyway. But fallbacks
10043 using the minimal symbol, for instance to find a method
10044 implemented in a stripped copy of libstdc++, will not work.
10045 If we do not have debug info for the definition, we will have to
10046 match them up some other way.
10048 When we do name matching there is a related problem with function
10049 templates; two instantiated function templates are allowed to
10050 differ only by their return types, which we do not add here. */
10052 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10054 struct attribute
*attr
;
10055 struct die_info
*child
;
10058 die
->building_fullname
= 1;
10060 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10064 const gdb_byte
*bytes
;
10065 struct dwarf2_locexpr_baton
*baton
;
10068 if (child
->tag
!= DW_TAG_template_type_param
10069 && child
->tag
!= DW_TAG_template_value_param
)
10080 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10083 complaint (_("template parameter missing DW_AT_type"));
10084 buf
.puts ("UNKNOWN_TYPE");
10087 type
= die_type (child
, cu
);
10089 if (child
->tag
== DW_TAG_template_type_param
)
10091 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10092 &type_print_raw_options
);
10096 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10099 complaint (_("template parameter missing "
10100 "DW_AT_const_value"));
10101 buf
.puts ("UNKNOWN_VALUE");
10105 dwarf2_const_value_attr (attr
, type
, name
,
10106 &cu
->comp_unit_obstack
, cu
,
10107 &value
, &bytes
, &baton
);
10109 if (TYPE_NOSIGN (type
))
10110 /* GDB prints characters as NUMBER 'CHAR'. If that's
10111 changed, this can use value_print instead. */
10112 c_printchar (value
, type
, &buf
);
10115 struct value_print_options opts
;
10118 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10122 else if (bytes
!= NULL
)
10124 v
= allocate_value (type
);
10125 memcpy (value_contents_writeable (v
), bytes
,
10126 TYPE_LENGTH (type
));
10129 v
= value_from_longest (type
, value
);
10131 /* Specify decimal so that we do not depend on
10133 get_formatted_print_options (&opts
, 'd');
10135 value_print (v
, &buf
, &opts
);
10140 die
->building_fullname
= 0;
10144 /* Close the argument list, with a space if necessary
10145 (nested templates). */
10146 if (!buf
.empty () && buf
.string ().back () == '>')
10153 /* For C++ methods, append formal parameter type
10154 information, if PHYSNAME. */
10156 if (physname
&& die
->tag
== DW_TAG_subprogram
10157 && cu
->language
== language_cplus
)
10159 struct type
*type
= read_type_die (die
, cu
);
10161 c_type_print_args (type
, &buf
, 1, cu
->language
,
10162 &type_print_raw_options
);
10164 if (cu
->language
== language_cplus
)
10166 /* Assume that an artificial first parameter is
10167 "this", but do not crash if it is not. RealView
10168 marks unnamed (and thus unused) parameters as
10169 artificial; there is no way to differentiate
10171 if (TYPE_NFIELDS (type
) > 0
10172 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10173 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10174 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10176 buf
.puts (" const");
10180 const std::string
&intermediate_name
= buf
.string ();
10182 if (cu
->language
== language_cplus
)
10184 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10187 /* If we only computed INTERMEDIATE_NAME, or if
10188 INTERMEDIATE_NAME is already canonical, then we need to
10190 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10191 name
= objfile
->intern (intermediate_name
);
10193 name
= canonical_name
;
10200 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10201 If scope qualifiers are appropriate they will be added. The result
10202 will be allocated on the storage_obstack, or NULL if the DIE does
10203 not have a name. NAME may either be from a previous call to
10204 dwarf2_name or NULL.
10206 The output string will be canonicalized (if C++). */
10208 static const char *
10209 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10211 return dwarf2_compute_name (name
, die
, cu
, 0);
10214 /* Construct a physname for the given DIE in CU. NAME may either be
10215 from a previous call to dwarf2_name or NULL. The result will be
10216 allocated on the objfile_objstack or NULL if the DIE does not have a
10219 The output string will be canonicalized (if C++). */
10221 static const char *
10222 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10224 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10225 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10228 /* In this case dwarf2_compute_name is just a shortcut not building anything
10230 if (!die_needs_namespace (die
, cu
))
10231 return dwarf2_compute_name (name
, die
, cu
, 1);
10233 mangled
= dw2_linkage_name (die
, cu
);
10235 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10236 See https://github.com/rust-lang/rust/issues/32925. */
10237 if (cu
->language
== language_rust
&& mangled
!= NULL
10238 && strchr (mangled
, '{') != NULL
)
10241 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10243 gdb::unique_xmalloc_ptr
<char> demangled
;
10244 if (mangled
!= NULL
)
10247 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10249 /* Do nothing (do not demangle the symbol name). */
10251 else if (cu
->language
== language_go
)
10253 /* This is a lie, but we already lie to the caller new_symbol.
10254 new_symbol assumes we return the mangled name.
10255 This just undoes that lie until things are cleaned up. */
10259 /* Use DMGL_RET_DROP for C++ template functions to suppress
10260 their return type. It is easier for GDB users to search
10261 for such functions as `name(params)' than `long name(params)'.
10262 In such case the minimal symbol names do not match the full
10263 symbol names but for template functions there is never a need
10264 to look up their definition from their declaration so
10265 the only disadvantage remains the minimal symbol variant
10266 `long name(params)' does not have the proper inferior type. */
10267 demangled
.reset (gdb_demangle (mangled
,
10268 (DMGL_PARAMS
| DMGL_ANSI
10269 | DMGL_RET_DROP
)));
10272 canon
= demangled
.get ();
10280 if (canon
== NULL
|| check_physname
)
10282 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10284 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10286 /* It may not mean a bug in GDB. The compiler could also
10287 compute DW_AT_linkage_name incorrectly. But in such case
10288 GDB would need to be bug-to-bug compatible. */
10290 complaint (_("Computed physname <%s> does not match demangled <%s> "
10291 "(from linkage <%s>) - DIE at %s [in module %s]"),
10292 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10293 objfile_name (objfile
));
10295 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10296 is available here - over computed PHYSNAME. It is safer
10297 against both buggy GDB and buggy compilers. */
10311 retval
= objfile
->intern (retval
);
10316 /* Inspect DIE in CU for a namespace alias. If one exists, record
10317 a new symbol for it.
10319 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10322 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10324 struct attribute
*attr
;
10326 /* If the die does not have a name, this is not a namespace
10328 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10332 struct die_info
*d
= die
;
10333 struct dwarf2_cu
*imported_cu
= cu
;
10335 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10336 keep inspecting DIEs until we hit the underlying import. */
10337 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10338 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10340 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10344 d
= follow_die_ref (d
, attr
, &imported_cu
);
10345 if (d
->tag
!= DW_TAG_imported_declaration
)
10349 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10351 complaint (_("DIE at %s has too many recursively imported "
10352 "declarations"), sect_offset_str (d
->sect_off
));
10359 sect_offset sect_off
= attr
->get_ref_die_offset ();
10361 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10362 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10364 /* This declaration is a global namespace alias. Add
10365 a symbol for it whose type is the aliased namespace. */
10366 new_symbol (die
, type
, cu
);
10375 /* Return the using directives repository (global or local?) to use in the
10376 current context for CU.
10378 For Ada, imported declarations can materialize renamings, which *may* be
10379 global. However it is impossible (for now?) in DWARF to distinguish
10380 "external" imported declarations and "static" ones. As all imported
10381 declarations seem to be static in all other languages, make them all CU-wide
10382 global only in Ada. */
10384 static struct using_direct
**
10385 using_directives (struct dwarf2_cu
*cu
)
10387 if (cu
->language
== language_ada
10388 && cu
->get_builder ()->outermost_context_p ())
10389 return cu
->get_builder ()->get_global_using_directives ();
10391 return cu
->get_builder ()->get_local_using_directives ();
10394 /* Read the import statement specified by the given die and record it. */
10397 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10399 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10400 struct attribute
*import_attr
;
10401 struct die_info
*imported_die
, *child_die
;
10402 struct dwarf2_cu
*imported_cu
;
10403 const char *imported_name
;
10404 const char *imported_name_prefix
;
10405 const char *canonical_name
;
10406 const char *import_alias
;
10407 const char *imported_declaration
= NULL
;
10408 const char *import_prefix
;
10409 std::vector
<const char *> excludes
;
10411 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10412 if (import_attr
== NULL
)
10414 complaint (_("Tag '%s' has no DW_AT_import"),
10415 dwarf_tag_name (die
->tag
));
10420 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10421 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10422 if (imported_name
== NULL
)
10424 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10426 The import in the following code:
10440 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10441 <52> DW_AT_decl_file : 1
10442 <53> DW_AT_decl_line : 6
10443 <54> DW_AT_import : <0x75>
10444 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10445 <59> DW_AT_name : B
10446 <5b> DW_AT_decl_file : 1
10447 <5c> DW_AT_decl_line : 2
10448 <5d> DW_AT_type : <0x6e>
10450 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10451 <76> DW_AT_byte_size : 4
10452 <77> DW_AT_encoding : 5 (signed)
10454 imports the wrong die ( 0x75 instead of 0x58 ).
10455 This case will be ignored until the gcc bug is fixed. */
10459 /* Figure out the local name after import. */
10460 import_alias
= dwarf2_name (die
, cu
);
10462 /* Figure out where the statement is being imported to. */
10463 import_prefix
= determine_prefix (die
, cu
);
10465 /* Figure out what the scope of the imported die is and prepend it
10466 to the name of the imported die. */
10467 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10469 if (imported_die
->tag
!= DW_TAG_namespace
10470 && imported_die
->tag
!= DW_TAG_module
)
10472 imported_declaration
= imported_name
;
10473 canonical_name
= imported_name_prefix
;
10475 else if (strlen (imported_name_prefix
) > 0)
10476 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10477 imported_name_prefix
,
10478 (cu
->language
== language_d
? "." : "::"),
10479 imported_name
, (char *) NULL
);
10481 canonical_name
= imported_name
;
10483 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10484 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10485 child_die
= child_die
->sibling
)
10487 /* DWARF-4: A Fortran use statement with a “rename list” may be
10488 represented by an imported module entry with an import attribute
10489 referring to the module and owned entries corresponding to those
10490 entities that are renamed as part of being imported. */
10492 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10494 complaint (_("child DW_TAG_imported_declaration expected "
10495 "- DIE at %s [in module %s]"),
10496 sect_offset_str (child_die
->sect_off
),
10497 objfile_name (objfile
));
10501 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10502 if (import_attr
== NULL
)
10504 complaint (_("Tag '%s' has no DW_AT_import"),
10505 dwarf_tag_name (child_die
->tag
));
10510 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10512 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10513 if (imported_name
== NULL
)
10515 complaint (_("child DW_TAG_imported_declaration has unknown "
10516 "imported name - DIE at %s [in module %s]"),
10517 sect_offset_str (child_die
->sect_off
),
10518 objfile_name (objfile
));
10522 excludes
.push_back (imported_name
);
10524 process_die (child_die
, cu
);
10527 add_using_directive (using_directives (cu
),
10531 imported_declaration
,
10534 &objfile
->objfile_obstack
);
10537 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10538 types, but gives them a size of zero. Starting with version 14,
10539 ICC is compatible with GCC. */
10542 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10544 if (!cu
->checked_producer
)
10545 check_producer (cu
);
10547 return cu
->producer_is_icc_lt_14
;
10550 /* ICC generates a DW_AT_type for C void functions. This was observed on
10551 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10552 which says that void functions should not have a DW_AT_type. */
10555 producer_is_icc (struct dwarf2_cu
*cu
)
10557 if (!cu
->checked_producer
)
10558 check_producer (cu
);
10560 return cu
->producer_is_icc
;
10563 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10564 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10565 this, it was first present in GCC release 4.3.0. */
10568 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10570 if (!cu
->checked_producer
)
10571 check_producer (cu
);
10573 return cu
->producer_is_gcc_lt_4_3
;
10576 static file_and_directory
10577 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10579 file_and_directory res
;
10581 /* Find the filename. Do not use dwarf2_name here, since the filename
10582 is not a source language identifier. */
10583 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10584 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10586 if (res
.comp_dir
== NULL
10587 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10588 && IS_ABSOLUTE_PATH (res
.name
))
10590 res
.comp_dir_storage
= ldirname (res
.name
);
10591 if (!res
.comp_dir_storage
.empty ())
10592 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10594 if (res
.comp_dir
!= NULL
)
10596 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10597 directory, get rid of it. */
10598 const char *cp
= strchr (res
.comp_dir
, ':');
10600 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10601 res
.comp_dir
= cp
+ 1;
10604 if (res
.name
== NULL
)
10605 res
.name
= "<unknown>";
10610 /* Handle DW_AT_stmt_list for a compilation unit.
10611 DIE is the DW_TAG_compile_unit die for CU.
10612 COMP_DIR is the compilation directory. LOWPC is passed to
10613 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10616 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10617 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10619 struct dwarf2_per_objfile
*dwarf2_per_objfile
10620 = cu
->per_cu
->dwarf2_per_objfile
;
10621 struct attribute
*attr
;
10622 struct line_header line_header_local
;
10623 hashval_t line_header_local_hash
;
10625 int decode_mapping
;
10627 gdb_assert (! cu
->per_cu
->is_debug_types
);
10629 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10633 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10635 /* The line header hash table is only created if needed (it exists to
10636 prevent redundant reading of the line table for partial_units).
10637 If we're given a partial_unit, we'll need it. If we're given a
10638 compile_unit, then use the line header hash table if it's already
10639 created, but don't create one just yet. */
10641 if (dwarf2_per_objfile
->line_header_hash
== NULL
10642 && die
->tag
== DW_TAG_partial_unit
)
10644 dwarf2_per_objfile
->line_header_hash
10645 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10646 line_header_eq_voidp
,
10647 free_line_header_voidp
,
10651 line_header_local
.sect_off
= line_offset
;
10652 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10653 line_header_local_hash
= line_header_hash (&line_header_local
);
10654 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10656 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10657 &line_header_local
,
10658 line_header_local_hash
, NO_INSERT
);
10660 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10661 is not present in *SLOT (since if there is something in *SLOT then
10662 it will be for a partial_unit). */
10663 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10665 gdb_assert (*slot
!= NULL
);
10666 cu
->line_header
= (struct line_header
*) *slot
;
10671 /* dwarf_decode_line_header does not yet provide sufficient information.
10672 We always have to call also dwarf_decode_lines for it. */
10673 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10677 cu
->line_header
= lh
.release ();
10678 cu
->line_header_die_owner
= die
;
10680 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10684 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10685 &line_header_local
,
10686 line_header_local_hash
, INSERT
);
10687 gdb_assert (slot
!= NULL
);
10689 if (slot
!= NULL
&& *slot
== NULL
)
10691 /* This newly decoded line number information unit will be owned
10692 by line_header_hash hash table. */
10693 *slot
= cu
->line_header
;
10694 cu
->line_header_die_owner
= NULL
;
10698 /* We cannot free any current entry in (*slot) as that struct line_header
10699 may be already used by multiple CUs. Create only temporary decoded
10700 line_header for this CU - it may happen at most once for each line
10701 number information unit. And if we're not using line_header_hash
10702 then this is what we want as well. */
10703 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10705 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10706 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10711 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10714 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10716 struct dwarf2_per_objfile
*dwarf2_per_objfile
10717 = cu
->per_cu
->dwarf2_per_objfile
;
10718 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10719 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10720 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10721 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10722 struct attribute
*attr
;
10723 struct die_info
*child_die
;
10724 CORE_ADDR baseaddr
;
10726 prepare_one_comp_unit (cu
, die
, cu
->language
);
10727 baseaddr
= objfile
->text_section_offset ();
10729 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10731 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10732 from finish_block. */
10733 if (lowpc
== ((CORE_ADDR
) -1))
10735 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10737 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10739 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10740 standardised yet. As a workaround for the language detection we fall
10741 back to the DW_AT_producer string. */
10742 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10743 cu
->language
= language_opencl
;
10745 /* Similar hack for Go. */
10746 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10747 set_cu_language (DW_LANG_Go
, cu
);
10749 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10751 /* Decode line number information if present. We do this before
10752 processing child DIEs, so that the line header table is available
10753 for DW_AT_decl_file. */
10754 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10756 /* Process all dies in compilation unit. */
10757 if (die
->child
!= NULL
)
10759 child_die
= die
->child
;
10760 while (child_die
&& child_die
->tag
)
10762 process_die (child_die
, cu
);
10763 child_die
= child_die
->sibling
;
10767 /* Decode macro information, if present. Dwarf 2 macro information
10768 refers to information in the line number info statement program
10769 header, so we can only read it if we've read the header
10771 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10773 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10774 if (attr
&& cu
->line_header
)
10776 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10777 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10779 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10783 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10784 if (attr
&& cu
->line_header
)
10786 unsigned int macro_offset
= DW_UNSND (attr
);
10788 dwarf_decode_macros (cu
, macro_offset
, 0);
10794 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10796 struct type_unit_group
*tu_group
;
10798 struct attribute
*attr
;
10800 struct signatured_type
*sig_type
;
10802 gdb_assert (per_cu
->is_debug_types
);
10803 sig_type
= (struct signatured_type
*) per_cu
;
10805 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10807 /* If we're using .gdb_index (includes -readnow) then
10808 per_cu->type_unit_group may not have been set up yet. */
10809 if (sig_type
->type_unit_group
== NULL
)
10810 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10811 tu_group
= sig_type
->type_unit_group
;
10813 /* If we've already processed this stmt_list there's no real need to
10814 do it again, we could fake it and just recreate the part we need
10815 (file name,index -> symtab mapping). If data shows this optimization
10816 is useful we can do it then. */
10817 first_time
= tu_group
->compunit_symtab
== NULL
;
10819 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10824 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10825 lh
= dwarf_decode_line_header (line_offset
, this);
10830 start_symtab ("", NULL
, 0);
10833 gdb_assert (tu_group
->symtabs
== NULL
);
10834 gdb_assert (m_builder
== nullptr);
10835 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10836 m_builder
.reset (new struct buildsym_compunit
10837 (COMPUNIT_OBJFILE (cust
), "",
10838 COMPUNIT_DIRNAME (cust
),
10839 compunit_language (cust
),
10845 line_header
= lh
.release ();
10846 line_header_die_owner
= die
;
10850 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10852 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10853 still initializing it, and our caller (a few levels up)
10854 process_full_type_unit still needs to know if this is the first
10858 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10859 struct symtab
*, line_header
->file_names_size ());
10861 auto &file_names
= line_header
->file_names ();
10862 for (i
= 0; i
< file_names
.size (); ++i
)
10864 file_entry
&fe
= file_names
[i
];
10865 dwarf2_start_subfile (this, fe
.name
,
10866 fe
.include_dir (line_header
));
10867 buildsym_compunit
*b
= get_builder ();
10868 if (b
->get_current_subfile ()->symtab
== NULL
)
10870 /* NOTE: start_subfile will recognize when it's been
10871 passed a file it has already seen. So we can't
10872 assume there's a simple mapping from
10873 cu->line_header->file_names to subfiles, plus
10874 cu->line_header->file_names may contain dups. */
10875 b
->get_current_subfile ()->symtab
10876 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10879 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10880 tu_group
->symtabs
[i
] = fe
.symtab
;
10885 gdb_assert (m_builder
== nullptr);
10886 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10887 m_builder
.reset (new struct buildsym_compunit
10888 (COMPUNIT_OBJFILE (cust
), "",
10889 COMPUNIT_DIRNAME (cust
),
10890 compunit_language (cust
),
10893 auto &file_names
= line_header
->file_names ();
10894 for (i
= 0; i
< file_names
.size (); ++i
)
10896 file_entry
&fe
= file_names
[i
];
10897 fe
.symtab
= tu_group
->symtabs
[i
];
10901 /* The main symtab is allocated last. Type units don't have DW_AT_name
10902 so they don't have a "real" (so to speak) symtab anyway.
10903 There is later code that will assign the main symtab to all symbols
10904 that don't have one. We need to handle the case of a symbol with a
10905 missing symtab (DW_AT_decl_file) anyway. */
10908 /* Process DW_TAG_type_unit.
10909 For TUs we want to skip the first top level sibling if it's not the
10910 actual type being defined by this TU. In this case the first top
10911 level sibling is there to provide context only. */
10914 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10916 struct die_info
*child_die
;
10918 prepare_one_comp_unit (cu
, die
, language_minimal
);
10920 /* Initialize (or reinitialize) the machinery for building symtabs.
10921 We do this before processing child DIEs, so that the line header table
10922 is available for DW_AT_decl_file. */
10923 cu
->setup_type_unit_groups (die
);
10925 if (die
->child
!= NULL
)
10927 child_die
= die
->child
;
10928 while (child_die
&& child_die
->tag
)
10930 process_die (child_die
, cu
);
10931 child_die
= child_die
->sibling
;
10938 http://gcc.gnu.org/wiki/DebugFission
10939 http://gcc.gnu.org/wiki/DebugFissionDWP
10941 To simplify handling of both DWO files ("object" files with the DWARF info)
10942 and DWP files (a file with the DWOs packaged up into one file), we treat
10943 DWP files as having a collection of virtual DWO files. */
10946 hash_dwo_file (const void *item
)
10948 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10951 hash
= htab_hash_string (dwo_file
->dwo_name
);
10952 if (dwo_file
->comp_dir
!= NULL
)
10953 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10958 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10960 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10961 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10963 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10965 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10966 return lhs
->comp_dir
== rhs
->comp_dir
;
10967 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10970 /* Allocate a hash table for DWO files. */
10973 allocate_dwo_file_hash_table ()
10975 auto delete_dwo_file
= [] (void *item
)
10977 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
10982 return htab_up (htab_create_alloc (41,
10989 /* Lookup DWO file DWO_NAME. */
10992 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
10993 const char *dwo_name
,
10994 const char *comp_dir
)
10996 struct dwo_file find_entry
;
10999 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11000 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
11002 find_entry
.dwo_name
= dwo_name
;
11003 find_entry
.comp_dir
= comp_dir
;
11004 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11011 hash_dwo_unit (const void *item
)
11013 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11015 /* This drops the top 32 bits of the id, but is ok for a hash. */
11016 return dwo_unit
->signature
;
11020 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11022 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11023 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11025 /* The signature is assumed to be unique within the DWO file.
11026 So while object file CU dwo_id's always have the value zero,
11027 that's OK, assuming each object file DWO file has only one CU,
11028 and that's the rule for now. */
11029 return lhs
->signature
== rhs
->signature
;
11032 /* Allocate a hash table for DWO CUs,TUs.
11033 There is one of these tables for each of CUs,TUs for each DWO file. */
11036 allocate_dwo_unit_table ()
11038 /* Start out with a pretty small number.
11039 Generally DWO files contain only one CU and maybe some TUs. */
11040 return htab_up (htab_create_alloc (3,
11043 NULL
, xcalloc
, xfree
));
11046 /* die_reader_func for create_dwo_cu. */
11049 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11050 const gdb_byte
*info_ptr
,
11051 struct die_info
*comp_unit_die
,
11052 struct dwo_file
*dwo_file
,
11053 struct dwo_unit
*dwo_unit
)
11055 struct dwarf2_cu
*cu
= reader
->cu
;
11056 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11057 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11059 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11060 if (!signature
.has_value ())
11062 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11063 " its dwo_id [in module %s]"),
11064 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11068 dwo_unit
->dwo_file
= dwo_file
;
11069 dwo_unit
->signature
= *signature
;
11070 dwo_unit
->section
= section
;
11071 dwo_unit
->sect_off
= sect_off
;
11072 dwo_unit
->length
= cu
->per_cu
->length
;
11074 if (dwarf_read_debug
)
11075 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11076 sect_offset_str (sect_off
),
11077 hex_string (dwo_unit
->signature
));
11080 /* Create the dwo_units for the CUs in a DWO_FILE.
11081 Note: This function processes DWO files only, not DWP files. */
11084 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11085 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11086 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11088 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11089 const gdb_byte
*info_ptr
, *end_ptr
;
11091 section
.read (objfile
);
11092 info_ptr
= section
.buffer
;
11094 if (info_ptr
== NULL
)
11097 if (dwarf_read_debug
)
11099 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11100 section
.get_name (),
11101 section
.get_file_name ());
11104 end_ptr
= info_ptr
+ section
.size
;
11105 while (info_ptr
< end_ptr
)
11107 struct dwarf2_per_cu_data per_cu
;
11108 struct dwo_unit read_unit
{};
11109 struct dwo_unit
*dwo_unit
;
11111 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11113 memset (&per_cu
, 0, sizeof (per_cu
));
11114 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11115 per_cu
.is_debug_types
= 0;
11116 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11117 per_cu
.section
= §ion
;
11119 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11120 if (!reader
.dummy_p
)
11121 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11122 &dwo_file
, &read_unit
);
11123 info_ptr
+= per_cu
.length
;
11125 // If the unit could not be parsed, skip it.
11126 if (read_unit
.dwo_file
== NULL
)
11129 if (cus_htab
== NULL
)
11130 cus_htab
= allocate_dwo_unit_table ();
11132 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11133 *dwo_unit
= read_unit
;
11134 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11135 gdb_assert (slot
!= NULL
);
11138 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11139 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11141 complaint (_("debug cu entry at offset %s is duplicate to"
11142 " the entry at offset %s, signature %s"),
11143 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11144 hex_string (dwo_unit
->signature
));
11146 *slot
= (void *)dwo_unit
;
11150 /* DWP file .debug_{cu,tu}_index section format:
11151 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11155 Both index sections have the same format, and serve to map a 64-bit
11156 signature to a set of section numbers. Each section begins with a header,
11157 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11158 indexes, and a pool of 32-bit section numbers. The index sections will be
11159 aligned at 8-byte boundaries in the file.
11161 The index section header consists of:
11163 V, 32 bit version number
11165 N, 32 bit number of compilation units or type units in the index
11166 M, 32 bit number of slots in the hash table
11168 Numbers are recorded using the byte order of the application binary.
11170 The hash table begins at offset 16 in the section, and consists of an array
11171 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11172 order of the application binary). Unused slots in the hash table are 0.
11173 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11175 The parallel table begins immediately after the hash table
11176 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11177 array of 32-bit indexes (using the byte order of the application binary),
11178 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11179 table contains a 32-bit index into the pool of section numbers. For unused
11180 hash table slots, the corresponding entry in the parallel table will be 0.
11182 The pool of section numbers begins immediately following the hash table
11183 (at offset 16 + 12 * M from the beginning of the section). The pool of
11184 section numbers consists of an array of 32-bit words (using the byte order
11185 of the application binary). Each item in the array is indexed starting
11186 from 0. The hash table entry provides the index of the first section
11187 number in the set. Additional section numbers in the set follow, and the
11188 set is terminated by a 0 entry (section number 0 is not used in ELF).
11190 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11191 section must be the first entry in the set, and the .debug_abbrev.dwo must
11192 be the second entry. Other members of the set may follow in any order.
11198 DWP Version 2 combines all the .debug_info, etc. sections into one,
11199 and the entries in the index tables are now offsets into these sections.
11200 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11203 Index Section Contents:
11205 Hash Table of Signatures dwp_hash_table.hash_table
11206 Parallel Table of Indices dwp_hash_table.unit_table
11207 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11208 Table of Section Sizes dwp_hash_table.v2.sizes
11210 The index section header consists of:
11212 V, 32 bit version number
11213 L, 32 bit number of columns in the table of section offsets
11214 N, 32 bit number of compilation units or type units in the index
11215 M, 32 bit number of slots in the hash table
11217 Numbers are recorded using the byte order of the application binary.
11219 The hash table has the same format as version 1.
11220 The parallel table of indices has the same format as version 1,
11221 except that the entries are origin-1 indices into the table of sections
11222 offsets and the table of section sizes.
11224 The table of offsets begins immediately following the parallel table
11225 (at offset 16 + 12 * M from the beginning of the section). The table is
11226 a two-dimensional array of 32-bit words (using the byte order of the
11227 application binary), with L columns and N+1 rows, in row-major order.
11228 Each row in the array is indexed starting from 0. The first row provides
11229 a key to the remaining rows: each column in this row provides an identifier
11230 for a debug section, and the offsets in the same column of subsequent rows
11231 refer to that section. The section identifiers are:
11233 DW_SECT_INFO 1 .debug_info.dwo
11234 DW_SECT_TYPES 2 .debug_types.dwo
11235 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11236 DW_SECT_LINE 4 .debug_line.dwo
11237 DW_SECT_LOC 5 .debug_loc.dwo
11238 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11239 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11240 DW_SECT_MACRO 8 .debug_macro.dwo
11242 The offsets provided by the CU and TU index sections are the base offsets
11243 for the contributions made by each CU or TU to the corresponding section
11244 in the package file. Each CU and TU header contains an abbrev_offset
11245 field, used to find the abbreviations table for that CU or TU within the
11246 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11247 be interpreted as relative to the base offset given in the index section.
11248 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11249 should be interpreted as relative to the base offset for .debug_line.dwo,
11250 and offsets into other debug sections obtained from DWARF attributes should
11251 also be interpreted as relative to the corresponding base offset.
11253 The table of sizes begins immediately following the table of offsets.
11254 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11255 with L columns and N rows, in row-major order. Each row in the array is
11256 indexed starting from 1 (row 0 is shared by the two tables).
11260 Hash table lookup is handled the same in version 1 and 2:
11262 We assume that N and M will not exceed 2^32 - 1.
11263 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11265 Given a 64-bit compilation unit signature or a type signature S, an entry
11266 in the hash table is located as follows:
11268 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11269 the low-order k bits all set to 1.
11271 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11273 3) If the hash table entry at index H matches the signature, use that
11274 entry. If the hash table entry at index H is unused (all zeroes),
11275 terminate the search: the signature is not present in the table.
11277 4) Let H = (H + H') modulo M. Repeat at Step 3.
11279 Because M > N and H' and M are relatively prime, the search is guaranteed
11280 to stop at an unused slot or find the match. */
11282 /* Create a hash table to map DWO IDs to their CU/TU entry in
11283 .debug_{info,types}.dwo in DWP_FILE.
11284 Returns NULL if there isn't one.
11285 Note: This function processes DWP files only, not DWO files. */
11287 static struct dwp_hash_table
*
11288 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11289 struct dwp_file
*dwp_file
, int is_debug_types
)
11291 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11292 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11293 const gdb_byte
*index_ptr
, *index_end
;
11294 struct dwarf2_section_info
*index
;
11295 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11296 struct dwp_hash_table
*htab
;
11298 if (is_debug_types
)
11299 index
= &dwp_file
->sections
.tu_index
;
11301 index
= &dwp_file
->sections
.cu_index
;
11303 if (index
->empty ())
11305 index
->read (objfile
);
11307 index_ptr
= index
->buffer
;
11308 index_end
= index_ptr
+ index
->size
;
11310 version
= read_4_bytes (dbfd
, index_ptr
);
11313 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11317 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11319 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11322 if (version
!= 1 && version
!= 2)
11324 error (_("Dwarf Error: unsupported DWP file version (%s)"
11325 " [in module %s]"),
11326 pulongest (version
), dwp_file
->name
);
11328 if (nr_slots
!= (nr_slots
& -nr_slots
))
11330 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11331 " is not power of 2 [in module %s]"),
11332 pulongest (nr_slots
), dwp_file
->name
);
11335 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11336 htab
->version
= version
;
11337 htab
->nr_columns
= nr_columns
;
11338 htab
->nr_units
= nr_units
;
11339 htab
->nr_slots
= nr_slots
;
11340 htab
->hash_table
= index_ptr
;
11341 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11343 /* Exit early if the table is empty. */
11344 if (nr_slots
== 0 || nr_units
== 0
11345 || (version
== 2 && nr_columns
== 0))
11347 /* All must be zero. */
11348 if (nr_slots
!= 0 || nr_units
!= 0
11349 || (version
== 2 && nr_columns
!= 0))
11351 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11352 " all zero [in modules %s]"),
11360 htab
->section_pool
.v1
.indices
=
11361 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11362 /* It's harder to decide whether the section is too small in v1.
11363 V1 is deprecated anyway so we punt. */
11367 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11368 int *ids
= htab
->section_pool
.v2
.section_ids
;
11369 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11370 /* Reverse map for error checking. */
11371 int ids_seen
[DW_SECT_MAX
+ 1];
11374 if (nr_columns
< 2)
11376 error (_("Dwarf Error: bad DWP hash table, too few columns"
11377 " in section table [in module %s]"),
11380 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11382 error (_("Dwarf Error: bad DWP hash table, too many columns"
11383 " in section table [in module %s]"),
11386 memset (ids
, 255, sizeof_ids
);
11387 memset (ids_seen
, 255, sizeof (ids_seen
));
11388 for (i
= 0; i
< nr_columns
; ++i
)
11390 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11392 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11394 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11395 " in section table [in module %s]"),
11396 id
, dwp_file
->name
);
11398 if (ids_seen
[id
] != -1)
11400 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11401 " id %d in section table [in module %s]"),
11402 id
, dwp_file
->name
);
11407 /* Must have exactly one info or types section. */
11408 if (((ids_seen
[DW_SECT_INFO
] != -1)
11409 + (ids_seen
[DW_SECT_TYPES
] != -1))
11412 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11413 " DWO info/types section [in module %s]"),
11416 /* Must have an abbrev section. */
11417 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11419 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11420 " section [in module %s]"),
11423 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11424 htab
->section_pool
.v2
.sizes
=
11425 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11426 * nr_units
* nr_columns
);
11427 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11428 * nr_units
* nr_columns
))
11431 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11432 " [in module %s]"),
11440 /* Update SECTIONS with the data from SECTP.
11442 This function is like the other "locate" section routines that are
11443 passed to bfd_map_over_sections, but in this context the sections to
11444 read comes from the DWP V1 hash table, not the full ELF section table.
11446 The result is non-zero for success, or zero if an error was found. */
11449 locate_v1_virtual_dwo_sections (asection
*sectp
,
11450 struct virtual_v1_dwo_sections
*sections
)
11452 const struct dwop_section_names
*names
= &dwop_section_names
;
11454 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11456 /* There can be only one. */
11457 if (sections
->abbrev
.s
.section
!= NULL
)
11459 sections
->abbrev
.s
.section
= sectp
;
11460 sections
->abbrev
.size
= bfd_section_size (sectp
);
11462 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11463 || section_is_p (sectp
->name
, &names
->types_dwo
))
11465 /* There can be only one. */
11466 if (sections
->info_or_types
.s
.section
!= NULL
)
11468 sections
->info_or_types
.s
.section
= sectp
;
11469 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11471 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11473 /* There can be only one. */
11474 if (sections
->line
.s
.section
!= NULL
)
11476 sections
->line
.s
.section
= sectp
;
11477 sections
->line
.size
= bfd_section_size (sectp
);
11479 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11481 /* There can be only one. */
11482 if (sections
->loc
.s
.section
!= NULL
)
11484 sections
->loc
.s
.section
= sectp
;
11485 sections
->loc
.size
= bfd_section_size (sectp
);
11487 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11489 /* There can be only one. */
11490 if (sections
->macinfo
.s
.section
!= NULL
)
11492 sections
->macinfo
.s
.section
= sectp
;
11493 sections
->macinfo
.size
= bfd_section_size (sectp
);
11495 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11497 /* There can be only one. */
11498 if (sections
->macro
.s
.section
!= NULL
)
11500 sections
->macro
.s
.section
= sectp
;
11501 sections
->macro
.size
= bfd_section_size (sectp
);
11503 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11505 /* There can be only one. */
11506 if (sections
->str_offsets
.s
.section
!= NULL
)
11508 sections
->str_offsets
.s
.section
= sectp
;
11509 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11513 /* No other kind of section is valid. */
11520 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11521 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11522 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11523 This is for DWP version 1 files. */
11525 static struct dwo_unit
*
11526 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11527 struct dwp_file
*dwp_file
,
11528 uint32_t unit_index
,
11529 const char *comp_dir
,
11530 ULONGEST signature
, int is_debug_types
)
11532 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11533 const struct dwp_hash_table
*dwp_htab
=
11534 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11535 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11536 const char *kind
= is_debug_types
? "TU" : "CU";
11537 struct dwo_file
*dwo_file
;
11538 struct dwo_unit
*dwo_unit
;
11539 struct virtual_v1_dwo_sections sections
;
11540 void **dwo_file_slot
;
11543 gdb_assert (dwp_file
->version
== 1);
11545 if (dwarf_read_debug
)
11547 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11549 pulongest (unit_index
), hex_string (signature
),
11553 /* Fetch the sections of this DWO unit.
11554 Put a limit on the number of sections we look for so that bad data
11555 doesn't cause us to loop forever. */
11557 #define MAX_NR_V1_DWO_SECTIONS \
11558 (1 /* .debug_info or .debug_types */ \
11559 + 1 /* .debug_abbrev */ \
11560 + 1 /* .debug_line */ \
11561 + 1 /* .debug_loc */ \
11562 + 1 /* .debug_str_offsets */ \
11563 + 1 /* .debug_macro or .debug_macinfo */ \
11564 + 1 /* trailing zero */)
11566 memset (§ions
, 0, sizeof (sections
));
11568 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11571 uint32_t section_nr
=
11572 read_4_bytes (dbfd
,
11573 dwp_htab
->section_pool
.v1
.indices
11574 + (unit_index
+ i
) * sizeof (uint32_t));
11576 if (section_nr
== 0)
11578 if (section_nr
>= dwp_file
->num_sections
)
11580 error (_("Dwarf Error: bad DWP hash table, section number too large"
11581 " [in module %s]"),
11585 sectp
= dwp_file
->elf_sections
[section_nr
];
11586 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11588 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11589 " [in module %s]"),
11595 || sections
.info_or_types
.empty ()
11596 || sections
.abbrev
.empty ())
11598 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11599 " [in module %s]"),
11602 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11604 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11605 " [in module %s]"),
11609 /* It's easier for the rest of the code if we fake a struct dwo_file and
11610 have dwo_unit "live" in that. At least for now.
11612 The DWP file can be made up of a random collection of CUs and TUs.
11613 However, for each CU + set of TUs that came from the same original DWO
11614 file, we can combine them back into a virtual DWO file to save space
11615 (fewer struct dwo_file objects to allocate). Remember that for really
11616 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11618 std::string virtual_dwo_name
=
11619 string_printf ("virtual-dwo/%d-%d-%d-%d",
11620 sections
.abbrev
.get_id (),
11621 sections
.line
.get_id (),
11622 sections
.loc
.get_id (),
11623 sections
.str_offsets
.get_id ());
11624 /* Can we use an existing virtual DWO file? */
11625 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11626 virtual_dwo_name
.c_str (),
11628 /* Create one if necessary. */
11629 if (*dwo_file_slot
== NULL
)
11631 if (dwarf_read_debug
)
11633 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11634 virtual_dwo_name
.c_str ());
11636 dwo_file
= new struct dwo_file
;
11637 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11638 dwo_file
->comp_dir
= comp_dir
;
11639 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11640 dwo_file
->sections
.line
= sections
.line
;
11641 dwo_file
->sections
.loc
= sections
.loc
;
11642 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11643 dwo_file
->sections
.macro
= sections
.macro
;
11644 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11645 /* The "str" section is global to the entire DWP file. */
11646 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11647 /* The info or types section is assigned below to dwo_unit,
11648 there's no need to record it in dwo_file.
11649 Also, we can't simply record type sections in dwo_file because
11650 we record a pointer into the vector in dwo_unit. As we collect more
11651 types we'll grow the vector and eventually have to reallocate space
11652 for it, invalidating all copies of pointers into the previous
11654 *dwo_file_slot
= dwo_file
;
11658 if (dwarf_read_debug
)
11660 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11661 virtual_dwo_name
.c_str ());
11663 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11666 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11667 dwo_unit
->dwo_file
= dwo_file
;
11668 dwo_unit
->signature
= signature
;
11669 dwo_unit
->section
=
11670 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11671 *dwo_unit
->section
= sections
.info_or_types
;
11672 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11677 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11678 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11679 piece within that section used by a TU/CU, return a virtual section
11680 of just that piece. */
11682 static struct dwarf2_section_info
11683 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11684 struct dwarf2_section_info
*section
,
11685 bfd_size_type offset
, bfd_size_type size
)
11687 struct dwarf2_section_info result
;
11690 gdb_assert (section
!= NULL
);
11691 gdb_assert (!section
->is_virtual
);
11693 memset (&result
, 0, sizeof (result
));
11694 result
.s
.containing_section
= section
;
11695 result
.is_virtual
= true;
11700 sectp
= section
->get_bfd_section ();
11702 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11703 bounds of the real section. This is a pretty-rare event, so just
11704 flag an error (easier) instead of a warning and trying to cope. */
11706 || offset
+ size
> bfd_section_size (sectp
))
11708 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11709 " in section %s [in module %s]"),
11710 sectp
? bfd_section_name (sectp
) : "<unknown>",
11711 objfile_name (dwarf2_per_objfile
->objfile
));
11714 result
.virtual_offset
= offset
;
11715 result
.size
= size
;
11719 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11720 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11721 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11722 This is for DWP version 2 files. */
11724 static struct dwo_unit
*
11725 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11726 struct dwp_file
*dwp_file
,
11727 uint32_t unit_index
,
11728 const char *comp_dir
,
11729 ULONGEST signature
, int is_debug_types
)
11731 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11732 const struct dwp_hash_table
*dwp_htab
=
11733 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11734 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11735 const char *kind
= is_debug_types
? "TU" : "CU";
11736 struct dwo_file
*dwo_file
;
11737 struct dwo_unit
*dwo_unit
;
11738 struct virtual_v2_dwo_sections sections
;
11739 void **dwo_file_slot
;
11742 gdb_assert (dwp_file
->version
== 2);
11744 if (dwarf_read_debug
)
11746 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11748 pulongest (unit_index
), hex_string (signature
),
11752 /* Fetch the section offsets of this DWO unit. */
11754 memset (§ions
, 0, sizeof (sections
));
11756 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11758 uint32_t offset
= read_4_bytes (dbfd
,
11759 dwp_htab
->section_pool
.v2
.offsets
11760 + (((unit_index
- 1) * dwp_htab
->nr_columns
11762 * sizeof (uint32_t)));
11763 uint32_t size
= read_4_bytes (dbfd
,
11764 dwp_htab
->section_pool
.v2
.sizes
11765 + (((unit_index
- 1) * dwp_htab
->nr_columns
11767 * sizeof (uint32_t)));
11769 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11772 case DW_SECT_TYPES
:
11773 sections
.info_or_types_offset
= offset
;
11774 sections
.info_or_types_size
= size
;
11776 case DW_SECT_ABBREV
:
11777 sections
.abbrev_offset
= offset
;
11778 sections
.abbrev_size
= size
;
11781 sections
.line_offset
= offset
;
11782 sections
.line_size
= size
;
11785 sections
.loc_offset
= offset
;
11786 sections
.loc_size
= size
;
11788 case DW_SECT_STR_OFFSETS
:
11789 sections
.str_offsets_offset
= offset
;
11790 sections
.str_offsets_size
= size
;
11792 case DW_SECT_MACINFO
:
11793 sections
.macinfo_offset
= offset
;
11794 sections
.macinfo_size
= size
;
11796 case DW_SECT_MACRO
:
11797 sections
.macro_offset
= offset
;
11798 sections
.macro_size
= size
;
11803 /* It's easier for the rest of the code if we fake a struct dwo_file and
11804 have dwo_unit "live" in that. At least for now.
11806 The DWP file can be made up of a random collection of CUs and TUs.
11807 However, for each CU + set of TUs that came from the same original DWO
11808 file, we can combine them back into a virtual DWO file to save space
11809 (fewer struct dwo_file objects to allocate). Remember that for really
11810 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11812 std::string virtual_dwo_name
=
11813 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11814 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11815 (long) (sections
.line_size
? sections
.line_offset
: 0),
11816 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11817 (long) (sections
.str_offsets_size
11818 ? sections
.str_offsets_offset
: 0));
11819 /* Can we use an existing virtual DWO file? */
11820 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11821 virtual_dwo_name
.c_str (),
11823 /* Create one if necessary. */
11824 if (*dwo_file_slot
== NULL
)
11826 if (dwarf_read_debug
)
11828 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11829 virtual_dwo_name
.c_str ());
11831 dwo_file
= new struct dwo_file
;
11832 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11833 dwo_file
->comp_dir
= comp_dir
;
11834 dwo_file
->sections
.abbrev
=
11835 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11836 sections
.abbrev_offset
, sections
.abbrev_size
);
11837 dwo_file
->sections
.line
=
11838 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11839 sections
.line_offset
, sections
.line_size
);
11840 dwo_file
->sections
.loc
=
11841 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11842 sections
.loc_offset
, sections
.loc_size
);
11843 dwo_file
->sections
.macinfo
=
11844 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11845 sections
.macinfo_offset
, sections
.macinfo_size
);
11846 dwo_file
->sections
.macro
=
11847 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11848 sections
.macro_offset
, sections
.macro_size
);
11849 dwo_file
->sections
.str_offsets
=
11850 create_dwp_v2_section (dwarf2_per_objfile
,
11851 &dwp_file
->sections
.str_offsets
,
11852 sections
.str_offsets_offset
,
11853 sections
.str_offsets_size
);
11854 /* The "str" section is global to the entire DWP file. */
11855 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11856 /* The info or types section is assigned below to dwo_unit,
11857 there's no need to record it in dwo_file.
11858 Also, we can't simply record type sections in dwo_file because
11859 we record a pointer into the vector in dwo_unit. As we collect more
11860 types we'll grow the vector and eventually have to reallocate space
11861 for it, invalidating all copies of pointers into the previous
11863 *dwo_file_slot
= dwo_file
;
11867 if (dwarf_read_debug
)
11869 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11870 virtual_dwo_name
.c_str ());
11872 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11875 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11876 dwo_unit
->dwo_file
= dwo_file
;
11877 dwo_unit
->signature
= signature
;
11878 dwo_unit
->section
=
11879 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11880 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11882 ? &dwp_file
->sections
.types
11883 : &dwp_file
->sections
.info
,
11884 sections
.info_or_types_offset
,
11885 sections
.info_or_types_size
);
11886 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11891 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11892 Returns NULL if the signature isn't found. */
11894 static struct dwo_unit
*
11895 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11896 struct dwp_file
*dwp_file
, const char *comp_dir
,
11897 ULONGEST signature
, int is_debug_types
)
11899 const struct dwp_hash_table
*dwp_htab
=
11900 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11901 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11902 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11903 uint32_t hash
= signature
& mask
;
11904 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11907 struct dwo_unit find_dwo_cu
;
11909 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11910 find_dwo_cu
.signature
= signature
;
11911 slot
= htab_find_slot (is_debug_types
11912 ? dwp_file
->loaded_tus
.get ()
11913 : dwp_file
->loaded_cus
.get (),
11914 &find_dwo_cu
, INSERT
);
11917 return (struct dwo_unit
*) *slot
;
11919 /* Use a for loop so that we don't loop forever on bad debug info. */
11920 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11922 ULONGEST signature_in_table
;
11924 signature_in_table
=
11925 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11926 if (signature_in_table
== signature
)
11928 uint32_t unit_index
=
11929 read_4_bytes (dbfd
,
11930 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11932 if (dwp_file
->version
== 1)
11934 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11935 dwp_file
, unit_index
,
11936 comp_dir
, signature
,
11941 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11942 dwp_file
, unit_index
,
11943 comp_dir
, signature
,
11946 return (struct dwo_unit
*) *slot
;
11948 if (signature_in_table
== 0)
11950 hash
= (hash
+ hash2
) & mask
;
11953 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11954 " [in module %s]"),
11958 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11959 Open the file specified by FILE_NAME and hand it off to BFD for
11960 preliminary analysis. Return a newly initialized bfd *, which
11961 includes a canonicalized copy of FILE_NAME.
11962 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11963 SEARCH_CWD is true if the current directory is to be searched.
11964 It will be searched before debug-file-directory.
11965 If successful, the file is added to the bfd include table of the
11966 objfile's bfd (see gdb_bfd_record_inclusion).
11967 If unable to find/open the file, return NULL.
11968 NOTE: This function is derived from symfile_bfd_open. */
11970 static gdb_bfd_ref_ptr
11971 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11972 const char *file_name
, int is_dwp
, int search_cwd
)
11975 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11976 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11977 to debug_file_directory. */
11978 const char *search_path
;
11979 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11981 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
11984 if (*debug_file_directory
!= '\0')
11986 search_path_holder
.reset (concat (".", dirname_separator_string
,
11987 debug_file_directory
,
11989 search_path
= search_path_holder
.get ();
11995 search_path
= debug_file_directory
;
11997 openp_flags flags
= OPF_RETURN_REALPATH
;
11999 flags
|= OPF_SEARCH_IN_PATH
;
12001 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12002 desc
= openp (search_path
, flags
, file_name
,
12003 O_RDONLY
| O_BINARY
, &absolute_name
);
12007 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12009 if (sym_bfd
== NULL
)
12011 bfd_set_cacheable (sym_bfd
.get (), 1);
12013 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12016 /* Success. Record the bfd as having been included by the objfile's bfd.
12017 This is important because things like demangled_names_hash lives in the
12018 objfile's per_bfd space and may have references to things like symbol
12019 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12020 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12025 /* Try to open DWO file FILE_NAME.
12026 COMP_DIR is the DW_AT_comp_dir attribute.
12027 The result is the bfd handle of the file.
12028 If there is a problem finding or opening the file, return NULL.
12029 Upon success, the canonicalized path of the file is stored in the bfd,
12030 same as symfile_bfd_open. */
12032 static gdb_bfd_ref_ptr
12033 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12034 const char *file_name
, const char *comp_dir
)
12036 if (IS_ABSOLUTE_PATH (file_name
))
12037 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12038 0 /*is_dwp*/, 0 /*search_cwd*/);
12040 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12042 if (comp_dir
!= NULL
)
12044 gdb::unique_xmalloc_ptr
<char> path_to_try
12045 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12047 /* NOTE: If comp_dir is a relative path, this will also try the
12048 search path, which seems useful. */
12049 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12050 path_to_try
.get (),
12052 1 /*search_cwd*/));
12057 /* That didn't work, try debug-file-directory, which, despite its name,
12058 is a list of paths. */
12060 if (*debug_file_directory
== '\0')
12063 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12064 0 /*is_dwp*/, 1 /*search_cwd*/);
12067 /* This function is mapped across the sections and remembers the offset and
12068 size of each of the DWO debugging sections we are interested in. */
12071 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12073 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12074 const struct dwop_section_names
*names
= &dwop_section_names
;
12076 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12078 dwo_sections
->abbrev
.s
.section
= sectp
;
12079 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12081 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12083 dwo_sections
->info
.s
.section
= sectp
;
12084 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12086 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12088 dwo_sections
->line
.s
.section
= sectp
;
12089 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12091 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12093 dwo_sections
->loc
.s
.section
= sectp
;
12094 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12096 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12098 dwo_sections
->loclists
.s
.section
= sectp
;
12099 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12101 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12103 dwo_sections
->macinfo
.s
.section
= sectp
;
12104 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12106 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12108 dwo_sections
->macro
.s
.section
= sectp
;
12109 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12111 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12113 dwo_sections
->str
.s
.section
= sectp
;
12114 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12116 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12118 dwo_sections
->str_offsets
.s
.section
= sectp
;
12119 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12121 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12123 struct dwarf2_section_info type_section
;
12125 memset (&type_section
, 0, sizeof (type_section
));
12126 type_section
.s
.section
= sectp
;
12127 type_section
.size
= bfd_section_size (sectp
);
12128 dwo_sections
->types
.push_back (type_section
);
12132 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12133 by PER_CU. This is for the non-DWP case.
12134 The result is NULL if DWO_NAME can't be found. */
12136 static struct dwo_file
*
12137 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12138 const char *dwo_name
, const char *comp_dir
)
12140 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12142 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12145 if (dwarf_read_debug
)
12146 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12150 dwo_file_up
dwo_file (new struct dwo_file
);
12151 dwo_file
->dwo_name
= dwo_name
;
12152 dwo_file
->comp_dir
= comp_dir
;
12153 dwo_file
->dbfd
= std::move (dbfd
);
12155 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12156 &dwo_file
->sections
);
12158 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12159 dwo_file
->sections
.info
, dwo_file
->cus
);
12161 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12162 dwo_file
->sections
.types
, dwo_file
->tus
);
12164 if (dwarf_read_debug
)
12165 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12167 return dwo_file
.release ();
12170 /* This function is mapped across the sections and remembers the offset and
12171 size of each of the DWP debugging sections common to version 1 and 2 that
12172 we are interested in. */
12175 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12176 void *dwp_file_ptr
)
12178 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12179 const struct dwop_section_names
*names
= &dwop_section_names
;
12180 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12182 /* Record the ELF section number for later lookup: this is what the
12183 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12184 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12185 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12187 /* Look for specific sections that we need. */
12188 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12190 dwp_file
->sections
.str
.s
.section
= sectp
;
12191 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12193 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12195 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12196 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12198 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12200 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12201 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12205 /* This function is mapped across the sections and remembers the offset and
12206 size of each of the DWP version 2 debugging sections that we are interested
12207 in. This is split into a separate function because we don't know if we
12208 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12211 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12213 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12214 const struct dwop_section_names
*names
= &dwop_section_names
;
12215 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12217 /* Record the ELF section number for later lookup: this is what the
12218 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12219 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12220 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12222 /* Look for specific sections that we need. */
12223 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12225 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12226 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12228 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12230 dwp_file
->sections
.info
.s
.section
= sectp
;
12231 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12233 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12235 dwp_file
->sections
.line
.s
.section
= sectp
;
12236 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12238 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12240 dwp_file
->sections
.loc
.s
.section
= sectp
;
12241 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12243 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12245 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12246 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12248 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12250 dwp_file
->sections
.macro
.s
.section
= sectp
;
12251 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12253 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12255 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12256 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12258 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12260 dwp_file
->sections
.types
.s
.section
= sectp
;
12261 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12265 /* Hash function for dwp_file loaded CUs/TUs. */
12268 hash_dwp_loaded_cutus (const void *item
)
12270 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12272 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12273 return dwo_unit
->signature
;
12276 /* Equality function for dwp_file loaded CUs/TUs. */
12279 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12281 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12282 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12284 return dua
->signature
== dub
->signature
;
12287 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12290 allocate_dwp_loaded_cutus_table ()
12292 return htab_up (htab_create_alloc (3,
12293 hash_dwp_loaded_cutus
,
12294 eq_dwp_loaded_cutus
,
12295 NULL
, xcalloc
, xfree
));
12298 /* Try to open DWP file FILE_NAME.
12299 The result is the bfd handle of the file.
12300 If there is a problem finding or opening the file, return NULL.
12301 Upon success, the canonicalized path of the file is stored in the bfd,
12302 same as symfile_bfd_open. */
12304 static gdb_bfd_ref_ptr
12305 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12306 const char *file_name
)
12308 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12310 1 /*search_cwd*/));
12314 /* Work around upstream bug 15652.
12315 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12316 [Whether that's a "bug" is debatable, but it is getting in our way.]
12317 We have no real idea where the dwp file is, because gdb's realpath-ing
12318 of the executable's path may have discarded the needed info.
12319 [IWBN if the dwp file name was recorded in the executable, akin to
12320 .gnu_debuglink, but that doesn't exist yet.]
12321 Strip the directory from FILE_NAME and search again. */
12322 if (*debug_file_directory
!= '\0')
12324 /* Don't implicitly search the current directory here.
12325 If the user wants to search "." to handle this case,
12326 it must be added to debug-file-directory. */
12327 return try_open_dwop_file (dwarf2_per_objfile
,
12328 lbasename (file_name
), 1 /*is_dwp*/,
12335 /* Initialize the use of the DWP file for the current objfile.
12336 By convention the name of the DWP file is ${objfile}.dwp.
12337 The result is NULL if it can't be found. */
12339 static std::unique_ptr
<struct dwp_file
>
12340 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12342 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12344 /* Try to find first .dwp for the binary file before any symbolic links
12347 /* If the objfile is a debug file, find the name of the real binary
12348 file and get the name of dwp file from there. */
12349 std::string dwp_name
;
12350 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12352 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12353 const char *backlink_basename
= lbasename (backlink
->original_name
);
12355 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12358 dwp_name
= objfile
->original_name
;
12360 dwp_name
+= ".dwp";
12362 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12364 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12366 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12367 dwp_name
= objfile_name (objfile
);
12368 dwp_name
+= ".dwp";
12369 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12374 if (dwarf_read_debug
)
12375 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12376 return std::unique_ptr
<dwp_file
> ();
12379 const char *name
= bfd_get_filename (dbfd
.get ());
12380 std::unique_ptr
<struct dwp_file
> dwp_file
12381 (new struct dwp_file (name
, std::move (dbfd
)));
12383 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12384 dwp_file
->elf_sections
=
12385 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12386 dwp_file
->num_sections
, asection
*);
12388 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12389 dwarf2_locate_common_dwp_sections
,
12392 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12395 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12398 /* The DWP file version is stored in the hash table. Oh well. */
12399 if (dwp_file
->cus
&& dwp_file
->tus
12400 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12402 /* Technically speaking, we should try to limp along, but this is
12403 pretty bizarre. We use pulongest here because that's the established
12404 portability solution (e.g, we cannot use %u for uint32_t). */
12405 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12406 " TU version %s [in DWP file %s]"),
12407 pulongest (dwp_file
->cus
->version
),
12408 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12412 dwp_file
->version
= dwp_file
->cus
->version
;
12413 else if (dwp_file
->tus
)
12414 dwp_file
->version
= dwp_file
->tus
->version
;
12416 dwp_file
->version
= 2;
12418 if (dwp_file
->version
== 2)
12419 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12420 dwarf2_locate_v2_dwp_sections
,
12423 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12424 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12426 if (dwarf_read_debug
)
12428 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12429 fprintf_unfiltered (gdb_stdlog
,
12430 " %s CUs, %s TUs\n",
12431 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12432 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12438 /* Wrapper around open_and_init_dwp_file, only open it once. */
12440 static struct dwp_file
*
12441 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12443 if (! dwarf2_per_objfile
->dwp_checked
)
12445 dwarf2_per_objfile
->dwp_file
12446 = open_and_init_dwp_file (dwarf2_per_objfile
);
12447 dwarf2_per_objfile
->dwp_checked
= 1;
12449 return dwarf2_per_objfile
->dwp_file
.get ();
12452 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12453 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12454 or in the DWP file for the objfile, referenced by THIS_UNIT.
12455 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12456 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12458 This is called, for example, when wanting to read a variable with a
12459 complex location. Therefore we don't want to do file i/o for every call.
12460 Therefore we don't want to look for a DWO file on every call.
12461 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12462 then we check if we've already seen DWO_NAME, and only THEN do we check
12465 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12466 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12468 static struct dwo_unit
*
12469 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12470 const char *dwo_name
, const char *comp_dir
,
12471 ULONGEST signature
, int is_debug_types
)
12473 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12474 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12475 const char *kind
= is_debug_types
? "TU" : "CU";
12476 void **dwo_file_slot
;
12477 struct dwo_file
*dwo_file
;
12478 struct dwp_file
*dwp_file
;
12480 /* First see if there's a DWP file.
12481 If we have a DWP file but didn't find the DWO inside it, don't
12482 look for the original DWO file. It makes gdb behave differently
12483 depending on whether one is debugging in the build tree. */
12485 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12486 if (dwp_file
!= NULL
)
12488 const struct dwp_hash_table
*dwp_htab
=
12489 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12491 if (dwp_htab
!= NULL
)
12493 struct dwo_unit
*dwo_cutu
=
12494 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12495 signature
, is_debug_types
);
12497 if (dwo_cutu
!= NULL
)
12499 if (dwarf_read_debug
)
12501 fprintf_unfiltered (gdb_stdlog
,
12502 "Virtual DWO %s %s found: @%s\n",
12503 kind
, hex_string (signature
),
12504 host_address_to_string (dwo_cutu
));
12512 /* No DWP file, look for the DWO file. */
12514 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12515 dwo_name
, comp_dir
);
12516 if (*dwo_file_slot
== NULL
)
12518 /* Read in the file and build a table of the CUs/TUs it contains. */
12519 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12521 /* NOTE: This will be NULL if unable to open the file. */
12522 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12524 if (dwo_file
!= NULL
)
12526 struct dwo_unit
*dwo_cutu
= NULL
;
12528 if (is_debug_types
&& dwo_file
->tus
)
12530 struct dwo_unit find_dwo_cutu
;
12532 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12533 find_dwo_cutu
.signature
= signature
;
12535 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12538 else if (!is_debug_types
&& dwo_file
->cus
)
12540 struct dwo_unit find_dwo_cutu
;
12542 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12543 find_dwo_cutu
.signature
= signature
;
12544 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12548 if (dwo_cutu
!= NULL
)
12550 if (dwarf_read_debug
)
12552 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12553 kind
, dwo_name
, hex_string (signature
),
12554 host_address_to_string (dwo_cutu
));
12561 /* We didn't find it. This could mean a dwo_id mismatch, or
12562 someone deleted the DWO/DWP file, or the search path isn't set up
12563 correctly to find the file. */
12565 if (dwarf_read_debug
)
12567 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12568 kind
, dwo_name
, hex_string (signature
));
12571 /* This is a warning and not a complaint because it can be caused by
12572 pilot error (e.g., user accidentally deleting the DWO). */
12574 /* Print the name of the DWP file if we looked there, helps the user
12575 better diagnose the problem. */
12576 std::string dwp_text
;
12578 if (dwp_file
!= NULL
)
12579 dwp_text
= string_printf (" [in DWP file %s]",
12580 lbasename (dwp_file
->name
));
12582 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12583 " [in module %s]"),
12584 kind
, dwo_name
, hex_string (signature
),
12586 this_unit
->is_debug_types
? "TU" : "CU",
12587 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12592 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12593 See lookup_dwo_cutu_unit for details. */
12595 static struct dwo_unit
*
12596 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12597 const char *dwo_name
, const char *comp_dir
,
12598 ULONGEST signature
)
12600 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12603 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12604 See lookup_dwo_cutu_unit for details. */
12606 static struct dwo_unit
*
12607 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12608 const char *dwo_name
, const char *comp_dir
)
12610 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12613 /* Traversal function for queue_and_load_all_dwo_tus. */
12616 queue_and_load_dwo_tu (void **slot
, void *info
)
12618 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12619 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12620 ULONGEST signature
= dwo_unit
->signature
;
12621 struct signatured_type
*sig_type
=
12622 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12624 if (sig_type
!= NULL
)
12626 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12628 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12629 a real dependency of PER_CU on SIG_TYPE. That is detected later
12630 while processing PER_CU. */
12631 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12632 load_full_type_unit (sig_cu
);
12633 per_cu
->imported_symtabs_push (sig_cu
);
12639 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12640 The DWO may have the only definition of the type, though it may not be
12641 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12642 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12645 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12647 struct dwo_unit
*dwo_unit
;
12648 struct dwo_file
*dwo_file
;
12650 gdb_assert (!per_cu
->is_debug_types
);
12651 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12652 gdb_assert (per_cu
->cu
!= NULL
);
12654 dwo_unit
= per_cu
->cu
->dwo_unit
;
12655 gdb_assert (dwo_unit
!= NULL
);
12657 dwo_file
= dwo_unit
->dwo_file
;
12658 if (dwo_file
->tus
!= NULL
)
12659 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12663 /* Read in various DIEs. */
12665 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12666 Inherit only the children of the DW_AT_abstract_origin DIE not being
12667 already referenced by DW_AT_abstract_origin from the children of the
12671 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12673 struct die_info
*child_die
;
12674 sect_offset
*offsetp
;
12675 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12676 struct die_info
*origin_die
;
12677 /* Iterator of the ORIGIN_DIE children. */
12678 struct die_info
*origin_child_die
;
12679 struct attribute
*attr
;
12680 struct dwarf2_cu
*origin_cu
;
12681 struct pending
**origin_previous_list_in_scope
;
12683 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12687 /* Note that following die references may follow to a die in a
12691 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12693 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12695 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12696 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12698 if (die
->tag
!= origin_die
->tag
12699 && !(die
->tag
== DW_TAG_inlined_subroutine
12700 && origin_die
->tag
== DW_TAG_subprogram
))
12701 complaint (_("DIE %s and its abstract origin %s have different tags"),
12702 sect_offset_str (die
->sect_off
),
12703 sect_offset_str (origin_die
->sect_off
));
12705 std::vector
<sect_offset
> offsets
;
12707 for (child_die
= die
->child
;
12708 child_die
&& child_die
->tag
;
12709 child_die
= child_die
->sibling
)
12711 struct die_info
*child_origin_die
;
12712 struct dwarf2_cu
*child_origin_cu
;
12714 /* We are trying to process concrete instance entries:
12715 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12716 it's not relevant to our analysis here. i.e. detecting DIEs that are
12717 present in the abstract instance but not referenced in the concrete
12719 if (child_die
->tag
== DW_TAG_call_site
12720 || child_die
->tag
== DW_TAG_GNU_call_site
)
12723 /* For each CHILD_DIE, find the corresponding child of
12724 ORIGIN_DIE. If there is more than one layer of
12725 DW_AT_abstract_origin, follow them all; there shouldn't be,
12726 but GCC versions at least through 4.4 generate this (GCC PR
12728 child_origin_die
= child_die
;
12729 child_origin_cu
= cu
;
12732 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12736 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12740 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12741 counterpart may exist. */
12742 if (child_origin_die
!= child_die
)
12744 if (child_die
->tag
!= child_origin_die
->tag
12745 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12746 && child_origin_die
->tag
== DW_TAG_subprogram
))
12747 complaint (_("Child DIE %s and its abstract origin %s have "
12749 sect_offset_str (child_die
->sect_off
),
12750 sect_offset_str (child_origin_die
->sect_off
));
12751 if (child_origin_die
->parent
!= origin_die
)
12752 complaint (_("Child DIE %s and its abstract origin %s have "
12753 "different parents"),
12754 sect_offset_str (child_die
->sect_off
),
12755 sect_offset_str (child_origin_die
->sect_off
));
12757 offsets
.push_back (child_origin_die
->sect_off
);
12760 std::sort (offsets
.begin (), offsets
.end ());
12761 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12762 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12763 if (offsetp
[-1] == *offsetp
)
12764 complaint (_("Multiple children of DIE %s refer "
12765 "to DIE %s as their abstract origin"),
12766 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12768 offsetp
= offsets
.data ();
12769 origin_child_die
= origin_die
->child
;
12770 while (origin_child_die
&& origin_child_die
->tag
)
12772 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12773 while (offsetp
< offsets_end
12774 && *offsetp
< origin_child_die
->sect_off
)
12776 if (offsetp
>= offsets_end
12777 || *offsetp
> origin_child_die
->sect_off
)
12779 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12780 Check whether we're already processing ORIGIN_CHILD_DIE.
12781 This can happen with mutually referenced abstract_origins.
12783 if (!origin_child_die
->in_process
)
12784 process_die (origin_child_die
, origin_cu
);
12786 origin_child_die
= origin_child_die
->sibling
;
12788 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12790 if (cu
!= origin_cu
)
12791 compute_delayed_physnames (origin_cu
);
12795 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12797 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12798 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12799 struct context_stack
*newobj
;
12802 struct die_info
*child_die
;
12803 struct attribute
*attr
, *call_line
, *call_file
;
12805 CORE_ADDR baseaddr
;
12806 struct block
*block
;
12807 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12808 std::vector
<struct symbol
*> template_args
;
12809 struct template_symbol
*templ_func
= NULL
;
12813 /* If we do not have call site information, we can't show the
12814 caller of this inlined function. That's too confusing, so
12815 only use the scope for local variables. */
12816 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12817 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12818 if (call_line
== NULL
|| call_file
== NULL
)
12820 read_lexical_block_scope (die
, cu
);
12825 baseaddr
= objfile
->text_section_offset ();
12827 name
= dwarf2_name (die
, cu
);
12829 /* Ignore functions with missing or empty names. These are actually
12830 illegal according to the DWARF standard. */
12833 complaint (_("missing name for subprogram DIE at %s"),
12834 sect_offset_str (die
->sect_off
));
12838 /* Ignore functions with missing or invalid low and high pc attributes. */
12839 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12840 <= PC_BOUNDS_INVALID
)
12842 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12843 if (!attr
|| !DW_UNSND (attr
))
12844 complaint (_("cannot get low and high bounds "
12845 "for subprogram DIE at %s"),
12846 sect_offset_str (die
->sect_off
));
12850 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12851 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12853 /* If we have any template arguments, then we must allocate a
12854 different sort of symbol. */
12855 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
12857 if (child_die
->tag
== DW_TAG_template_type_param
12858 || child_die
->tag
== DW_TAG_template_value_param
)
12860 templ_func
= allocate_template_symbol (objfile
);
12861 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12866 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12867 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12868 (struct symbol
*) templ_func
);
12870 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12871 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12874 /* If there is a location expression for DW_AT_frame_base, record
12876 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12877 if (attr
!= nullptr)
12878 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12880 /* If there is a location for the static link, record it. */
12881 newobj
->static_link
= NULL
;
12882 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12883 if (attr
!= nullptr)
12885 newobj
->static_link
12886 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12887 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12888 cu
->per_cu
->addr_type ());
12891 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12893 if (die
->child
!= NULL
)
12895 child_die
= die
->child
;
12896 while (child_die
&& child_die
->tag
)
12898 if (child_die
->tag
== DW_TAG_template_type_param
12899 || child_die
->tag
== DW_TAG_template_value_param
)
12901 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12904 template_args
.push_back (arg
);
12907 process_die (child_die
, cu
);
12908 child_die
= child_die
->sibling
;
12912 inherit_abstract_dies (die
, cu
);
12914 /* If we have a DW_AT_specification, we might need to import using
12915 directives from the context of the specification DIE. See the
12916 comment in determine_prefix. */
12917 if (cu
->language
== language_cplus
12918 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12920 struct dwarf2_cu
*spec_cu
= cu
;
12921 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12925 child_die
= spec_die
->child
;
12926 while (child_die
&& child_die
->tag
)
12928 if (child_die
->tag
== DW_TAG_imported_module
)
12929 process_die (child_die
, spec_cu
);
12930 child_die
= child_die
->sibling
;
12933 /* In some cases, GCC generates specification DIEs that
12934 themselves contain DW_AT_specification attributes. */
12935 spec_die
= die_specification (spec_die
, &spec_cu
);
12939 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12940 /* Make a block for the local symbols within. */
12941 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12942 cstk
.static_link
, lowpc
, highpc
);
12944 /* For C++, set the block's scope. */
12945 if ((cu
->language
== language_cplus
12946 || cu
->language
== language_fortran
12947 || cu
->language
== language_d
12948 || cu
->language
== language_rust
)
12949 && cu
->processing_has_namespace_info
)
12950 block_set_scope (block
, determine_prefix (die
, cu
),
12951 &objfile
->objfile_obstack
);
12953 /* If we have address ranges, record them. */
12954 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12956 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12958 /* Attach template arguments to function. */
12959 if (!template_args
.empty ())
12961 gdb_assert (templ_func
!= NULL
);
12963 templ_func
->n_template_arguments
= template_args
.size ();
12964 templ_func
->template_arguments
12965 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12966 templ_func
->n_template_arguments
);
12967 memcpy (templ_func
->template_arguments
,
12968 template_args
.data (),
12969 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12971 /* Make sure that the symtab is set on the new symbols. Even
12972 though they don't appear in this symtab directly, other parts
12973 of gdb assume that symbols do, and this is reasonably
12975 for (symbol
*sym
: template_args
)
12976 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
12979 /* In C++, we can have functions nested inside functions (e.g., when
12980 a function declares a class that has methods). This means that
12981 when we finish processing a function scope, we may need to go
12982 back to building a containing block's symbol lists. */
12983 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12984 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12986 /* If we've finished processing a top-level function, subsequent
12987 symbols go in the file symbol list. */
12988 if (cu
->get_builder ()->outermost_context_p ())
12989 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
12992 /* Process all the DIES contained within a lexical block scope. Start
12993 a new scope, process the dies, and then close the scope. */
12996 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12998 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12999 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13000 CORE_ADDR lowpc
, highpc
;
13001 struct die_info
*child_die
;
13002 CORE_ADDR baseaddr
;
13004 baseaddr
= objfile
->text_section_offset ();
13006 /* Ignore blocks with missing or invalid low and high pc attributes. */
13007 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13008 as multiple lexical blocks? Handling children in a sane way would
13009 be nasty. Might be easier to properly extend generic blocks to
13010 describe ranges. */
13011 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13013 case PC_BOUNDS_NOT_PRESENT
:
13014 /* DW_TAG_lexical_block has no attributes, process its children as if
13015 there was no wrapping by that DW_TAG_lexical_block.
13016 GCC does no longer produces such DWARF since GCC r224161. */
13017 for (child_die
= die
->child
;
13018 child_die
!= NULL
&& child_die
->tag
;
13019 child_die
= child_die
->sibling
)
13020 process_die (child_die
, cu
);
13022 case PC_BOUNDS_INVALID
:
13025 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13026 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13028 cu
->get_builder ()->push_context (0, lowpc
);
13029 if (die
->child
!= NULL
)
13031 child_die
= die
->child
;
13032 while (child_die
&& child_die
->tag
)
13034 process_die (child_die
, cu
);
13035 child_die
= child_die
->sibling
;
13038 inherit_abstract_dies (die
, cu
);
13039 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13041 if (*cu
->get_builder ()->get_local_symbols () != NULL
13042 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13044 struct block
*block
13045 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13046 cstk
.start_addr
, highpc
);
13048 /* Note that recording ranges after traversing children, as we
13049 do here, means that recording a parent's ranges entails
13050 walking across all its children's ranges as they appear in
13051 the address map, which is quadratic behavior.
13053 It would be nicer to record the parent's ranges before
13054 traversing its children, simply overriding whatever you find
13055 there. But since we don't even decide whether to create a
13056 block until after we've traversed its children, that's hard
13058 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13060 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13061 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13064 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13067 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13069 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13070 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13071 CORE_ADDR pc
, baseaddr
;
13072 struct attribute
*attr
;
13073 struct call_site
*call_site
, call_site_local
;
13076 struct die_info
*child_die
;
13078 baseaddr
= objfile
->text_section_offset ();
13080 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13083 /* This was a pre-DWARF-5 GNU extension alias
13084 for DW_AT_call_return_pc. */
13085 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13089 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13090 "DIE %s [in module %s]"),
13091 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13094 pc
= attr
->value_as_address () + baseaddr
;
13095 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13097 if (cu
->call_site_htab
== NULL
)
13098 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13099 NULL
, &objfile
->objfile_obstack
,
13100 hashtab_obstack_allocate
, NULL
);
13101 call_site_local
.pc
= pc
;
13102 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13105 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13106 "DIE %s [in module %s]"),
13107 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13108 objfile_name (objfile
));
13112 /* Count parameters at the caller. */
13115 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13116 child_die
= child_die
->sibling
)
13118 if (child_die
->tag
!= DW_TAG_call_site_parameter
13119 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13121 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13122 "DW_TAG_call_site child DIE %s [in module %s]"),
13123 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13124 objfile_name (objfile
));
13132 = ((struct call_site
*)
13133 obstack_alloc (&objfile
->objfile_obstack
,
13134 sizeof (*call_site
)
13135 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13137 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13138 call_site
->pc
= pc
;
13140 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13141 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13143 struct die_info
*func_die
;
13145 /* Skip also over DW_TAG_inlined_subroutine. */
13146 for (func_die
= die
->parent
;
13147 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13148 && func_die
->tag
!= DW_TAG_subroutine_type
;
13149 func_die
= func_die
->parent
);
13151 /* DW_AT_call_all_calls is a superset
13152 of DW_AT_call_all_tail_calls. */
13154 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13155 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13156 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13157 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13159 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13160 not complete. But keep CALL_SITE for look ups via call_site_htab,
13161 both the initial caller containing the real return address PC and
13162 the final callee containing the current PC of a chain of tail
13163 calls do not need to have the tail call list complete. But any
13164 function candidate for a virtual tail call frame searched via
13165 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13166 determined unambiguously. */
13170 struct type
*func_type
= NULL
;
13173 func_type
= get_die_type (func_die
, cu
);
13174 if (func_type
!= NULL
)
13176 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13178 /* Enlist this call site to the function. */
13179 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13180 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13183 complaint (_("Cannot find function owning DW_TAG_call_site "
13184 "DIE %s [in module %s]"),
13185 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13189 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13191 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13193 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13196 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13197 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13199 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13200 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13201 /* Keep NULL DWARF_BLOCK. */;
13202 else if (attr
->form_is_block ())
13204 struct dwarf2_locexpr_baton
*dlbaton
;
13206 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13207 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13208 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13209 dlbaton
->per_cu
= cu
->per_cu
;
13211 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13213 else if (attr
->form_is_ref ())
13215 struct dwarf2_cu
*target_cu
= cu
;
13216 struct die_info
*target_die
;
13218 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13219 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13220 if (die_is_declaration (target_die
, target_cu
))
13222 const char *target_physname
;
13224 /* Prefer the mangled name; otherwise compute the demangled one. */
13225 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13226 if (target_physname
== NULL
)
13227 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13228 if (target_physname
== NULL
)
13229 complaint (_("DW_AT_call_target target DIE has invalid "
13230 "physname, for referencing DIE %s [in module %s]"),
13231 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13233 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13239 /* DW_AT_entry_pc should be preferred. */
13240 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13241 <= PC_BOUNDS_INVALID
)
13242 complaint (_("DW_AT_call_target target DIE has invalid "
13243 "low pc, for referencing DIE %s [in module %s]"),
13244 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13247 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13248 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13253 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13254 "block nor reference, for DIE %s [in module %s]"),
13255 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13257 call_site
->per_cu
= cu
->per_cu
;
13259 for (child_die
= die
->child
;
13260 child_die
&& child_die
->tag
;
13261 child_die
= child_die
->sibling
)
13263 struct call_site_parameter
*parameter
;
13264 struct attribute
*loc
, *origin
;
13266 if (child_die
->tag
!= DW_TAG_call_site_parameter
13267 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13269 /* Already printed the complaint above. */
13273 gdb_assert (call_site
->parameter_count
< nparams
);
13274 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13276 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13277 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13278 register is contained in DW_AT_call_value. */
13280 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13281 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13282 if (origin
== NULL
)
13284 /* This was a pre-DWARF-5 GNU extension alias
13285 for DW_AT_call_parameter. */
13286 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13288 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13290 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13292 sect_offset sect_off
= origin
->get_ref_die_offset ();
13293 if (!cu
->header
.offset_in_cu_p (sect_off
))
13295 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13296 binding can be done only inside one CU. Such referenced DIE
13297 therefore cannot be even moved to DW_TAG_partial_unit. */
13298 complaint (_("DW_AT_call_parameter offset is not in CU for "
13299 "DW_TAG_call_site child DIE %s [in module %s]"),
13300 sect_offset_str (child_die
->sect_off
),
13301 objfile_name (objfile
));
13304 parameter
->u
.param_cu_off
13305 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13307 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13309 complaint (_("No DW_FORM_block* DW_AT_location for "
13310 "DW_TAG_call_site child DIE %s [in module %s]"),
13311 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13316 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13317 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13318 if (parameter
->u
.dwarf_reg
!= -1)
13319 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13320 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13321 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13322 ¶meter
->u
.fb_offset
))
13323 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13326 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13327 "for DW_FORM_block* DW_AT_location is supported for "
13328 "DW_TAG_call_site child DIE %s "
13330 sect_offset_str (child_die
->sect_off
),
13331 objfile_name (objfile
));
13336 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13338 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13339 if (attr
== NULL
|| !attr
->form_is_block ())
13341 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13342 "DW_TAG_call_site child DIE %s [in module %s]"),
13343 sect_offset_str (child_die
->sect_off
),
13344 objfile_name (objfile
));
13347 parameter
->value
= DW_BLOCK (attr
)->data
;
13348 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13350 /* Parameters are not pre-cleared by memset above. */
13351 parameter
->data_value
= NULL
;
13352 parameter
->data_value_size
= 0;
13353 call_site
->parameter_count
++;
13355 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13357 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13358 if (attr
!= nullptr)
13360 if (!attr
->form_is_block ())
13361 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13362 "DW_TAG_call_site child DIE %s [in module %s]"),
13363 sect_offset_str (child_die
->sect_off
),
13364 objfile_name (objfile
));
13367 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13368 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13374 /* Helper function for read_variable. If DIE represents a virtual
13375 table, then return the type of the concrete object that is
13376 associated with the virtual table. Otherwise, return NULL. */
13378 static struct type
*
13379 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13381 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13385 /* Find the type DIE. */
13386 struct die_info
*type_die
= NULL
;
13387 struct dwarf2_cu
*type_cu
= cu
;
13389 if (attr
->form_is_ref ())
13390 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13391 if (type_die
== NULL
)
13394 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13396 return die_containing_type (type_die
, type_cu
);
13399 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13402 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13404 struct rust_vtable_symbol
*storage
= NULL
;
13406 if (cu
->language
== language_rust
)
13408 struct type
*containing_type
= rust_containing_type (die
, cu
);
13410 if (containing_type
!= NULL
)
13412 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13414 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13415 initialize_objfile_symbol (storage
);
13416 storage
->concrete_type
= containing_type
;
13417 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13421 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13422 struct attribute
*abstract_origin
13423 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13424 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13425 if (res
== NULL
&& loc
&& abstract_origin
)
13427 /* We have a variable without a name, but with a location and an abstract
13428 origin. This may be a concrete instance of an abstract variable
13429 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13431 struct dwarf2_cu
*origin_cu
= cu
;
13432 struct die_info
*origin_die
13433 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13434 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13435 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13439 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13440 reading .debug_rnglists.
13441 Callback's type should be:
13442 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13443 Return true if the attributes are present and valid, otherwise,
13446 template <typename Callback
>
13448 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13449 Callback
&&callback
)
13451 struct dwarf2_per_objfile
*dwarf2_per_objfile
13452 = cu
->per_cu
->dwarf2_per_objfile
;
13453 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13454 bfd
*obfd
= objfile
->obfd
;
13455 /* Base address selection entry. */
13456 gdb::optional
<CORE_ADDR
> base
;
13457 const gdb_byte
*buffer
;
13458 CORE_ADDR baseaddr
;
13459 bool overflow
= false;
13461 base
= cu
->base_address
;
13463 dwarf2_per_objfile
->rnglists
.read (objfile
);
13464 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13466 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13470 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13472 baseaddr
= objfile
->text_section_offset ();
13476 /* Initialize it due to a false compiler warning. */
13477 CORE_ADDR range_beginning
= 0, range_end
= 0;
13478 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13479 + dwarf2_per_objfile
->rnglists
.size
);
13480 unsigned int bytes_read
;
13482 if (buffer
== buf_end
)
13487 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13490 case DW_RLE_end_of_list
:
13492 case DW_RLE_base_address
:
13493 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13498 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13499 buffer
+= bytes_read
;
13501 case DW_RLE_start_length
:
13502 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13507 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13509 buffer
+= bytes_read
;
13510 range_end
= (range_beginning
13511 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13512 buffer
+= bytes_read
;
13513 if (buffer
> buf_end
)
13519 case DW_RLE_offset_pair
:
13520 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13521 buffer
+= bytes_read
;
13522 if (buffer
> buf_end
)
13527 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13528 buffer
+= bytes_read
;
13529 if (buffer
> buf_end
)
13535 case DW_RLE_start_end
:
13536 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13541 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13543 buffer
+= bytes_read
;
13544 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13545 buffer
+= bytes_read
;
13548 complaint (_("Invalid .debug_rnglists data (no base address)"));
13551 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13553 if (rlet
== DW_RLE_base_address
)
13556 if (!base
.has_value ())
13558 /* We have no valid base address for the ranges
13560 complaint (_("Invalid .debug_rnglists data (no base address)"));
13564 if (range_beginning
> range_end
)
13566 /* Inverted range entries are invalid. */
13567 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13571 /* Empty range entries have no effect. */
13572 if (range_beginning
== range_end
)
13575 range_beginning
+= *base
;
13576 range_end
+= *base
;
13578 /* A not-uncommon case of bad debug info.
13579 Don't pollute the addrmap with bad data. */
13580 if (range_beginning
+ baseaddr
== 0
13581 && !dwarf2_per_objfile
->has_section_at_zero
)
13583 complaint (_(".debug_rnglists entry has start address of zero"
13584 " [in module %s]"), objfile_name (objfile
));
13588 callback (range_beginning
, range_end
);
13593 complaint (_("Offset %d is not terminated "
13594 "for DW_AT_ranges attribute"),
13602 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13603 Callback's type should be:
13604 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13605 Return 1 if the attributes are present and valid, otherwise, return 0. */
13607 template <typename Callback
>
13609 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13610 Callback
&&callback
)
13612 struct dwarf2_per_objfile
*dwarf2_per_objfile
13613 = cu
->per_cu
->dwarf2_per_objfile
;
13614 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13615 struct comp_unit_head
*cu_header
= &cu
->header
;
13616 bfd
*obfd
= objfile
->obfd
;
13617 unsigned int addr_size
= cu_header
->addr_size
;
13618 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13619 /* Base address selection entry. */
13620 gdb::optional
<CORE_ADDR
> base
;
13621 unsigned int dummy
;
13622 const gdb_byte
*buffer
;
13623 CORE_ADDR baseaddr
;
13625 if (cu_header
->version
>= 5)
13626 return dwarf2_rnglists_process (offset
, cu
, callback
);
13628 base
= cu
->base_address
;
13630 dwarf2_per_objfile
->ranges
.read (objfile
);
13631 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13633 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13637 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13639 baseaddr
= objfile
->text_section_offset ();
13643 CORE_ADDR range_beginning
, range_end
;
13645 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13646 buffer
+= addr_size
;
13647 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13648 buffer
+= addr_size
;
13649 offset
+= 2 * addr_size
;
13651 /* An end of list marker is a pair of zero addresses. */
13652 if (range_beginning
== 0 && range_end
== 0)
13653 /* Found the end of list entry. */
13656 /* Each base address selection entry is a pair of 2 values.
13657 The first is the largest possible address, the second is
13658 the base address. Check for a base address here. */
13659 if ((range_beginning
& mask
) == mask
)
13661 /* If we found the largest possible address, then we already
13662 have the base address in range_end. */
13667 if (!base
.has_value ())
13669 /* We have no valid base address for the ranges
13671 complaint (_("Invalid .debug_ranges data (no base address)"));
13675 if (range_beginning
> range_end
)
13677 /* Inverted range entries are invalid. */
13678 complaint (_("Invalid .debug_ranges data (inverted range)"));
13682 /* Empty range entries have no effect. */
13683 if (range_beginning
== range_end
)
13686 range_beginning
+= *base
;
13687 range_end
+= *base
;
13689 /* A not-uncommon case of bad debug info.
13690 Don't pollute the addrmap with bad data. */
13691 if (range_beginning
+ baseaddr
== 0
13692 && !dwarf2_per_objfile
->has_section_at_zero
)
13694 complaint (_(".debug_ranges entry has start address of zero"
13695 " [in module %s]"), objfile_name (objfile
));
13699 callback (range_beginning
, range_end
);
13705 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13706 Return 1 if the attributes are present and valid, otherwise, return 0.
13707 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13710 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13711 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13712 dwarf2_psymtab
*ranges_pst
)
13714 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13715 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13716 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13719 CORE_ADDR high
= 0;
13722 retval
= dwarf2_ranges_process (offset
, cu
,
13723 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13725 if (ranges_pst
!= NULL
)
13730 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13731 range_beginning
+ baseaddr
)
13733 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13734 range_end
+ baseaddr
)
13736 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13737 lowpc
, highpc
- 1, ranges_pst
);
13740 /* FIXME: This is recording everything as a low-high
13741 segment of consecutive addresses. We should have a
13742 data structure for discontiguous block ranges
13746 low
= range_beginning
;
13752 if (range_beginning
< low
)
13753 low
= range_beginning
;
13754 if (range_end
> high
)
13762 /* If the first entry is an end-of-list marker, the range
13763 describes an empty scope, i.e. no instructions. */
13769 *high_return
= high
;
13773 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13774 definition for the return value. *LOWPC and *HIGHPC are set iff
13775 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13777 static enum pc_bounds_kind
13778 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13779 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13780 dwarf2_psymtab
*pst
)
13782 struct dwarf2_per_objfile
*dwarf2_per_objfile
13783 = cu
->per_cu
->dwarf2_per_objfile
;
13784 struct attribute
*attr
;
13785 struct attribute
*attr_high
;
13787 CORE_ADDR high
= 0;
13788 enum pc_bounds_kind ret
;
13790 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13793 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13794 if (attr
!= nullptr)
13796 low
= attr
->value_as_address ();
13797 high
= attr_high
->value_as_address ();
13798 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13802 /* Found high w/o low attribute. */
13803 return PC_BOUNDS_INVALID
;
13805 /* Found consecutive range of addresses. */
13806 ret
= PC_BOUNDS_HIGH_LOW
;
13810 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13813 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13814 We take advantage of the fact that DW_AT_ranges does not appear
13815 in DW_TAG_compile_unit of DWO files. */
13816 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13817 unsigned int ranges_offset
= (DW_UNSND (attr
)
13818 + (need_ranges_base
13822 /* Value of the DW_AT_ranges attribute is the offset in the
13823 .debug_ranges section. */
13824 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13825 return PC_BOUNDS_INVALID
;
13826 /* Found discontinuous range of addresses. */
13827 ret
= PC_BOUNDS_RANGES
;
13830 return PC_BOUNDS_NOT_PRESENT
;
13833 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13835 return PC_BOUNDS_INVALID
;
13837 /* When using the GNU linker, .gnu.linkonce. sections are used to
13838 eliminate duplicate copies of functions and vtables and such.
13839 The linker will arbitrarily choose one and discard the others.
13840 The AT_*_pc values for such functions refer to local labels in
13841 these sections. If the section from that file was discarded, the
13842 labels are not in the output, so the relocs get a value of 0.
13843 If this is a discarded function, mark the pc bounds as invalid,
13844 so that GDB will ignore it. */
13845 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13846 return PC_BOUNDS_INVALID
;
13854 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13855 its low and high PC addresses. Do nothing if these addresses could not
13856 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13857 and HIGHPC to the high address if greater than HIGHPC. */
13860 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13861 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13862 struct dwarf2_cu
*cu
)
13864 CORE_ADDR low
, high
;
13865 struct die_info
*child
= die
->child
;
13867 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13869 *lowpc
= std::min (*lowpc
, low
);
13870 *highpc
= std::max (*highpc
, high
);
13873 /* If the language does not allow nested subprograms (either inside
13874 subprograms or lexical blocks), we're done. */
13875 if (cu
->language
!= language_ada
)
13878 /* Check all the children of the given DIE. If it contains nested
13879 subprograms, then check their pc bounds. Likewise, we need to
13880 check lexical blocks as well, as they may also contain subprogram
13882 while (child
&& child
->tag
)
13884 if (child
->tag
== DW_TAG_subprogram
13885 || child
->tag
== DW_TAG_lexical_block
)
13886 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13887 child
= child
->sibling
;
13891 /* Get the low and high pc's represented by the scope DIE, and store
13892 them in *LOWPC and *HIGHPC. If the correct values can't be
13893 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13896 get_scope_pc_bounds (struct die_info
*die
,
13897 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13898 struct dwarf2_cu
*cu
)
13900 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13901 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13902 CORE_ADDR current_low
, current_high
;
13904 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13905 >= PC_BOUNDS_RANGES
)
13907 best_low
= current_low
;
13908 best_high
= current_high
;
13912 struct die_info
*child
= die
->child
;
13914 while (child
&& child
->tag
)
13916 switch (child
->tag
) {
13917 case DW_TAG_subprogram
:
13918 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13920 case DW_TAG_namespace
:
13921 case DW_TAG_module
:
13922 /* FIXME: carlton/2004-01-16: Should we do this for
13923 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13924 that current GCC's always emit the DIEs corresponding
13925 to definitions of methods of classes as children of a
13926 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13927 the DIEs giving the declarations, which could be
13928 anywhere). But I don't see any reason why the
13929 standards says that they have to be there. */
13930 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13932 if (current_low
!= ((CORE_ADDR
) -1))
13934 best_low
= std::min (best_low
, current_low
);
13935 best_high
= std::max (best_high
, current_high
);
13943 child
= child
->sibling
;
13948 *highpc
= best_high
;
13951 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13955 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13956 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13958 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13959 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13960 struct attribute
*attr
;
13961 struct attribute
*attr_high
;
13963 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13966 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13967 if (attr
!= nullptr)
13969 CORE_ADDR low
= attr
->value_as_address ();
13970 CORE_ADDR high
= attr_high
->value_as_address ();
13972 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13975 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13976 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13977 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
13981 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13982 if (attr
!= nullptr)
13984 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13985 We take advantage of the fact that DW_AT_ranges does not appear
13986 in DW_TAG_compile_unit of DWO files. */
13987 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13989 /* The value of the DW_AT_ranges attribute is the offset of the
13990 address range list in the .debug_ranges section. */
13991 unsigned long offset
= (DW_UNSND (attr
)
13992 + (need_ranges_base
? cu
->ranges_base
: 0));
13994 std::vector
<blockrange
> blockvec
;
13995 dwarf2_ranges_process (offset
, cu
,
13996 [&] (CORE_ADDR start
, CORE_ADDR end
)
14000 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14001 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14002 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14003 blockvec
.emplace_back (start
, end
);
14006 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14010 /* Check whether the producer field indicates either of GCC < 4.6, or the
14011 Intel C/C++ compiler, and cache the result in CU. */
14014 check_producer (struct dwarf2_cu
*cu
)
14018 if (cu
->producer
== NULL
)
14020 /* For unknown compilers expect their behavior is DWARF version
14023 GCC started to support .debug_types sections by -gdwarf-4 since
14024 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14025 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14026 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14027 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14029 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14031 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14032 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14034 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14036 cu
->producer_is_icc
= true;
14037 cu
->producer_is_icc_lt_14
= major
< 14;
14039 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14040 cu
->producer_is_codewarrior
= true;
14043 /* For other non-GCC compilers, expect their behavior is DWARF version
14047 cu
->checked_producer
= true;
14050 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14051 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14052 during 4.6.0 experimental. */
14055 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14057 if (!cu
->checked_producer
)
14058 check_producer (cu
);
14060 return cu
->producer_is_gxx_lt_4_6
;
14064 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14065 with incorrect is_stmt attributes. */
14068 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14070 if (!cu
->checked_producer
)
14071 check_producer (cu
);
14073 return cu
->producer_is_codewarrior
;
14076 /* Return the default accessibility type if it is not overridden by
14077 DW_AT_accessibility. */
14079 static enum dwarf_access_attribute
14080 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14082 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14084 /* The default DWARF 2 accessibility for members is public, the default
14085 accessibility for inheritance is private. */
14087 if (die
->tag
!= DW_TAG_inheritance
)
14088 return DW_ACCESS_public
;
14090 return DW_ACCESS_private
;
14094 /* DWARF 3+ defines the default accessibility a different way. The same
14095 rules apply now for DW_TAG_inheritance as for the members and it only
14096 depends on the container kind. */
14098 if (die
->parent
->tag
== DW_TAG_class_type
)
14099 return DW_ACCESS_private
;
14101 return DW_ACCESS_public
;
14105 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14106 offset. If the attribute was not found return 0, otherwise return
14107 1. If it was found but could not properly be handled, set *OFFSET
14111 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14114 struct attribute
*attr
;
14116 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14121 /* Note that we do not check for a section offset first here.
14122 This is because DW_AT_data_member_location is new in DWARF 4,
14123 so if we see it, we can assume that a constant form is really
14124 a constant and not a section offset. */
14125 if (attr
->form_is_constant ())
14126 *offset
= attr
->constant_value (0);
14127 else if (attr
->form_is_section_offset ())
14128 dwarf2_complex_location_expr_complaint ();
14129 else if (attr
->form_is_block ())
14130 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14132 dwarf2_complex_location_expr_complaint ();
14140 /* Add an aggregate field to the field list. */
14143 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14144 struct dwarf2_cu
*cu
)
14146 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14147 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14148 struct nextfield
*new_field
;
14149 struct attribute
*attr
;
14151 const char *fieldname
= "";
14153 if (die
->tag
== DW_TAG_inheritance
)
14155 fip
->baseclasses
.emplace_back ();
14156 new_field
= &fip
->baseclasses
.back ();
14160 fip
->fields
.emplace_back ();
14161 new_field
= &fip
->fields
.back ();
14164 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14165 if (attr
!= nullptr)
14166 new_field
->accessibility
= DW_UNSND (attr
);
14168 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14169 if (new_field
->accessibility
!= DW_ACCESS_public
)
14170 fip
->non_public_fields
= 1;
14172 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14173 if (attr
!= nullptr)
14174 new_field
->virtuality
= DW_UNSND (attr
);
14176 new_field
->virtuality
= DW_VIRTUALITY_none
;
14178 fp
= &new_field
->field
;
14180 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14184 /* Data member other than a C++ static data member. */
14186 /* Get type of field. */
14187 fp
->type
= die_type (die
, cu
);
14189 SET_FIELD_BITPOS (*fp
, 0);
14191 /* Get bit size of field (zero if none). */
14192 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14193 if (attr
!= nullptr)
14195 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14199 FIELD_BITSIZE (*fp
) = 0;
14202 /* Get bit offset of field. */
14203 if (handle_data_member_location (die
, cu
, &offset
))
14204 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14205 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14206 if (attr
!= nullptr)
14208 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14210 /* For big endian bits, the DW_AT_bit_offset gives the
14211 additional bit offset from the MSB of the containing
14212 anonymous object to the MSB of the field. We don't
14213 have to do anything special since we don't need to
14214 know the size of the anonymous object. */
14215 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14219 /* For little endian bits, compute the bit offset to the
14220 MSB of the anonymous object, subtract off the number of
14221 bits from the MSB of the field to the MSB of the
14222 object, and then subtract off the number of bits of
14223 the field itself. The result is the bit offset of
14224 the LSB of the field. */
14225 int anonymous_size
;
14226 int bit_offset
= DW_UNSND (attr
);
14228 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14229 if (attr
!= nullptr)
14231 /* The size of the anonymous object containing
14232 the bit field is explicit, so use the
14233 indicated size (in bytes). */
14234 anonymous_size
= DW_UNSND (attr
);
14238 /* The size of the anonymous object containing
14239 the bit field must be inferred from the type
14240 attribute of the data member containing the
14242 anonymous_size
= TYPE_LENGTH (fp
->type
);
14244 SET_FIELD_BITPOS (*fp
,
14245 (FIELD_BITPOS (*fp
)
14246 + anonymous_size
* bits_per_byte
14247 - bit_offset
- FIELD_BITSIZE (*fp
)));
14250 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14252 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14253 + attr
->constant_value (0)));
14255 /* Get name of field. */
14256 fieldname
= dwarf2_name (die
, cu
);
14257 if (fieldname
== NULL
)
14260 /* The name is already allocated along with this objfile, so we don't
14261 need to duplicate it for the type. */
14262 fp
->name
= fieldname
;
14264 /* Change accessibility for artificial fields (e.g. virtual table
14265 pointer or virtual base class pointer) to private. */
14266 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14268 FIELD_ARTIFICIAL (*fp
) = 1;
14269 new_field
->accessibility
= DW_ACCESS_private
;
14270 fip
->non_public_fields
= 1;
14273 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14275 /* C++ static member. */
14277 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14278 is a declaration, but all versions of G++ as of this writing
14279 (so through at least 3.2.1) incorrectly generate
14280 DW_TAG_variable tags. */
14282 const char *physname
;
14284 /* Get name of field. */
14285 fieldname
= dwarf2_name (die
, cu
);
14286 if (fieldname
== NULL
)
14289 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14291 /* Only create a symbol if this is an external value.
14292 new_symbol checks this and puts the value in the global symbol
14293 table, which we want. If it is not external, new_symbol
14294 will try to put the value in cu->list_in_scope which is wrong. */
14295 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14297 /* A static const member, not much different than an enum as far as
14298 we're concerned, except that we can support more types. */
14299 new_symbol (die
, NULL
, cu
);
14302 /* Get physical name. */
14303 physname
= dwarf2_physname (fieldname
, die
, cu
);
14305 /* The name is already allocated along with this objfile, so we don't
14306 need to duplicate it for the type. */
14307 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14308 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14309 FIELD_NAME (*fp
) = fieldname
;
14311 else if (die
->tag
== DW_TAG_inheritance
)
14315 /* C++ base class field. */
14316 if (handle_data_member_location (die
, cu
, &offset
))
14317 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14318 FIELD_BITSIZE (*fp
) = 0;
14319 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14320 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14322 else if (die
->tag
== DW_TAG_variant_part
)
14324 /* process_structure_scope will treat this DIE as a union. */
14325 process_structure_scope (die
, cu
);
14327 /* The variant part is relative to the start of the enclosing
14329 SET_FIELD_BITPOS (*fp
, 0);
14330 fp
->type
= get_die_type (die
, cu
);
14331 fp
->artificial
= 1;
14332 fp
->name
= "<<variant>>";
14334 /* Normally a DW_TAG_variant_part won't have a size, but our
14335 representation requires one, so set it to the maximum of the
14336 child sizes, being sure to account for the offset at which
14337 each child is seen. */
14338 if (TYPE_LENGTH (fp
->type
) == 0)
14341 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14343 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14344 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14348 TYPE_LENGTH (fp
->type
) = max
;
14352 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14355 /* Can the type given by DIE define another type? */
14358 type_can_define_types (const struct die_info
*die
)
14362 case DW_TAG_typedef
:
14363 case DW_TAG_class_type
:
14364 case DW_TAG_structure_type
:
14365 case DW_TAG_union_type
:
14366 case DW_TAG_enumeration_type
:
14374 /* Add a type definition defined in the scope of the FIP's class. */
14377 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14378 struct dwarf2_cu
*cu
)
14380 struct decl_field fp
;
14381 memset (&fp
, 0, sizeof (fp
));
14383 gdb_assert (type_can_define_types (die
));
14385 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14386 fp
.name
= dwarf2_name (die
, cu
);
14387 fp
.type
= read_type_die (die
, cu
);
14389 /* Save accessibility. */
14390 enum dwarf_access_attribute accessibility
;
14391 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14393 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14395 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14396 switch (accessibility
)
14398 case DW_ACCESS_public
:
14399 /* The assumed value if neither private nor protected. */
14401 case DW_ACCESS_private
:
14404 case DW_ACCESS_protected
:
14405 fp
.is_protected
= 1;
14408 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14411 if (die
->tag
== DW_TAG_typedef
)
14412 fip
->typedef_field_list
.push_back (fp
);
14414 fip
->nested_types_list
.push_back (fp
);
14417 /* Create the vector of fields, and attach it to the type. */
14420 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14421 struct dwarf2_cu
*cu
)
14423 int nfields
= fip
->nfields ();
14425 /* Record the field count, allocate space for the array of fields,
14426 and create blank accessibility bitfields if necessary. */
14427 TYPE_NFIELDS (type
) = nfields
;
14428 TYPE_FIELDS (type
) = (struct field
*)
14429 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14431 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14433 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14435 TYPE_FIELD_PRIVATE_BITS (type
) =
14436 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14437 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14439 TYPE_FIELD_PROTECTED_BITS (type
) =
14440 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14441 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14443 TYPE_FIELD_IGNORE_BITS (type
) =
14444 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14445 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14448 /* If the type has baseclasses, allocate and clear a bit vector for
14449 TYPE_FIELD_VIRTUAL_BITS. */
14450 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14452 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14453 unsigned char *pointer
;
14455 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14456 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14457 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14458 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14459 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14462 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14464 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14466 for (int index
= 0; index
< nfields
; ++index
)
14468 struct nextfield
&field
= fip
->fields
[index
];
14470 if (field
.variant
.is_discriminant
)
14471 di
->discriminant_index
= index
;
14472 else if (field
.variant
.default_branch
)
14473 di
->default_index
= index
;
14475 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14479 /* Copy the saved-up fields into the field vector. */
14480 for (int i
= 0; i
< nfields
; ++i
)
14482 struct nextfield
&field
14483 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14484 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14486 TYPE_FIELD (type
, i
) = field
.field
;
14487 switch (field
.accessibility
)
14489 case DW_ACCESS_private
:
14490 if (cu
->language
!= language_ada
)
14491 SET_TYPE_FIELD_PRIVATE (type
, i
);
14494 case DW_ACCESS_protected
:
14495 if (cu
->language
!= language_ada
)
14496 SET_TYPE_FIELD_PROTECTED (type
, i
);
14499 case DW_ACCESS_public
:
14503 /* Unknown accessibility. Complain and treat it as public. */
14505 complaint (_("unsupported accessibility %d"),
14506 field
.accessibility
);
14510 if (i
< fip
->baseclasses
.size ())
14512 switch (field
.virtuality
)
14514 case DW_VIRTUALITY_virtual
:
14515 case DW_VIRTUALITY_pure_virtual
:
14516 if (cu
->language
== language_ada
)
14517 error (_("unexpected virtuality in component of Ada type"));
14518 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14525 /* Return true if this member function is a constructor, false
14529 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14531 const char *fieldname
;
14532 const char *type_name
;
14535 if (die
->parent
== NULL
)
14538 if (die
->parent
->tag
!= DW_TAG_structure_type
14539 && die
->parent
->tag
!= DW_TAG_union_type
14540 && die
->parent
->tag
!= DW_TAG_class_type
)
14543 fieldname
= dwarf2_name (die
, cu
);
14544 type_name
= dwarf2_name (die
->parent
, cu
);
14545 if (fieldname
== NULL
|| type_name
== NULL
)
14548 len
= strlen (fieldname
);
14549 return (strncmp (fieldname
, type_name
, len
) == 0
14550 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14553 /* Check if the given VALUE is a recognized enum
14554 dwarf_defaulted_attribute constant according to DWARF5 spec,
14558 is_valid_DW_AT_defaulted (ULONGEST value
)
14562 case DW_DEFAULTED_no
:
14563 case DW_DEFAULTED_in_class
:
14564 case DW_DEFAULTED_out_of_class
:
14568 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14572 /* Add a member function to the proper fieldlist. */
14575 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14576 struct type
*type
, struct dwarf2_cu
*cu
)
14578 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14579 struct attribute
*attr
;
14581 struct fnfieldlist
*flp
= nullptr;
14582 struct fn_field
*fnp
;
14583 const char *fieldname
;
14584 struct type
*this_type
;
14585 enum dwarf_access_attribute accessibility
;
14587 if (cu
->language
== language_ada
)
14588 error (_("unexpected member function in Ada type"));
14590 /* Get name of member function. */
14591 fieldname
= dwarf2_name (die
, cu
);
14592 if (fieldname
== NULL
)
14595 /* Look up member function name in fieldlist. */
14596 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14598 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14600 flp
= &fip
->fnfieldlists
[i
];
14605 /* Create a new fnfieldlist if necessary. */
14606 if (flp
== nullptr)
14608 fip
->fnfieldlists
.emplace_back ();
14609 flp
= &fip
->fnfieldlists
.back ();
14610 flp
->name
= fieldname
;
14611 i
= fip
->fnfieldlists
.size () - 1;
14614 /* Create a new member function field and add it to the vector of
14616 flp
->fnfields
.emplace_back ();
14617 fnp
= &flp
->fnfields
.back ();
14619 /* Delay processing of the physname until later. */
14620 if (cu
->language
== language_cplus
)
14621 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14625 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14626 fnp
->physname
= physname
? physname
: "";
14629 fnp
->type
= alloc_type (objfile
);
14630 this_type
= read_type_die (die
, cu
);
14631 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14633 int nparams
= TYPE_NFIELDS (this_type
);
14635 /* TYPE is the domain of this method, and THIS_TYPE is the type
14636 of the method itself (TYPE_CODE_METHOD). */
14637 smash_to_method_type (fnp
->type
, type
,
14638 TYPE_TARGET_TYPE (this_type
),
14639 TYPE_FIELDS (this_type
),
14640 TYPE_NFIELDS (this_type
),
14641 TYPE_VARARGS (this_type
));
14643 /* Handle static member functions.
14644 Dwarf2 has no clean way to discern C++ static and non-static
14645 member functions. G++ helps GDB by marking the first
14646 parameter for non-static member functions (which is the this
14647 pointer) as artificial. We obtain this information from
14648 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14649 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14650 fnp
->voffset
= VOFFSET_STATIC
;
14653 complaint (_("member function type missing for '%s'"),
14654 dwarf2_full_name (fieldname
, die
, cu
));
14656 /* Get fcontext from DW_AT_containing_type if present. */
14657 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14658 fnp
->fcontext
= die_containing_type (die
, cu
);
14660 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14661 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14663 /* Get accessibility. */
14664 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14665 if (attr
!= nullptr)
14666 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14668 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14669 switch (accessibility
)
14671 case DW_ACCESS_private
:
14672 fnp
->is_private
= 1;
14674 case DW_ACCESS_protected
:
14675 fnp
->is_protected
= 1;
14679 /* Check for artificial methods. */
14680 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14681 if (attr
&& DW_UNSND (attr
) != 0)
14682 fnp
->is_artificial
= 1;
14684 /* Check for defaulted methods. */
14685 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14686 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14687 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14689 /* Check for deleted methods. */
14690 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14691 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14692 fnp
->is_deleted
= 1;
14694 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14696 /* Get index in virtual function table if it is a virtual member
14697 function. For older versions of GCC, this is an offset in the
14698 appropriate virtual table, as specified by DW_AT_containing_type.
14699 For everyone else, it is an expression to be evaluated relative
14700 to the object address. */
14702 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14703 if (attr
!= nullptr)
14705 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14707 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14709 /* Old-style GCC. */
14710 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14712 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14713 || (DW_BLOCK (attr
)->size
> 1
14714 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14715 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14717 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14718 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14719 dwarf2_complex_location_expr_complaint ();
14721 fnp
->voffset
/= cu
->header
.addr_size
;
14725 dwarf2_complex_location_expr_complaint ();
14727 if (!fnp
->fcontext
)
14729 /* If there is no `this' field and no DW_AT_containing_type,
14730 we cannot actually find a base class context for the
14732 if (TYPE_NFIELDS (this_type
) == 0
14733 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14735 complaint (_("cannot determine context for virtual member "
14736 "function \"%s\" (offset %s)"),
14737 fieldname
, sect_offset_str (die
->sect_off
));
14742 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14746 else if (attr
->form_is_section_offset ())
14748 dwarf2_complex_location_expr_complaint ();
14752 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14758 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14759 if (attr
&& DW_UNSND (attr
))
14761 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14762 complaint (_("Member function \"%s\" (offset %s) is virtual "
14763 "but the vtable offset is not specified"),
14764 fieldname
, sect_offset_str (die
->sect_off
));
14765 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14766 TYPE_CPLUS_DYNAMIC (type
) = 1;
14771 /* Create the vector of member function fields, and attach it to the type. */
14774 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14775 struct dwarf2_cu
*cu
)
14777 if (cu
->language
== language_ada
)
14778 error (_("unexpected member functions in Ada type"));
14780 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14781 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14783 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14785 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14787 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14788 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14790 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14791 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14792 fn_flp
->fn_fields
= (struct fn_field
*)
14793 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14795 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14796 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14799 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14802 /* Returns non-zero if NAME is the name of a vtable member in CU's
14803 language, zero otherwise. */
14805 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14807 static const char vptr
[] = "_vptr";
14809 /* Look for the C++ form of the vtable. */
14810 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14816 /* GCC outputs unnamed structures that are really pointers to member
14817 functions, with the ABI-specified layout. If TYPE describes
14818 such a structure, smash it into a member function type.
14820 GCC shouldn't do this; it should just output pointer to member DIEs.
14821 This is GCC PR debug/28767. */
14824 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14826 struct type
*pfn_type
, *self_type
, *new_type
;
14828 /* Check for a structure with no name and two children. */
14829 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14832 /* Check for __pfn and __delta members. */
14833 if (TYPE_FIELD_NAME (type
, 0) == NULL
14834 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14835 || TYPE_FIELD_NAME (type
, 1) == NULL
14836 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14839 /* Find the type of the method. */
14840 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14841 if (pfn_type
== NULL
14842 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14843 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14846 /* Look for the "this" argument. */
14847 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14848 if (TYPE_NFIELDS (pfn_type
) == 0
14849 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14850 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14853 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14854 new_type
= alloc_type (objfile
);
14855 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14856 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14857 TYPE_VARARGS (pfn_type
));
14858 smash_to_methodptr_type (type
, new_type
);
14861 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14862 appropriate error checking and issuing complaints if there is a
14866 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14868 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14870 if (attr
== nullptr)
14873 if (!attr
->form_is_constant ())
14875 complaint (_("DW_AT_alignment must have constant form"
14876 " - DIE at %s [in module %s]"),
14877 sect_offset_str (die
->sect_off
),
14878 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14883 if (attr
->form
== DW_FORM_sdata
)
14885 LONGEST val
= DW_SND (attr
);
14888 complaint (_("DW_AT_alignment value must not be negative"
14889 " - DIE at %s [in module %s]"),
14890 sect_offset_str (die
->sect_off
),
14891 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14897 align
= DW_UNSND (attr
);
14901 complaint (_("DW_AT_alignment value must not be zero"
14902 " - DIE at %s [in module %s]"),
14903 sect_offset_str (die
->sect_off
),
14904 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14907 if ((align
& (align
- 1)) != 0)
14909 complaint (_("DW_AT_alignment value must be a power of 2"
14910 " - DIE at %s [in module %s]"),
14911 sect_offset_str (die
->sect_off
),
14912 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14919 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14920 the alignment for TYPE. */
14923 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14926 if (!set_type_align (type
, get_alignment (cu
, die
)))
14927 complaint (_("DW_AT_alignment value too large"
14928 " - DIE at %s [in module %s]"),
14929 sect_offset_str (die
->sect_off
),
14930 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14933 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14934 constant for a type, according to DWARF5 spec, Table 5.5. */
14937 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14942 case DW_CC_pass_by_reference
:
14943 case DW_CC_pass_by_value
:
14947 complaint (_("unrecognized DW_AT_calling_convention value "
14948 "(%s) for a type"), pulongest (value
));
14953 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14954 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14955 also according to GNU-specific values (see include/dwarf2.h). */
14958 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14963 case DW_CC_program
:
14967 case DW_CC_GNU_renesas_sh
:
14968 case DW_CC_GNU_borland_fastcall_i386
:
14969 case DW_CC_GDB_IBM_OpenCL
:
14973 complaint (_("unrecognized DW_AT_calling_convention value "
14974 "(%s) for a subroutine"), pulongest (value
));
14979 /* Called when we find the DIE that starts a structure or union scope
14980 (definition) to create a type for the structure or union. Fill in
14981 the type's name and general properties; the members will not be
14982 processed until process_structure_scope. A symbol table entry for
14983 the type will also not be done until process_structure_scope (assuming
14984 the type has a name).
14986 NOTE: we need to call these functions regardless of whether or not the
14987 DIE has a DW_AT_name attribute, since it might be an anonymous
14988 structure or union. This gets the type entered into our set of
14989 user defined types. */
14991 static struct type
*
14992 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14994 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14996 struct attribute
*attr
;
14999 /* If the definition of this type lives in .debug_types, read that type.
15000 Don't follow DW_AT_specification though, that will take us back up
15001 the chain and we want to go down. */
15002 attr
= die
->attr (DW_AT_signature
);
15003 if (attr
!= nullptr)
15005 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15007 /* The type's CU may not be the same as CU.
15008 Ensure TYPE is recorded with CU in die_type_hash. */
15009 return set_die_type (die
, type
, cu
);
15012 type
= alloc_type (objfile
);
15013 INIT_CPLUS_SPECIFIC (type
);
15015 name
= dwarf2_name (die
, cu
);
15018 if (cu
->language
== language_cplus
15019 || cu
->language
== language_d
15020 || cu
->language
== language_rust
)
15022 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15024 /* dwarf2_full_name might have already finished building the DIE's
15025 type. If so, there is no need to continue. */
15026 if (get_die_type (die
, cu
) != NULL
)
15027 return get_die_type (die
, cu
);
15029 TYPE_NAME (type
) = full_name
;
15033 /* The name is already allocated along with this objfile, so
15034 we don't need to duplicate it for the type. */
15035 TYPE_NAME (type
) = name
;
15039 if (die
->tag
== DW_TAG_structure_type
)
15041 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15043 else if (die
->tag
== DW_TAG_union_type
)
15045 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15047 else if (die
->tag
== DW_TAG_variant_part
)
15049 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15050 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15054 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15057 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15058 TYPE_DECLARED_CLASS (type
) = 1;
15060 /* Store the calling convention in the type if it's available in
15061 the die. Otherwise the calling convention remains set to
15062 the default value DW_CC_normal. */
15063 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15064 if (attr
!= nullptr
15065 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15067 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15068 TYPE_CPLUS_CALLING_CONVENTION (type
)
15069 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15072 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15073 if (attr
!= nullptr)
15075 if (attr
->form_is_constant ())
15076 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15079 /* For the moment, dynamic type sizes are not supported
15080 by GDB's struct type. The actual size is determined
15081 on-demand when resolving the type of a given object,
15082 so set the type's length to zero for now. Otherwise,
15083 we record an expression as the length, and that expression
15084 could lead to a very large value, which could eventually
15085 lead to us trying to allocate that much memory when creating
15086 a value of that type. */
15087 TYPE_LENGTH (type
) = 0;
15092 TYPE_LENGTH (type
) = 0;
15095 maybe_set_alignment (cu
, die
, type
);
15097 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15099 /* ICC<14 does not output the required DW_AT_declaration on
15100 incomplete types, but gives them a size of zero. */
15101 TYPE_STUB (type
) = 1;
15104 TYPE_STUB_SUPPORTED (type
) = 1;
15106 if (die_is_declaration (die
, cu
))
15107 TYPE_STUB (type
) = 1;
15108 else if (attr
== NULL
&& die
->child
== NULL
15109 && producer_is_realview (cu
->producer
))
15110 /* RealView does not output the required DW_AT_declaration
15111 on incomplete types. */
15112 TYPE_STUB (type
) = 1;
15114 /* We need to add the type field to the die immediately so we don't
15115 infinitely recurse when dealing with pointers to the structure
15116 type within the structure itself. */
15117 set_die_type (die
, type
, cu
);
15119 /* set_die_type should be already done. */
15120 set_descriptive_type (type
, die
, cu
);
15125 /* A helper for process_structure_scope that handles a single member
15129 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15130 struct field_info
*fi
,
15131 std::vector
<struct symbol
*> *template_args
,
15132 struct dwarf2_cu
*cu
)
15134 if (child_die
->tag
== DW_TAG_member
15135 || child_die
->tag
== DW_TAG_variable
15136 || child_die
->tag
== DW_TAG_variant_part
)
15138 /* NOTE: carlton/2002-11-05: A C++ static data member
15139 should be a DW_TAG_member that is a declaration, but
15140 all versions of G++ as of this writing (so through at
15141 least 3.2.1) incorrectly generate DW_TAG_variable
15142 tags for them instead. */
15143 dwarf2_add_field (fi
, child_die
, cu
);
15145 else if (child_die
->tag
== DW_TAG_subprogram
)
15147 /* Rust doesn't have member functions in the C++ sense.
15148 However, it does emit ordinary functions as children
15149 of a struct DIE. */
15150 if (cu
->language
== language_rust
)
15151 read_func_scope (child_die
, cu
);
15154 /* C++ member function. */
15155 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15158 else if (child_die
->tag
== DW_TAG_inheritance
)
15160 /* C++ base class field. */
15161 dwarf2_add_field (fi
, child_die
, cu
);
15163 else if (type_can_define_types (child_die
))
15164 dwarf2_add_type_defn (fi
, child_die
, cu
);
15165 else if (child_die
->tag
== DW_TAG_template_type_param
15166 || child_die
->tag
== DW_TAG_template_value_param
)
15168 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15171 template_args
->push_back (arg
);
15173 else if (child_die
->tag
== DW_TAG_variant
)
15175 /* In a variant we want to get the discriminant and also add a
15176 field for our sole member child. */
15177 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15179 for (die_info
*variant_child
= child_die
->child
;
15180 variant_child
!= NULL
;
15181 variant_child
= variant_child
->sibling
)
15183 if (variant_child
->tag
== DW_TAG_member
)
15185 handle_struct_member_die (variant_child
, type
, fi
,
15186 template_args
, cu
);
15187 /* Only handle the one. */
15192 /* We don't handle this but we might as well report it if we see
15194 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15195 complaint (_("DW_AT_discr_list is not supported yet"
15196 " - DIE at %s [in module %s]"),
15197 sect_offset_str (child_die
->sect_off
),
15198 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15200 /* The first field was just added, so we can stash the
15201 discriminant there. */
15202 gdb_assert (!fi
->fields
.empty ());
15204 fi
->fields
.back ().variant
.default_branch
= true;
15206 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15210 /* Finish creating a structure or union type, including filling in
15211 its members and creating a symbol for it. */
15214 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15216 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15217 struct die_info
*child_die
;
15220 type
= get_die_type (die
, cu
);
15222 type
= read_structure_type (die
, cu
);
15224 /* When reading a DW_TAG_variant_part, we need to notice when we
15225 read the discriminant member, so we can record it later in the
15226 discriminant_info. */
15227 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15228 sect_offset discr_offset
{};
15229 bool has_template_parameters
= false;
15231 if (is_variant_part
)
15233 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15236 /* Maybe it's a univariant form, an extension we support.
15237 In this case arrange not to check the offset. */
15238 is_variant_part
= false;
15240 else if (discr
->form_is_ref ())
15242 struct dwarf2_cu
*target_cu
= cu
;
15243 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15245 discr_offset
= target_die
->sect_off
;
15249 complaint (_("DW_AT_discr does not have DIE reference form"
15250 " - DIE at %s [in module %s]"),
15251 sect_offset_str (die
->sect_off
),
15252 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15253 is_variant_part
= false;
15257 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15259 struct field_info fi
;
15260 std::vector
<struct symbol
*> template_args
;
15262 child_die
= die
->child
;
15264 while (child_die
&& child_die
->tag
)
15266 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15268 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15269 fi
.fields
.back ().variant
.is_discriminant
= true;
15271 child_die
= child_die
->sibling
;
15274 /* Attach template arguments to type. */
15275 if (!template_args
.empty ())
15277 has_template_parameters
= true;
15278 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15279 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15280 TYPE_TEMPLATE_ARGUMENTS (type
)
15281 = XOBNEWVEC (&objfile
->objfile_obstack
,
15283 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15284 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15285 template_args
.data (),
15286 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15287 * sizeof (struct symbol
*)));
15290 /* Attach fields and member functions to the type. */
15291 if (fi
.nfields () > 0)
15292 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15293 if (!fi
.fnfieldlists
.empty ())
15295 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15297 /* Get the type which refers to the base class (possibly this
15298 class itself) which contains the vtable pointer for the current
15299 class from the DW_AT_containing_type attribute. This use of
15300 DW_AT_containing_type is a GNU extension. */
15302 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15304 struct type
*t
= die_containing_type (die
, cu
);
15306 set_type_vptr_basetype (type
, t
);
15311 /* Our own class provides vtbl ptr. */
15312 for (i
= TYPE_NFIELDS (t
) - 1;
15313 i
>= TYPE_N_BASECLASSES (t
);
15316 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15318 if (is_vtable_name (fieldname
, cu
))
15320 set_type_vptr_fieldno (type
, i
);
15325 /* Complain if virtual function table field not found. */
15326 if (i
< TYPE_N_BASECLASSES (t
))
15327 complaint (_("virtual function table pointer "
15328 "not found when defining class '%s'"),
15329 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15333 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15336 else if (cu
->producer
15337 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15339 /* The IBM XLC compiler does not provide direct indication
15340 of the containing type, but the vtable pointer is
15341 always named __vfp. */
15345 for (i
= TYPE_NFIELDS (type
) - 1;
15346 i
>= TYPE_N_BASECLASSES (type
);
15349 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15351 set_type_vptr_fieldno (type
, i
);
15352 set_type_vptr_basetype (type
, type
);
15359 /* Copy fi.typedef_field_list linked list elements content into the
15360 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15361 if (!fi
.typedef_field_list
.empty ())
15363 int count
= fi
.typedef_field_list
.size ();
15365 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15366 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15367 = ((struct decl_field
*)
15369 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15370 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15372 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15373 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15376 /* Copy fi.nested_types_list linked list elements content into the
15377 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15378 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15380 int count
= fi
.nested_types_list
.size ();
15382 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15383 TYPE_NESTED_TYPES_ARRAY (type
)
15384 = ((struct decl_field
*)
15385 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15386 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15388 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15389 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15393 quirk_gcc_member_function_pointer (type
, objfile
);
15394 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15395 cu
->rust_unions
.push_back (type
);
15397 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15398 snapshots) has been known to create a die giving a declaration
15399 for a class that has, as a child, a die giving a definition for a
15400 nested class. So we have to process our children even if the
15401 current die is a declaration. Normally, of course, a declaration
15402 won't have any children at all. */
15404 child_die
= die
->child
;
15406 while (child_die
!= NULL
&& child_die
->tag
)
15408 if (child_die
->tag
== DW_TAG_member
15409 || child_die
->tag
== DW_TAG_variable
15410 || child_die
->tag
== DW_TAG_inheritance
15411 || child_die
->tag
== DW_TAG_template_value_param
15412 || child_die
->tag
== DW_TAG_template_type_param
)
15417 process_die (child_die
, cu
);
15419 child_die
= child_die
->sibling
;
15422 /* Do not consider external references. According to the DWARF standard,
15423 these DIEs are identified by the fact that they have no byte_size
15424 attribute, and a declaration attribute. */
15425 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15426 || !die_is_declaration (die
, cu
))
15428 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15430 if (has_template_parameters
)
15432 struct symtab
*symtab
;
15433 if (sym
!= nullptr)
15434 symtab
= symbol_symtab (sym
);
15435 else if (cu
->line_header
!= nullptr)
15437 /* Any related symtab will do. */
15439 = cu
->line_header
->file_names ()[0].symtab
;
15444 complaint (_("could not find suitable "
15445 "symtab for template parameter"
15446 " - DIE at %s [in module %s]"),
15447 sect_offset_str (die
->sect_off
),
15448 objfile_name (objfile
));
15451 if (symtab
!= nullptr)
15453 /* Make sure that the symtab is set on the new symbols.
15454 Even though they don't appear in this symtab directly,
15455 other parts of gdb assume that symbols do, and this is
15456 reasonably true. */
15457 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15458 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15464 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15465 update TYPE using some information only available in DIE's children. */
15468 update_enumeration_type_from_children (struct die_info
*die
,
15470 struct dwarf2_cu
*cu
)
15472 struct die_info
*child_die
;
15473 int unsigned_enum
= 1;
15476 auto_obstack obstack
;
15478 for (child_die
= die
->child
;
15479 child_die
!= NULL
&& child_die
->tag
;
15480 child_die
= child_die
->sibling
)
15482 struct attribute
*attr
;
15484 const gdb_byte
*bytes
;
15485 struct dwarf2_locexpr_baton
*baton
;
15488 if (child_die
->tag
!= DW_TAG_enumerator
)
15491 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15495 name
= dwarf2_name (child_die
, cu
);
15497 name
= "<anonymous enumerator>";
15499 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15500 &value
, &bytes
, &baton
);
15508 if (count_one_bits_ll (value
) >= 2)
15512 /* If we already know that the enum type is neither unsigned, nor
15513 a flag type, no need to look at the rest of the enumerates. */
15514 if (!unsigned_enum
&& !flag_enum
)
15519 TYPE_UNSIGNED (type
) = 1;
15521 TYPE_FLAG_ENUM (type
) = 1;
15524 /* Given a DW_AT_enumeration_type die, set its type. We do not
15525 complete the type's fields yet, or create any symbols. */
15527 static struct type
*
15528 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15530 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15532 struct attribute
*attr
;
15535 /* If the definition of this type lives in .debug_types, read that type.
15536 Don't follow DW_AT_specification though, that will take us back up
15537 the chain and we want to go down. */
15538 attr
= die
->attr (DW_AT_signature
);
15539 if (attr
!= nullptr)
15541 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15543 /* The type's CU may not be the same as CU.
15544 Ensure TYPE is recorded with CU in die_type_hash. */
15545 return set_die_type (die
, type
, cu
);
15548 type
= alloc_type (objfile
);
15550 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15551 name
= dwarf2_full_name (NULL
, die
, cu
);
15553 TYPE_NAME (type
) = name
;
15555 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15558 struct type
*underlying_type
= die_type (die
, cu
);
15560 TYPE_TARGET_TYPE (type
) = underlying_type
;
15563 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15564 if (attr
!= nullptr)
15566 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15570 TYPE_LENGTH (type
) = 0;
15573 maybe_set_alignment (cu
, die
, type
);
15575 /* The enumeration DIE can be incomplete. In Ada, any type can be
15576 declared as private in the package spec, and then defined only
15577 inside the package body. Such types are known as Taft Amendment
15578 Types. When another package uses such a type, an incomplete DIE
15579 may be generated by the compiler. */
15580 if (die_is_declaration (die
, cu
))
15581 TYPE_STUB (type
) = 1;
15583 /* Finish the creation of this type by using the enum's children.
15584 We must call this even when the underlying type has been provided
15585 so that we can determine if we're looking at a "flag" enum. */
15586 update_enumeration_type_from_children (die
, type
, cu
);
15588 /* If this type has an underlying type that is not a stub, then we
15589 may use its attributes. We always use the "unsigned" attribute
15590 in this situation, because ordinarily we guess whether the type
15591 is unsigned -- but the guess can be wrong and the underlying type
15592 can tell us the reality. However, we defer to a local size
15593 attribute if one exists, because this lets the compiler override
15594 the underlying type if needed. */
15595 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15597 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
15598 underlying_type
= check_typedef (underlying_type
);
15599 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
15600 if (TYPE_LENGTH (type
) == 0)
15601 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
15602 if (TYPE_RAW_ALIGN (type
) == 0
15603 && TYPE_RAW_ALIGN (underlying_type
) != 0)
15604 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
15607 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15609 return set_die_type (die
, type
, cu
);
15612 /* Given a pointer to a die which begins an enumeration, process all
15613 the dies that define the members of the enumeration, and create the
15614 symbol for the enumeration type.
15616 NOTE: We reverse the order of the element list. */
15619 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15621 struct type
*this_type
;
15623 this_type
= get_die_type (die
, cu
);
15624 if (this_type
== NULL
)
15625 this_type
= read_enumeration_type (die
, cu
);
15627 if (die
->child
!= NULL
)
15629 struct die_info
*child_die
;
15630 struct symbol
*sym
;
15631 std::vector
<struct field
> fields
;
15634 child_die
= die
->child
;
15635 while (child_die
&& child_die
->tag
)
15637 if (child_die
->tag
!= DW_TAG_enumerator
)
15639 process_die (child_die
, cu
);
15643 name
= dwarf2_name (child_die
, cu
);
15646 sym
= new_symbol (child_die
, this_type
, cu
);
15648 fields
.emplace_back ();
15649 struct field
&field
= fields
.back ();
15651 FIELD_NAME (field
) = sym
->linkage_name ();
15652 FIELD_TYPE (field
) = NULL
;
15653 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15654 FIELD_BITSIZE (field
) = 0;
15658 child_die
= child_die
->sibling
;
15661 if (!fields
.empty ())
15663 TYPE_NFIELDS (this_type
) = fields
.size ();
15664 TYPE_FIELDS (this_type
) = (struct field
*)
15665 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15666 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15667 sizeof (struct field
) * fields
.size ());
15671 /* If we are reading an enum from a .debug_types unit, and the enum
15672 is a declaration, and the enum is not the signatured type in the
15673 unit, then we do not want to add a symbol for it. Adding a
15674 symbol would in some cases obscure the true definition of the
15675 enum, giving users an incomplete type when the definition is
15676 actually available. Note that we do not want to do this for all
15677 enums which are just declarations, because C++0x allows forward
15678 enum declarations. */
15679 if (cu
->per_cu
->is_debug_types
15680 && die_is_declaration (die
, cu
))
15682 struct signatured_type
*sig_type
;
15684 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15685 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15686 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15690 new_symbol (die
, this_type
, cu
);
15693 /* Extract all information from a DW_TAG_array_type DIE and put it in
15694 the DIE's type field. For now, this only handles one dimensional
15697 static struct type
*
15698 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15700 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15701 struct die_info
*child_die
;
15703 struct type
*element_type
, *range_type
, *index_type
;
15704 struct attribute
*attr
;
15706 struct dynamic_prop
*byte_stride_prop
= NULL
;
15707 unsigned int bit_stride
= 0;
15709 element_type
= die_type (die
, cu
);
15711 /* The die_type call above may have already set the type for this DIE. */
15712 type
= get_die_type (die
, cu
);
15716 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15720 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15723 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15724 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15728 complaint (_("unable to read array DW_AT_byte_stride "
15729 " - DIE at %s [in module %s]"),
15730 sect_offset_str (die
->sect_off
),
15731 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15732 /* Ignore this attribute. We will likely not be able to print
15733 arrays of this type correctly, but there is little we can do
15734 to help if we cannot read the attribute's value. */
15735 byte_stride_prop
= NULL
;
15739 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15741 bit_stride
= DW_UNSND (attr
);
15743 /* Irix 6.2 native cc creates array types without children for
15744 arrays with unspecified length. */
15745 if (die
->child
== NULL
)
15747 index_type
= objfile_type (objfile
)->builtin_int
;
15748 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15749 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15750 byte_stride_prop
, bit_stride
);
15751 return set_die_type (die
, type
, cu
);
15754 std::vector
<struct type
*> range_types
;
15755 child_die
= die
->child
;
15756 while (child_die
&& child_die
->tag
)
15758 if (child_die
->tag
== DW_TAG_subrange_type
)
15760 struct type
*child_type
= read_type_die (child_die
, cu
);
15762 if (child_type
!= NULL
)
15764 /* The range type was succesfully read. Save it for the
15765 array type creation. */
15766 range_types
.push_back (child_type
);
15769 child_die
= child_die
->sibling
;
15772 /* Dwarf2 dimensions are output from left to right, create the
15773 necessary array types in backwards order. */
15775 type
= element_type
;
15777 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15781 while (i
< range_types
.size ())
15782 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15783 byte_stride_prop
, bit_stride
);
15787 size_t ndim
= range_types
.size ();
15789 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15790 byte_stride_prop
, bit_stride
);
15793 /* Understand Dwarf2 support for vector types (like they occur on
15794 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15795 array type. This is not part of the Dwarf2/3 standard yet, but a
15796 custom vendor extension. The main difference between a regular
15797 array and the vector variant is that vectors are passed by value
15799 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15800 if (attr
!= nullptr)
15801 make_vector_type (type
);
15803 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15804 implementation may choose to implement triple vectors using this
15806 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15807 if (attr
!= nullptr)
15809 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15810 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15812 complaint (_("DW_AT_byte_size for array type smaller "
15813 "than the total size of elements"));
15816 name
= dwarf2_name (die
, cu
);
15818 TYPE_NAME (type
) = name
;
15820 maybe_set_alignment (cu
, die
, type
);
15822 /* Install the type in the die. */
15823 set_die_type (die
, type
, cu
);
15825 /* set_die_type should be already done. */
15826 set_descriptive_type (type
, die
, cu
);
15831 static enum dwarf_array_dim_ordering
15832 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15834 struct attribute
*attr
;
15836 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15838 if (attr
!= nullptr)
15839 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15841 /* GNU F77 is a special case, as at 08/2004 array type info is the
15842 opposite order to the dwarf2 specification, but data is still
15843 laid out as per normal fortran.
15845 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15846 version checking. */
15848 if (cu
->language
== language_fortran
15849 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15851 return DW_ORD_row_major
;
15854 switch (cu
->language_defn
->la_array_ordering
)
15856 case array_column_major
:
15857 return DW_ORD_col_major
;
15858 case array_row_major
:
15860 return DW_ORD_row_major
;
15864 /* Extract all information from a DW_TAG_set_type DIE and put it in
15865 the DIE's type field. */
15867 static struct type
*
15868 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15870 struct type
*domain_type
, *set_type
;
15871 struct attribute
*attr
;
15873 domain_type
= die_type (die
, cu
);
15875 /* The die_type call above may have already set the type for this DIE. */
15876 set_type
= get_die_type (die
, cu
);
15880 set_type
= create_set_type (NULL
, domain_type
);
15882 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15883 if (attr
!= nullptr)
15884 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15886 maybe_set_alignment (cu
, die
, set_type
);
15888 return set_die_type (die
, set_type
, cu
);
15891 /* A helper for read_common_block that creates a locexpr baton.
15892 SYM is the symbol which we are marking as computed.
15893 COMMON_DIE is the DIE for the common block.
15894 COMMON_LOC is the location expression attribute for the common
15896 MEMBER_LOC is the location expression attribute for the particular
15897 member of the common block that we are processing.
15898 CU is the CU from which the above come. */
15901 mark_common_block_symbol_computed (struct symbol
*sym
,
15902 struct die_info
*common_die
,
15903 struct attribute
*common_loc
,
15904 struct attribute
*member_loc
,
15905 struct dwarf2_cu
*cu
)
15907 struct dwarf2_per_objfile
*dwarf2_per_objfile
15908 = cu
->per_cu
->dwarf2_per_objfile
;
15909 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15910 struct dwarf2_locexpr_baton
*baton
;
15912 unsigned int cu_off
;
15913 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15914 LONGEST offset
= 0;
15916 gdb_assert (common_loc
&& member_loc
);
15917 gdb_assert (common_loc
->form_is_block ());
15918 gdb_assert (member_loc
->form_is_block ()
15919 || member_loc
->form_is_constant ());
15921 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15922 baton
->per_cu
= cu
->per_cu
;
15923 gdb_assert (baton
->per_cu
);
15925 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15927 if (member_loc
->form_is_constant ())
15929 offset
= member_loc
->constant_value (0);
15930 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15933 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15935 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15938 *ptr
++ = DW_OP_call4
;
15939 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15940 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15943 if (member_loc
->form_is_constant ())
15945 *ptr
++ = DW_OP_addr
;
15946 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15947 ptr
+= cu
->header
.addr_size
;
15951 /* We have to copy the data here, because DW_OP_call4 will only
15952 use a DW_AT_location attribute. */
15953 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15954 ptr
+= DW_BLOCK (member_loc
)->size
;
15957 *ptr
++ = DW_OP_plus
;
15958 gdb_assert (ptr
- baton
->data
== baton
->size
);
15960 SYMBOL_LOCATION_BATON (sym
) = baton
;
15961 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15964 /* Create appropriate locally-scoped variables for all the
15965 DW_TAG_common_block entries. Also create a struct common_block
15966 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15967 is used to separate the common blocks name namespace from regular
15971 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15973 struct attribute
*attr
;
15975 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15976 if (attr
!= nullptr)
15978 /* Support the .debug_loc offsets. */
15979 if (attr
->form_is_block ())
15983 else if (attr
->form_is_section_offset ())
15985 dwarf2_complex_location_expr_complaint ();
15990 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15991 "common block member");
15996 if (die
->child
!= NULL
)
15998 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15999 struct die_info
*child_die
;
16000 size_t n_entries
= 0, size
;
16001 struct common_block
*common_block
;
16002 struct symbol
*sym
;
16004 for (child_die
= die
->child
;
16005 child_die
&& child_die
->tag
;
16006 child_die
= child_die
->sibling
)
16009 size
= (sizeof (struct common_block
)
16010 + (n_entries
- 1) * sizeof (struct symbol
*));
16012 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16014 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16015 common_block
->n_entries
= 0;
16017 for (child_die
= die
->child
;
16018 child_die
&& child_die
->tag
;
16019 child_die
= child_die
->sibling
)
16021 /* Create the symbol in the DW_TAG_common_block block in the current
16023 sym
= new_symbol (child_die
, NULL
, cu
);
16026 struct attribute
*member_loc
;
16028 common_block
->contents
[common_block
->n_entries
++] = sym
;
16030 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16034 /* GDB has handled this for a long time, but it is
16035 not specified by DWARF. It seems to have been
16036 emitted by gfortran at least as recently as:
16037 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16038 complaint (_("Variable in common block has "
16039 "DW_AT_data_member_location "
16040 "- DIE at %s [in module %s]"),
16041 sect_offset_str (child_die
->sect_off
),
16042 objfile_name (objfile
));
16044 if (member_loc
->form_is_section_offset ())
16045 dwarf2_complex_location_expr_complaint ();
16046 else if (member_loc
->form_is_constant ()
16047 || member_loc
->form_is_block ())
16049 if (attr
!= nullptr)
16050 mark_common_block_symbol_computed (sym
, die
, attr
,
16054 dwarf2_complex_location_expr_complaint ();
16059 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16060 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16064 /* Create a type for a C++ namespace. */
16066 static struct type
*
16067 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16069 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16070 const char *previous_prefix
, *name
;
16074 /* For extensions, reuse the type of the original namespace. */
16075 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16077 struct die_info
*ext_die
;
16078 struct dwarf2_cu
*ext_cu
= cu
;
16080 ext_die
= dwarf2_extension (die
, &ext_cu
);
16081 type
= read_type_die (ext_die
, ext_cu
);
16083 /* EXT_CU may not be the same as CU.
16084 Ensure TYPE is recorded with CU in die_type_hash. */
16085 return set_die_type (die
, type
, cu
);
16088 name
= namespace_name (die
, &is_anonymous
, cu
);
16090 /* Now build the name of the current namespace. */
16092 previous_prefix
= determine_prefix (die
, cu
);
16093 if (previous_prefix
[0] != '\0')
16094 name
= typename_concat (&objfile
->objfile_obstack
,
16095 previous_prefix
, name
, 0, cu
);
16097 /* Create the type. */
16098 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16100 return set_die_type (die
, type
, cu
);
16103 /* Read a namespace scope. */
16106 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16108 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16111 /* Add a symbol associated to this if we haven't seen the namespace
16112 before. Also, add a using directive if it's an anonymous
16115 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16119 type
= read_type_die (die
, cu
);
16120 new_symbol (die
, type
, cu
);
16122 namespace_name (die
, &is_anonymous
, cu
);
16125 const char *previous_prefix
= determine_prefix (die
, cu
);
16127 std::vector
<const char *> excludes
;
16128 add_using_directive (using_directives (cu
),
16129 previous_prefix
, TYPE_NAME (type
), NULL
,
16130 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16134 if (die
->child
!= NULL
)
16136 struct die_info
*child_die
= die
->child
;
16138 while (child_die
&& child_die
->tag
)
16140 process_die (child_die
, cu
);
16141 child_die
= child_die
->sibling
;
16146 /* Read a Fortran module as type. This DIE can be only a declaration used for
16147 imported module. Still we need that type as local Fortran "use ... only"
16148 declaration imports depend on the created type in determine_prefix. */
16150 static struct type
*
16151 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16153 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16154 const char *module_name
;
16157 module_name
= dwarf2_name (die
, cu
);
16158 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16160 return set_die_type (die
, type
, cu
);
16163 /* Read a Fortran module. */
16166 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16168 struct die_info
*child_die
= die
->child
;
16171 type
= read_type_die (die
, cu
);
16172 new_symbol (die
, type
, cu
);
16174 while (child_die
&& child_die
->tag
)
16176 process_die (child_die
, cu
);
16177 child_die
= child_die
->sibling
;
16181 /* Return the name of the namespace represented by DIE. Set
16182 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16185 static const char *
16186 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16188 struct die_info
*current_die
;
16189 const char *name
= NULL
;
16191 /* Loop through the extensions until we find a name. */
16193 for (current_die
= die
;
16194 current_die
!= NULL
;
16195 current_die
= dwarf2_extension (die
, &cu
))
16197 /* We don't use dwarf2_name here so that we can detect the absence
16198 of a name -> anonymous namespace. */
16199 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16205 /* Is it an anonymous namespace? */
16207 *is_anonymous
= (name
== NULL
);
16209 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16214 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16215 the user defined type vector. */
16217 static struct type
*
16218 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16220 struct gdbarch
*gdbarch
16221 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16222 struct comp_unit_head
*cu_header
= &cu
->header
;
16224 struct attribute
*attr_byte_size
;
16225 struct attribute
*attr_address_class
;
16226 int byte_size
, addr_class
;
16227 struct type
*target_type
;
16229 target_type
= die_type (die
, cu
);
16231 /* The die_type call above may have already set the type for this DIE. */
16232 type
= get_die_type (die
, cu
);
16236 type
= lookup_pointer_type (target_type
);
16238 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16239 if (attr_byte_size
)
16240 byte_size
= DW_UNSND (attr_byte_size
);
16242 byte_size
= cu_header
->addr_size
;
16244 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16245 if (attr_address_class
)
16246 addr_class
= DW_UNSND (attr_address_class
);
16248 addr_class
= DW_ADDR_none
;
16250 ULONGEST alignment
= get_alignment (cu
, die
);
16252 /* If the pointer size, alignment, or address class is different
16253 than the default, create a type variant marked as such and set
16254 the length accordingly. */
16255 if (TYPE_LENGTH (type
) != byte_size
16256 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16257 && alignment
!= TYPE_RAW_ALIGN (type
))
16258 || addr_class
!= DW_ADDR_none
)
16260 if (gdbarch_address_class_type_flags_p (gdbarch
))
16264 type_flags
= gdbarch_address_class_type_flags
16265 (gdbarch
, byte_size
, addr_class
);
16266 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16268 type
= make_type_with_address_space (type
, type_flags
);
16270 else if (TYPE_LENGTH (type
) != byte_size
)
16272 complaint (_("invalid pointer size %d"), byte_size
);
16274 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16276 complaint (_("Invalid DW_AT_alignment"
16277 " - DIE at %s [in module %s]"),
16278 sect_offset_str (die
->sect_off
),
16279 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16283 /* Should we also complain about unhandled address classes? */
16287 TYPE_LENGTH (type
) = byte_size
;
16288 set_type_align (type
, alignment
);
16289 return set_die_type (die
, type
, cu
);
16292 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16293 the user defined type vector. */
16295 static struct type
*
16296 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16299 struct type
*to_type
;
16300 struct type
*domain
;
16302 to_type
= die_type (die
, cu
);
16303 domain
= die_containing_type (die
, cu
);
16305 /* The calls above may have already set the type for this DIE. */
16306 type
= get_die_type (die
, cu
);
16310 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16311 type
= lookup_methodptr_type (to_type
);
16312 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16314 struct type
*new_type
16315 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16317 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16318 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16319 TYPE_VARARGS (to_type
));
16320 type
= lookup_methodptr_type (new_type
);
16323 type
= lookup_memberptr_type (to_type
, domain
);
16325 return set_die_type (die
, type
, cu
);
16328 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16329 the user defined type vector. */
16331 static struct type
*
16332 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16333 enum type_code refcode
)
16335 struct comp_unit_head
*cu_header
= &cu
->header
;
16336 struct type
*type
, *target_type
;
16337 struct attribute
*attr
;
16339 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16341 target_type
= die_type (die
, cu
);
16343 /* The die_type call above may have already set the type for this DIE. */
16344 type
= get_die_type (die
, cu
);
16348 type
= lookup_reference_type (target_type
, refcode
);
16349 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16350 if (attr
!= nullptr)
16352 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16356 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16358 maybe_set_alignment (cu
, die
, type
);
16359 return set_die_type (die
, type
, cu
);
16362 /* Add the given cv-qualifiers to the element type of the array. GCC
16363 outputs DWARF type qualifiers that apply to an array, not the
16364 element type. But GDB relies on the array element type to carry
16365 the cv-qualifiers. This mimics section 6.7.3 of the C99
16368 static struct type
*
16369 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16370 struct type
*base_type
, int cnst
, int voltl
)
16372 struct type
*el_type
, *inner_array
;
16374 base_type
= copy_type (base_type
);
16375 inner_array
= base_type
;
16377 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16379 TYPE_TARGET_TYPE (inner_array
) =
16380 copy_type (TYPE_TARGET_TYPE (inner_array
));
16381 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16384 el_type
= TYPE_TARGET_TYPE (inner_array
);
16385 cnst
|= TYPE_CONST (el_type
);
16386 voltl
|= TYPE_VOLATILE (el_type
);
16387 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16389 return set_die_type (die
, base_type
, cu
);
16392 static struct type
*
16393 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16395 struct type
*base_type
, *cv_type
;
16397 base_type
= die_type (die
, cu
);
16399 /* The die_type call above may have already set the type for this DIE. */
16400 cv_type
= get_die_type (die
, cu
);
16404 /* In case the const qualifier is applied to an array type, the element type
16405 is so qualified, not the array type (section 6.7.3 of C99). */
16406 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16407 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16409 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16410 return set_die_type (die
, cv_type
, cu
);
16413 static struct type
*
16414 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16416 struct type
*base_type
, *cv_type
;
16418 base_type
= die_type (die
, cu
);
16420 /* The die_type call above may have already set the type for this DIE. */
16421 cv_type
= get_die_type (die
, cu
);
16425 /* In case the volatile qualifier is applied to an array type, the
16426 element type is so qualified, not the array type (section 6.7.3
16428 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16429 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16431 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16432 return set_die_type (die
, cv_type
, cu
);
16435 /* Handle DW_TAG_restrict_type. */
16437 static struct type
*
16438 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16440 struct type
*base_type
, *cv_type
;
16442 base_type
= die_type (die
, cu
);
16444 /* The die_type call above may have already set the type for this DIE. */
16445 cv_type
= get_die_type (die
, cu
);
16449 cv_type
= make_restrict_type (base_type
);
16450 return set_die_type (die
, cv_type
, cu
);
16453 /* Handle DW_TAG_atomic_type. */
16455 static struct type
*
16456 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16458 struct type
*base_type
, *cv_type
;
16460 base_type
= die_type (die
, cu
);
16462 /* The die_type call above may have already set the type for this DIE. */
16463 cv_type
= get_die_type (die
, cu
);
16467 cv_type
= make_atomic_type (base_type
);
16468 return set_die_type (die
, cv_type
, cu
);
16471 /* Extract all information from a DW_TAG_string_type DIE and add to
16472 the user defined type vector. It isn't really a user defined type,
16473 but it behaves like one, with other DIE's using an AT_user_def_type
16474 attribute to reference it. */
16476 static struct type
*
16477 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16479 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16480 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16481 struct type
*type
, *range_type
, *index_type
, *char_type
;
16482 struct attribute
*attr
;
16483 struct dynamic_prop prop
;
16484 bool length_is_constant
= true;
16487 /* There are a couple of places where bit sizes might be made use of
16488 when parsing a DW_TAG_string_type, however, no producer that we know
16489 of make use of these. Handling bit sizes that are a multiple of the
16490 byte size is easy enough, but what about other bit sizes? Lets deal
16491 with that problem when we have to. Warn about these attributes being
16492 unsupported, then parse the type and ignore them like we always
16494 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16495 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16497 static bool warning_printed
= false;
16498 if (!warning_printed
)
16500 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16501 "currently supported on DW_TAG_string_type."));
16502 warning_printed
= true;
16506 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16507 if (attr
!= nullptr && !attr
->form_is_constant ())
16509 /* The string length describes the location at which the length of
16510 the string can be found. The size of the length field can be
16511 specified with one of the attributes below. */
16512 struct type
*prop_type
;
16513 struct attribute
*len
16514 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16515 if (len
== nullptr)
16516 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16517 if (len
!= nullptr && len
->form_is_constant ())
16519 /* Pass 0 as the default as we know this attribute is constant
16520 and the default value will not be returned. */
16521 LONGEST sz
= len
->constant_value (0);
16522 prop_type
= cu
->per_cu
->int_type (sz
, true);
16526 /* If the size is not specified then we assume it is the size of
16527 an address on this target. */
16528 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16531 /* Convert the attribute into a dynamic property. */
16532 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16535 length_is_constant
= false;
16537 else if (attr
!= nullptr)
16539 /* This DW_AT_string_length just contains the length with no
16540 indirection. There's no need to create a dynamic property in this
16541 case. Pass 0 for the default value as we know it will not be
16542 returned in this case. */
16543 length
= attr
->constant_value (0);
16545 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16547 /* We don't currently support non-constant byte sizes for strings. */
16548 length
= attr
->constant_value (1);
16552 /* Use 1 as a fallback length if we have nothing else. */
16556 index_type
= objfile_type (objfile
)->builtin_int
;
16557 if (length_is_constant
)
16558 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16561 struct dynamic_prop low_bound
;
16563 low_bound
.kind
= PROP_CONST
;
16564 low_bound
.data
.const_val
= 1;
16565 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16567 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16568 type
= create_string_type (NULL
, char_type
, range_type
);
16570 return set_die_type (die
, type
, cu
);
16573 /* Assuming that DIE corresponds to a function, returns nonzero
16574 if the function is prototyped. */
16577 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16579 struct attribute
*attr
;
16581 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16582 if (attr
&& (DW_UNSND (attr
) != 0))
16585 /* The DWARF standard implies that the DW_AT_prototyped attribute
16586 is only meaningful for C, but the concept also extends to other
16587 languages that allow unprototyped functions (Eg: Objective C).
16588 For all other languages, assume that functions are always
16590 if (cu
->language
!= language_c
16591 && cu
->language
!= language_objc
16592 && cu
->language
!= language_opencl
)
16595 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16596 prototyped and unprototyped functions; default to prototyped,
16597 since that is more common in modern code (and RealView warns
16598 about unprototyped functions). */
16599 if (producer_is_realview (cu
->producer
))
16605 /* Handle DIES due to C code like:
16609 int (*funcp)(int a, long l);
16613 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16615 static struct type
*
16616 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16618 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16619 struct type
*type
; /* Type that this function returns. */
16620 struct type
*ftype
; /* Function that returns above type. */
16621 struct attribute
*attr
;
16623 type
= die_type (die
, cu
);
16625 /* The die_type call above may have already set the type for this DIE. */
16626 ftype
= get_die_type (die
, cu
);
16630 ftype
= lookup_function_type (type
);
16632 if (prototyped_function_p (die
, cu
))
16633 TYPE_PROTOTYPED (ftype
) = 1;
16635 /* Store the calling convention in the type if it's available in
16636 the subroutine die. Otherwise set the calling convention to
16637 the default value DW_CC_normal. */
16638 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16639 if (attr
!= nullptr
16640 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16641 TYPE_CALLING_CONVENTION (ftype
)
16642 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16643 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16644 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16646 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16648 /* Record whether the function returns normally to its caller or not
16649 if the DWARF producer set that information. */
16650 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16651 if (attr
&& (DW_UNSND (attr
) != 0))
16652 TYPE_NO_RETURN (ftype
) = 1;
16654 /* We need to add the subroutine type to the die immediately so
16655 we don't infinitely recurse when dealing with parameters
16656 declared as the same subroutine type. */
16657 set_die_type (die
, ftype
, cu
);
16659 if (die
->child
!= NULL
)
16661 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16662 struct die_info
*child_die
;
16663 int nparams
, iparams
;
16665 /* Count the number of parameters.
16666 FIXME: GDB currently ignores vararg functions, but knows about
16667 vararg member functions. */
16669 child_die
= die
->child
;
16670 while (child_die
&& child_die
->tag
)
16672 if (child_die
->tag
== DW_TAG_formal_parameter
)
16674 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16675 TYPE_VARARGS (ftype
) = 1;
16676 child_die
= child_die
->sibling
;
16679 /* Allocate storage for parameters and fill them in. */
16680 TYPE_NFIELDS (ftype
) = nparams
;
16681 TYPE_FIELDS (ftype
) = (struct field
*)
16682 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16684 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16685 even if we error out during the parameters reading below. */
16686 for (iparams
= 0; iparams
< nparams
; iparams
++)
16687 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16690 child_die
= die
->child
;
16691 while (child_die
&& child_die
->tag
)
16693 if (child_die
->tag
== DW_TAG_formal_parameter
)
16695 struct type
*arg_type
;
16697 /* DWARF version 2 has no clean way to discern C++
16698 static and non-static member functions. G++ helps
16699 GDB by marking the first parameter for non-static
16700 member functions (which is the this pointer) as
16701 artificial. We pass this information to
16702 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16704 DWARF version 3 added DW_AT_object_pointer, which GCC
16705 4.5 does not yet generate. */
16706 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16707 if (attr
!= nullptr)
16708 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16710 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16711 arg_type
= die_type (child_die
, cu
);
16713 /* RealView does not mark THIS as const, which the testsuite
16714 expects. GCC marks THIS as const in method definitions,
16715 but not in the class specifications (GCC PR 43053). */
16716 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16717 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16720 struct dwarf2_cu
*arg_cu
= cu
;
16721 const char *name
= dwarf2_name (child_die
, cu
);
16723 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16724 if (attr
!= nullptr)
16726 /* If the compiler emits this, use it. */
16727 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16730 else if (name
&& strcmp (name
, "this") == 0)
16731 /* Function definitions will have the argument names. */
16733 else if (name
== NULL
&& iparams
== 0)
16734 /* Declarations may not have the names, so like
16735 elsewhere in GDB, assume an artificial first
16736 argument is "this". */
16740 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16744 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16747 child_die
= child_die
->sibling
;
16754 static struct type
*
16755 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16757 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16758 const char *name
= NULL
;
16759 struct type
*this_type
, *target_type
;
16761 name
= dwarf2_full_name (NULL
, die
, cu
);
16762 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16763 TYPE_TARGET_STUB (this_type
) = 1;
16764 set_die_type (die
, this_type
, cu
);
16765 target_type
= die_type (die
, cu
);
16766 if (target_type
!= this_type
)
16767 TYPE_TARGET_TYPE (this_type
) = target_type
;
16770 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16771 spec and cause infinite loops in GDB. */
16772 complaint (_("Self-referential DW_TAG_typedef "
16773 "- DIE at %s [in module %s]"),
16774 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16775 TYPE_TARGET_TYPE (this_type
) = NULL
;
16779 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16780 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16781 Handle these by just returning the target type, rather than
16782 constructing an anonymous typedef type and trying to handle this
16784 set_die_type (die
, target_type
, cu
);
16785 return target_type
;
16790 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16791 (which may be different from NAME) to the architecture back-end to allow
16792 it to guess the correct format if necessary. */
16794 static struct type
*
16795 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16796 const char *name_hint
, enum bfd_endian byte_order
)
16798 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16799 const struct floatformat
**format
;
16802 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16804 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16806 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16811 /* Allocate an integer type of size BITS and name NAME. */
16813 static struct type
*
16814 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16815 int bits
, int unsigned_p
, const char *name
)
16819 /* Versions of Intel's C Compiler generate an integer type called "void"
16820 instead of using DW_TAG_unspecified_type. This has been seen on
16821 at least versions 14, 17, and 18. */
16822 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16823 && strcmp (name
, "void") == 0)
16824 type
= objfile_type (objfile
)->builtin_void
;
16826 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16831 /* Initialise and return a floating point type of size BITS suitable for
16832 use as a component of a complex number. The NAME_HINT is passed through
16833 when initialising the floating point type and is the name of the complex
16836 As DWARF doesn't currently provide an explicit name for the components
16837 of a complex number, but it can be helpful to have these components
16838 named, we try to select a suitable name based on the size of the
16840 static struct type
*
16841 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16842 struct objfile
*objfile
,
16843 int bits
, const char *name_hint
,
16844 enum bfd_endian byte_order
)
16846 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16847 struct type
*tt
= nullptr;
16849 /* Try to find a suitable floating point builtin type of size BITS.
16850 We're going to use the name of this type as the name for the complex
16851 target type that we are about to create. */
16852 switch (cu
->language
)
16854 case language_fortran
:
16858 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16861 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16863 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16865 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16873 tt
= builtin_type (gdbarch
)->builtin_float
;
16876 tt
= builtin_type (gdbarch
)->builtin_double
;
16878 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16880 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16886 /* If the type we found doesn't match the size we were looking for, then
16887 pretend we didn't find a type at all, the complex target type we
16888 create will then be nameless. */
16889 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16892 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16893 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16896 /* Find a representation of a given base type and install
16897 it in the TYPE field of the die. */
16899 static struct type
*
16900 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16902 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16904 struct attribute
*attr
;
16905 int encoding
= 0, bits
= 0;
16909 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16910 if (attr
!= nullptr)
16911 encoding
= DW_UNSND (attr
);
16912 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16913 if (attr
!= nullptr)
16914 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16915 name
= dwarf2_name (die
, cu
);
16917 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16919 arch
= get_objfile_arch (objfile
);
16920 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16922 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16925 int endianity
= DW_UNSND (attr
);
16930 byte_order
= BFD_ENDIAN_BIG
;
16932 case DW_END_little
:
16933 byte_order
= BFD_ENDIAN_LITTLE
;
16936 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16943 case DW_ATE_address
:
16944 /* Turn DW_ATE_address into a void * pointer. */
16945 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16946 type
= init_pointer_type (objfile
, bits
, name
, type
);
16948 case DW_ATE_boolean
:
16949 type
= init_boolean_type (objfile
, bits
, 1, name
);
16951 case DW_ATE_complex_float
:
16952 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16954 if (TYPE_CODE (type
) == TYPE_CODE_ERROR
)
16956 if (name
== nullptr)
16958 struct obstack
*obstack
16959 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
16960 name
= obconcat (obstack
, "_Complex ", TYPE_NAME (type
),
16963 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16966 type
= init_complex_type (name
, type
);
16968 case DW_ATE_decimal_float
:
16969 type
= init_decfloat_type (objfile
, bits
, name
);
16972 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16974 case DW_ATE_signed
:
16975 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16977 case DW_ATE_unsigned
:
16978 if (cu
->language
== language_fortran
16980 && startswith (name
, "character("))
16981 type
= init_character_type (objfile
, bits
, 1, name
);
16983 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16985 case DW_ATE_signed_char
:
16986 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16987 || cu
->language
== language_pascal
16988 || cu
->language
== language_fortran
)
16989 type
= init_character_type (objfile
, bits
, 0, name
);
16991 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16993 case DW_ATE_unsigned_char
:
16994 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16995 || cu
->language
== language_pascal
16996 || cu
->language
== language_fortran
16997 || cu
->language
== language_rust
)
16998 type
= init_character_type (objfile
, bits
, 1, name
);
17000 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17005 type
= builtin_type (arch
)->builtin_char16
;
17006 else if (bits
== 32)
17007 type
= builtin_type (arch
)->builtin_char32
;
17010 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17012 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17014 return set_die_type (die
, type
, cu
);
17019 complaint (_("unsupported DW_AT_encoding: '%s'"),
17020 dwarf_type_encoding_name (encoding
));
17021 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17025 if (name
&& strcmp (name
, "char") == 0)
17026 TYPE_NOSIGN (type
) = 1;
17028 maybe_set_alignment (cu
, die
, type
);
17030 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17032 return set_die_type (die
, type
, cu
);
17035 /* Parse dwarf attribute if it's a block, reference or constant and put the
17036 resulting value of the attribute into struct bound_prop.
17037 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17040 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17041 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17042 struct type
*default_type
)
17044 struct dwarf2_property_baton
*baton
;
17045 struct obstack
*obstack
17046 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17048 gdb_assert (default_type
!= NULL
);
17050 if (attr
== NULL
|| prop
== NULL
)
17053 if (attr
->form_is_block ())
17055 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17056 baton
->property_type
= default_type
;
17057 baton
->locexpr
.per_cu
= cu
->per_cu
;
17058 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17059 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17060 switch (attr
->name
)
17062 case DW_AT_string_length
:
17063 baton
->locexpr
.is_reference
= true;
17066 baton
->locexpr
.is_reference
= false;
17069 prop
->data
.baton
= baton
;
17070 prop
->kind
= PROP_LOCEXPR
;
17071 gdb_assert (prop
->data
.baton
!= NULL
);
17073 else if (attr
->form_is_ref ())
17075 struct dwarf2_cu
*target_cu
= cu
;
17076 struct die_info
*target_die
;
17077 struct attribute
*target_attr
;
17079 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17080 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17081 if (target_attr
== NULL
)
17082 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17084 if (target_attr
== NULL
)
17087 switch (target_attr
->name
)
17089 case DW_AT_location
:
17090 if (target_attr
->form_is_section_offset ())
17092 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17093 baton
->property_type
= die_type (target_die
, target_cu
);
17094 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17095 prop
->data
.baton
= baton
;
17096 prop
->kind
= PROP_LOCLIST
;
17097 gdb_assert (prop
->data
.baton
!= NULL
);
17099 else if (target_attr
->form_is_block ())
17101 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17102 baton
->property_type
= die_type (target_die
, target_cu
);
17103 baton
->locexpr
.per_cu
= cu
->per_cu
;
17104 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17105 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17106 baton
->locexpr
.is_reference
= true;
17107 prop
->data
.baton
= baton
;
17108 prop
->kind
= PROP_LOCEXPR
;
17109 gdb_assert (prop
->data
.baton
!= NULL
);
17113 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17114 "dynamic property");
17118 case DW_AT_data_member_location
:
17122 if (!handle_data_member_location (target_die
, target_cu
,
17126 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17127 baton
->property_type
= read_type_die (target_die
->parent
,
17129 baton
->offset_info
.offset
= offset
;
17130 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17131 prop
->data
.baton
= baton
;
17132 prop
->kind
= PROP_ADDR_OFFSET
;
17137 else if (attr
->form_is_constant ())
17139 prop
->data
.const_val
= attr
->constant_value (0);
17140 prop
->kind
= PROP_CONST
;
17144 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17145 dwarf2_name (die
, cu
));
17155 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17157 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17158 struct type
*int_type
;
17160 /* Helper macro to examine the various builtin types. */
17161 #define TRY_TYPE(F) \
17162 int_type = (unsigned_p \
17163 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17164 : objfile_type (objfile)->builtin_ ## F); \
17165 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17172 TRY_TYPE (long_long
);
17176 gdb_assert_not_reached ("unable to find suitable integer type");
17182 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17184 int addr_size
= this->addr_size ();
17185 return int_type (addr_size
, unsigned_p
);
17188 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17189 present (which is valid) then compute the default type based on the
17190 compilation units address size. */
17192 static struct type
*
17193 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17195 struct type
*index_type
= die_type (die
, cu
);
17197 /* Dwarf-2 specifications explicitly allows to create subrange types
17198 without specifying a base type.
17199 In that case, the base type must be set to the type of
17200 the lower bound, upper bound or count, in that order, if any of these
17201 three attributes references an object that has a type.
17202 If no base type is found, the Dwarf-2 specifications say that
17203 a signed integer type of size equal to the size of an address should
17205 For the following C code: `extern char gdb_int [];'
17206 GCC produces an empty range DIE.
17207 FIXME: muller/2010-05-28: Possible references to object for low bound,
17208 high bound or count are not yet handled by this code. */
17209 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17210 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17215 /* Read the given DW_AT_subrange DIE. */
17217 static struct type
*
17218 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17220 struct type
*base_type
, *orig_base_type
;
17221 struct type
*range_type
;
17222 struct attribute
*attr
;
17223 struct dynamic_prop low
, high
;
17224 int low_default_is_valid
;
17225 int high_bound_is_count
= 0;
17227 ULONGEST negative_mask
;
17229 orig_base_type
= read_subrange_index_type (die
, cu
);
17231 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17232 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17233 creating the range type, but we use the result of check_typedef
17234 when examining properties of the type. */
17235 base_type
= check_typedef (orig_base_type
);
17237 /* The die_type call above may have already set the type for this DIE. */
17238 range_type
= get_die_type (die
, cu
);
17242 low
.kind
= PROP_CONST
;
17243 high
.kind
= PROP_CONST
;
17244 high
.data
.const_val
= 0;
17246 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17247 omitting DW_AT_lower_bound. */
17248 switch (cu
->language
)
17251 case language_cplus
:
17252 low
.data
.const_val
= 0;
17253 low_default_is_valid
= 1;
17255 case language_fortran
:
17256 low
.data
.const_val
= 1;
17257 low_default_is_valid
= 1;
17260 case language_objc
:
17261 case language_rust
:
17262 low
.data
.const_val
= 0;
17263 low_default_is_valid
= (cu
->header
.version
>= 4);
17267 case language_pascal
:
17268 low
.data
.const_val
= 1;
17269 low_default_is_valid
= (cu
->header
.version
>= 4);
17272 low
.data
.const_val
= 0;
17273 low_default_is_valid
= 0;
17277 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17278 if (attr
!= nullptr)
17279 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17280 else if (!low_default_is_valid
)
17281 complaint (_("Missing DW_AT_lower_bound "
17282 "- DIE at %s [in module %s]"),
17283 sect_offset_str (die
->sect_off
),
17284 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17286 struct attribute
*attr_ub
, *attr_count
;
17287 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17288 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17290 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17291 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17293 /* If bounds are constant do the final calculation here. */
17294 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17295 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17297 high_bound_is_count
= 1;
17301 if (attr_ub
!= NULL
)
17302 complaint (_("Unresolved DW_AT_upper_bound "
17303 "- DIE at %s [in module %s]"),
17304 sect_offset_str (die
->sect_off
),
17305 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17306 if (attr_count
!= NULL
)
17307 complaint (_("Unresolved DW_AT_count "
17308 "- DIE at %s [in module %s]"),
17309 sect_offset_str (die
->sect_off
),
17310 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17315 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17316 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17317 bias
= bias_attr
->constant_value (0);
17319 /* Normally, the DWARF producers are expected to use a signed
17320 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17321 But this is unfortunately not always the case, as witnessed
17322 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17323 is used instead. To work around that ambiguity, we treat
17324 the bounds as signed, and thus sign-extend their values, when
17325 the base type is signed. */
17327 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17328 if (low
.kind
== PROP_CONST
17329 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17330 low
.data
.const_val
|= negative_mask
;
17331 if (high
.kind
== PROP_CONST
17332 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17333 high
.data
.const_val
|= negative_mask
;
17335 /* Check for bit and byte strides. */
17336 struct dynamic_prop byte_stride_prop
;
17337 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17338 if (attr_byte_stride
!= nullptr)
17340 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17341 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17345 struct dynamic_prop bit_stride_prop
;
17346 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17347 if (attr_bit_stride
!= nullptr)
17349 /* It only makes sense to have either a bit or byte stride. */
17350 if (attr_byte_stride
!= nullptr)
17352 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17353 "- DIE at %s [in module %s]"),
17354 sect_offset_str (die
->sect_off
),
17355 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17356 attr_bit_stride
= nullptr;
17360 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17361 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17366 if (attr_byte_stride
!= nullptr
17367 || attr_bit_stride
!= nullptr)
17369 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17370 struct dynamic_prop
*stride
17371 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17374 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17375 &high
, bias
, stride
, byte_stride_p
);
17378 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17380 if (high_bound_is_count
)
17381 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17383 /* Ada expects an empty array on no boundary attributes. */
17384 if (attr
== NULL
&& cu
->language
!= language_ada
)
17385 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17387 name
= dwarf2_name (die
, cu
);
17389 TYPE_NAME (range_type
) = name
;
17391 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17392 if (attr
!= nullptr)
17393 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17395 maybe_set_alignment (cu
, die
, range_type
);
17397 set_die_type (die
, range_type
, cu
);
17399 /* set_die_type should be already done. */
17400 set_descriptive_type (range_type
, die
, cu
);
17405 static struct type
*
17406 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17410 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17412 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17414 /* In Ada, an unspecified type is typically used when the description
17415 of the type is deferred to a different unit. When encountering
17416 such a type, we treat it as a stub, and try to resolve it later on,
17418 if (cu
->language
== language_ada
)
17419 TYPE_STUB (type
) = 1;
17421 return set_die_type (die
, type
, cu
);
17424 /* Read a single die and all its descendents. Set the die's sibling
17425 field to NULL; set other fields in the die correctly, and set all
17426 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17427 location of the info_ptr after reading all of those dies. PARENT
17428 is the parent of the die in question. */
17430 static struct die_info
*
17431 read_die_and_children (const struct die_reader_specs
*reader
,
17432 const gdb_byte
*info_ptr
,
17433 const gdb_byte
**new_info_ptr
,
17434 struct die_info
*parent
)
17436 struct die_info
*die
;
17437 const gdb_byte
*cur_ptr
;
17439 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17442 *new_info_ptr
= cur_ptr
;
17445 store_in_ref_table (die
, reader
->cu
);
17447 if (die
->has_children
)
17448 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17452 *new_info_ptr
= cur_ptr
;
17455 die
->sibling
= NULL
;
17456 die
->parent
= parent
;
17460 /* Read a die, all of its descendents, and all of its siblings; set
17461 all of the fields of all of the dies correctly. Arguments are as
17462 in read_die_and_children. */
17464 static struct die_info
*
17465 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17466 const gdb_byte
*info_ptr
,
17467 const gdb_byte
**new_info_ptr
,
17468 struct die_info
*parent
)
17470 struct die_info
*first_die
, *last_sibling
;
17471 const gdb_byte
*cur_ptr
;
17473 cur_ptr
= info_ptr
;
17474 first_die
= last_sibling
= NULL
;
17478 struct die_info
*die
17479 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17483 *new_info_ptr
= cur_ptr
;
17490 last_sibling
->sibling
= die
;
17492 last_sibling
= die
;
17496 /* Read a die, all of its descendents, and all of its siblings; set
17497 all of the fields of all of the dies correctly. Arguments are as
17498 in read_die_and_children.
17499 This the main entry point for reading a DIE and all its children. */
17501 static struct die_info
*
17502 read_die_and_siblings (const struct die_reader_specs
*reader
,
17503 const gdb_byte
*info_ptr
,
17504 const gdb_byte
**new_info_ptr
,
17505 struct die_info
*parent
)
17507 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17508 new_info_ptr
, parent
);
17510 if (dwarf_die_debug
)
17512 fprintf_unfiltered (gdb_stdlog
,
17513 "Read die from %s@0x%x of %s:\n",
17514 reader
->die_section
->get_name (),
17515 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17516 bfd_get_filename (reader
->abfd
));
17517 dump_die (die
, dwarf_die_debug
);
17523 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17525 The caller is responsible for filling in the extra attributes
17526 and updating (*DIEP)->num_attrs.
17527 Set DIEP to point to a newly allocated die with its information,
17528 except for its child, sibling, and parent fields. */
17530 static const gdb_byte
*
17531 read_full_die_1 (const struct die_reader_specs
*reader
,
17532 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17533 int num_extra_attrs
)
17535 unsigned int abbrev_number
, bytes_read
, i
;
17536 struct abbrev_info
*abbrev
;
17537 struct die_info
*die
;
17538 struct dwarf2_cu
*cu
= reader
->cu
;
17539 bfd
*abfd
= reader
->abfd
;
17541 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17542 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17543 info_ptr
+= bytes_read
;
17544 if (!abbrev_number
)
17550 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17552 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17554 bfd_get_filename (abfd
));
17556 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17557 die
->sect_off
= sect_off
;
17558 die
->tag
= abbrev
->tag
;
17559 die
->abbrev
= abbrev_number
;
17560 die
->has_children
= abbrev
->has_children
;
17562 /* Make the result usable.
17563 The caller needs to update num_attrs after adding the extra
17565 die
->num_attrs
= abbrev
->num_attrs
;
17567 std::vector
<int> indexes_that_need_reprocess
;
17568 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17570 bool need_reprocess
;
17572 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17573 info_ptr
, &need_reprocess
);
17574 if (need_reprocess
)
17575 indexes_that_need_reprocess
.push_back (i
);
17578 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
17579 if (attr
!= nullptr)
17580 cu
->str_offsets_base
= DW_UNSND (attr
);
17582 attr
= die
->attr (DW_AT_loclists_base
);
17583 if (attr
!= nullptr)
17584 cu
->loclist_base
= DW_UNSND (attr
);
17586 auto maybe_addr_base
= die
->addr_base ();
17587 if (maybe_addr_base
.has_value ())
17588 cu
->addr_base
= *maybe_addr_base
;
17589 for (int index
: indexes_that_need_reprocess
)
17590 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17595 /* Read a die and all its attributes.
17596 Set DIEP to point to a newly allocated die with its information,
17597 except for its child, sibling, and parent fields. */
17599 static const gdb_byte
*
17600 read_full_die (const struct die_reader_specs
*reader
,
17601 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17603 const gdb_byte
*result
;
17605 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17607 if (dwarf_die_debug
)
17609 fprintf_unfiltered (gdb_stdlog
,
17610 "Read die from %s@0x%x of %s:\n",
17611 reader
->die_section
->get_name (),
17612 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17613 bfd_get_filename (reader
->abfd
));
17614 dump_die (*diep
, dwarf_die_debug
);
17621 /* Returns nonzero if TAG represents a type that we might generate a partial
17625 is_type_tag_for_partial (int tag
)
17630 /* Some types that would be reasonable to generate partial symbols for,
17631 that we don't at present. */
17632 case DW_TAG_array_type
:
17633 case DW_TAG_file_type
:
17634 case DW_TAG_ptr_to_member_type
:
17635 case DW_TAG_set_type
:
17636 case DW_TAG_string_type
:
17637 case DW_TAG_subroutine_type
:
17639 case DW_TAG_base_type
:
17640 case DW_TAG_class_type
:
17641 case DW_TAG_interface_type
:
17642 case DW_TAG_enumeration_type
:
17643 case DW_TAG_structure_type
:
17644 case DW_TAG_subrange_type
:
17645 case DW_TAG_typedef
:
17646 case DW_TAG_union_type
:
17653 /* Load all DIEs that are interesting for partial symbols into memory. */
17655 static struct partial_die_info
*
17656 load_partial_dies (const struct die_reader_specs
*reader
,
17657 const gdb_byte
*info_ptr
, int building_psymtab
)
17659 struct dwarf2_cu
*cu
= reader
->cu
;
17660 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17661 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17662 unsigned int bytes_read
;
17663 unsigned int load_all
= 0;
17664 int nesting_level
= 1;
17669 gdb_assert (cu
->per_cu
!= NULL
);
17670 if (cu
->per_cu
->load_all_dies
)
17674 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17678 &cu
->comp_unit_obstack
,
17679 hashtab_obstack_allocate
,
17680 dummy_obstack_deallocate
);
17684 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17686 /* A NULL abbrev means the end of a series of children. */
17687 if (abbrev
== NULL
)
17689 if (--nesting_level
== 0)
17692 info_ptr
+= bytes_read
;
17693 last_die
= parent_die
;
17694 parent_die
= parent_die
->die_parent
;
17698 /* Check for template arguments. We never save these; if
17699 they're seen, we just mark the parent, and go on our way. */
17700 if (parent_die
!= NULL
17701 && cu
->language
== language_cplus
17702 && (abbrev
->tag
== DW_TAG_template_type_param
17703 || abbrev
->tag
== DW_TAG_template_value_param
))
17705 parent_die
->has_template_arguments
= 1;
17709 /* We don't need a partial DIE for the template argument. */
17710 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17715 /* We only recurse into c++ subprograms looking for template arguments.
17716 Skip their other children. */
17718 && cu
->language
== language_cplus
17719 && parent_die
!= NULL
17720 && parent_die
->tag
== DW_TAG_subprogram
)
17722 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17726 /* Check whether this DIE is interesting enough to save. Normally
17727 we would not be interested in members here, but there may be
17728 later variables referencing them via DW_AT_specification (for
17729 static members). */
17731 && !is_type_tag_for_partial (abbrev
->tag
)
17732 && abbrev
->tag
!= DW_TAG_constant
17733 && abbrev
->tag
!= DW_TAG_enumerator
17734 && abbrev
->tag
!= DW_TAG_subprogram
17735 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17736 && abbrev
->tag
!= DW_TAG_lexical_block
17737 && abbrev
->tag
!= DW_TAG_variable
17738 && abbrev
->tag
!= DW_TAG_namespace
17739 && abbrev
->tag
!= DW_TAG_module
17740 && abbrev
->tag
!= DW_TAG_member
17741 && abbrev
->tag
!= DW_TAG_imported_unit
17742 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17744 /* Otherwise we skip to the next sibling, if any. */
17745 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17749 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17752 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17754 /* This two-pass algorithm for processing partial symbols has a
17755 high cost in cache pressure. Thus, handle some simple cases
17756 here which cover the majority of C partial symbols. DIEs
17757 which neither have specification tags in them, nor could have
17758 specification tags elsewhere pointing at them, can simply be
17759 processed and discarded.
17761 This segment is also optional; scan_partial_symbols and
17762 add_partial_symbol will handle these DIEs if we chain
17763 them in normally. When compilers which do not emit large
17764 quantities of duplicate debug information are more common,
17765 this code can probably be removed. */
17767 /* Any complete simple types at the top level (pretty much all
17768 of them, for a language without namespaces), can be processed
17770 if (parent_die
== NULL
17771 && pdi
.has_specification
== 0
17772 && pdi
.is_declaration
== 0
17773 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17774 || pdi
.tag
== DW_TAG_base_type
17775 || pdi
.tag
== DW_TAG_subrange_type
))
17777 if (building_psymtab
&& pdi
.name
!= NULL
)
17778 add_psymbol_to_list (pdi
.name
, false,
17779 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17780 psymbol_placement::STATIC
,
17781 0, cu
->language
, objfile
);
17782 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17786 /* The exception for DW_TAG_typedef with has_children above is
17787 a workaround of GCC PR debug/47510. In the case of this complaint
17788 type_name_or_error will error on such types later.
17790 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17791 it could not find the child DIEs referenced later, this is checked
17792 above. In correct DWARF DW_TAG_typedef should have no children. */
17794 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17795 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17796 "- DIE at %s [in module %s]"),
17797 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17799 /* If we're at the second level, and we're an enumerator, and
17800 our parent has no specification (meaning possibly lives in a
17801 namespace elsewhere), then we can add the partial symbol now
17802 instead of queueing it. */
17803 if (pdi
.tag
== DW_TAG_enumerator
17804 && parent_die
!= NULL
17805 && parent_die
->die_parent
== NULL
17806 && parent_die
->tag
== DW_TAG_enumeration_type
17807 && parent_die
->has_specification
== 0)
17809 if (pdi
.name
== NULL
)
17810 complaint (_("malformed enumerator DIE ignored"));
17811 else if (building_psymtab
)
17812 add_psymbol_to_list (pdi
.name
, false,
17813 VAR_DOMAIN
, LOC_CONST
, -1,
17814 cu
->language
== language_cplus
17815 ? psymbol_placement::GLOBAL
17816 : psymbol_placement::STATIC
,
17817 0, cu
->language
, objfile
);
17819 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17823 struct partial_die_info
*part_die
17824 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17826 /* We'll save this DIE so link it in. */
17827 part_die
->die_parent
= parent_die
;
17828 part_die
->die_sibling
= NULL
;
17829 part_die
->die_child
= NULL
;
17831 if (last_die
&& last_die
== parent_die
)
17832 last_die
->die_child
= part_die
;
17834 last_die
->die_sibling
= part_die
;
17836 last_die
= part_die
;
17838 if (first_die
== NULL
)
17839 first_die
= part_die
;
17841 /* Maybe add the DIE to the hash table. Not all DIEs that we
17842 find interesting need to be in the hash table, because we
17843 also have the parent/sibling/child chains; only those that we
17844 might refer to by offset later during partial symbol reading.
17846 For now this means things that might have be the target of a
17847 DW_AT_specification, DW_AT_abstract_origin, or
17848 DW_AT_extension. DW_AT_extension will refer only to
17849 namespaces; DW_AT_abstract_origin refers to functions (and
17850 many things under the function DIE, but we do not recurse
17851 into function DIEs during partial symbol reading) and
17852 possibly variables as well; DW_AT_specification refers to
17853 declarations. Declarations ought to have the DW_AT_declaration
17854 flag. It happens that GCC forgets to put it in sometimes, but
17855 only for functions, not for types.
17857 Adding more things than necessary to the hash table is harmless
17858 except for the performance cost. Adding too few will result in
17859 wasted time in find_partial_die, when we reread the compilation
17860 unit with load_all_dies set. */
17863 || abbrev
->tag
== DW_TAG_constant
17864 || abbrev
->tag
== DW_TAG_subprogram
17865 || abbrev
->tag
== DW_TAG_variable
17866 || abbrev
->tag
== DW_TAG_namespace
17867 || part_die
->is_declaration
)
17871 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17872 to_underlying (part_die
->sect_off
),
17877 /* For some DIEs we want to follow their children (if any). For C
17878 we have no reason to follow the children of structures; for other
17879 languages we have to, so that we can get at method physnames
17880 to infer fully qualified class names, for DW_AT_specification,
17881 and for C++ template arguments. For C++, we also look one level
17882 inside functions to find template arguments (if the name of the
17883 function does not already contain the template arguments).
17885 For Ada and Fortran, we need to scan the children of subprograms
17886 and lexical blocks as well because these languages allow the
17887 definition of nested entities that could be interesting for the
17888 debugger, such as nested subprograms for instance. */
17889 if (last_die
->has_children
17891 || last_die
->tag
== DW_TAG_namespace
17892 || last_die
->tag
== DW_TAG_module
17893 || last_die
->tag
== DW_TAG_enumeration_type
17894 || (cu
->language
== language_cplus
17895 && last_die
->tag
== DW_TAG_subprogram
17896 && (last_die
->name
== NULL
17897 || strchr (last_die
->name
, '<') == NULL
))
17898 || (cu
->language
!= language_c
17899 && (last_die
->tag
== DW_TAG_class_type
17900 || last_die
->tag
== DW_TAG_interface_type
17901 || last_die
->tag
== DW_TAG_structure_type
17902 || last_die
->tag
== DW_TAG_union_type
))
17903 || ((cu
->language
== language_ada
17904 || cu
->language
== language_fortran
)
17905 && (last_die
->tag
== DW_TAG_subprogram
17906 || last_die
->tag
== DW_TAG_lexical_block
))))
17909 parent_die
= last_die
;
17913 /* Otherwise we skip to the next sibling, if any. */
17914 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17916 /* Back to the top, do it again. */
17920 partial_die_info::partial_die_info (sect_offset sect_off_
,
17921 struct abbrev_info
*abbrev
)
17922 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17926 /* Read a minimal amount of information into the minimal die structure.
17927 INFO_PTR should point just after the initial uleb128 of a DIE. */
17930 partial_die_info::read (const struct die_reader_specs
*reader
,
17931 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17933 struct dwarf2_cu
*cu
= reader
->cu
;
17934 struct dwarf2_per_objfile
*dwarf2_per_objfile
17935 = cu
->per_cu
->dwarf2_per_objfile
;
17937 int has_low_pc_attr
= 0;
17938 int has_high_pc_attr
= 0;
17939 int high_pc_relative
= 0;
17941 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17944 bool need_reprocess
;
17945 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
17946 info_ptr
, &need_reprocess
);
17947 /* String and address offsets that need to do the reprocessing have
17948 already been read at this point, so there is no need to wait until
17949 the loop terminates to do the reprocessing. */
17950 if (need_reprocess
)
17951 read_attribute_reprocess (reader
, &attr
);
17952 /* Store the data if it is of an attribute we want to keep in a
17953 partial symbol table. */
17959 case DW_TAG_compile_unit
:
17960 case DW_TAG_partial_unit
:
17961 case DW_TAG_type_unit
:
17962 /* Compilation units have a DW_AT_name that is a filename, not
17963 a source language identifier. */
17964 case DW_TAG_enumeration_type
:
17965 case DW_TAG_enumerator
:
17966 /* These tags always have simple identifiers already; no need
17967 to canonicalize them. */
17968 name
= DW_STRING (&attr
);
17972 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17975 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
17980 case DW_AT_linkage_name
:
17981 case DW_AT_MIPS_linkage_name
:
17982 /* Note that both forms of linkage name might appear. We
17983 assume they will be the same, and we only store the last
17985 linkage_name
= DW_STRING (&attr
);
17988 has_low_pc_attr
= 1;
17989 lowpc
= attr
.value_as_address ();
17991 case DW_AT_high_pc
:
17992 has_high_pc_attr
= 1;
17993 highpc
= attr
.value_as_address ();
17994 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
17995 high_pc_relative
= 1;
17997 case DW_AT_location
:
17998 /* Support the .debug_loc offsets. */
17999 if (attr
.form_is_block ())
18001 d
.locdesc
= DW_BLOCK (&attr
);
18003 else if (attr
.form_is_section_offset ())
18005 dwarf2_complex_location_expr_complaint ();
18009 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18010 "partial symbol information");
18013 case DW_AT_external
:
18014 is_external
= DW_UNSND (&attr
);
18016 case DW_AT_declaration
:
18017 is_declaration
= DW_UNSND (&attr
);
18022 case DW_AT_abstract_origin
:
18023 case DW_AT_specification
:
18024 case DW_AT_extension
:
18025 has_specification
= 1;
18026 spec_offset
= attr
.get_ref_die_offset ();
18027 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18028 || cu
->per_cu
->is_dwz
);
18030 case DW_AT_sibling
:
18031 /* Ignore absolute siblings, they might point outside of
18032 the current compile unit. */
18033 if (attr
.form
== DW_FORM_ref_addr
)
18034 complaint (_("ignoring absolute DW_AT_sibling"));
18037 const gdb_byte
*buffer
= reader
->buffer
;
18038 sect_offset off
= attr
.get_ref_die_offset ();
18039 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18041 if (sibling_ptr
< info_ptr
)
18042 complaint (_("DW_AT_sibling points backwards"));
18043 else if (sibling_ptr
> reader
->buffer_end
)
18044 reader
->die_section
->overflow_complaint ();
18046 sibling
= sibling_ptr
;
18049 case DW_AT_byte_size
:
18052 case DW_AT_const_value
:
18053 has_const_value
= 1;
18055 case DW_AT_calling_convention
:
18056 /* DWARF doesn't provide a way to identify a program's source-level
18057 entry point. DW_AT_calling_convention attributes are only meant
18058 to describe functions' calling conventions.
18060 However, because it's a necessary piece of information in
18061 Fortran, and before DWARF 4 DW_CC_program was the only
18062 piece of debugging information whose definition refers to
18063 a 'main program' at all, several compilers marked Fortran
18064 main programs with DW_CC_program --- even when those
18065 functions use the standard calling conventions.
18067 Although DWARF now specifies a way to provide this
18068 information, we support this practice for backward
18070 if (DW_UNSND (&attr
) == DW_CC_program
18071 && cu
->language
== language_fortran
)
18072 main_subprogram
= 1;
18075 if (DW_UNSND (&attr
) == DW_INL_inlined
18076 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18077 may_be_inlined
= 1;
18081 if (tag
== DW_TAG_imported_unit
)
18083 d
.sect_off
= attr
.get_ref_die_offset ();
18084 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18085 || cu
->per_cu
->is_dwz
);
18089 case DW_AT_main_subprogram
:
18090 main_subprogram
= DW_UNSND (&attr
);
18095 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18096 but that requires a full DIE, so instead we just
18098 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18099 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18100 + (need_ranges_base
18104 /* Value of the DW_AT_ranges attribute is the offset in the
18105 .debug_ranges section. */
18106 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18117 /* For Ada, if both the name and the linkage name appear, we prefer
18118 the latter. This lets "catch exception" work better, regardless
18119 of the order in which the name and linkage name were emitted.
18120 Really, though, this is just a workaround for the fact that gdb
18121 doesn't store both the name and the linkage name. */
18122 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18123 name
= linkage_name
;
18125 if (high_pc_relative
)
18128 if (has_low_pc_attr
&& has_high_pc_attr
)
18130 /* When using the GNU linker, .gnu.linkonce. sections are used to
18131 eliminate duplicate copies of functions and vtables and such.
18132 The linker will arbitrarily choose one and discard the others.
18133 The AT_*_pc values for such functions refer to local labels in
18134 these sections. If the section from that file was discarded, the
18135 labels are not in the output, so the relocs get a value of 0.
18136 If this is a discarded function, mark the pc bounds as invalid,
18137 so that GDB will ignore it. */
18138 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18140 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18141 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18143 complaint (_("DW_AT_low_pc %s is zero "
18144 "for DIE at %s [in module %s]"),
18145 paddress (gdbarch
, lowpc
),
18146 sect_offset_str (sect_off
),
18147 objfile_name (objfile
));
18149 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18150 else if (lowpc
>= highpc
)
18152 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18153 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18155 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18156 "for DIE at %s [in module %s]"),
18157 paddress (gdbarch
, lowpc
),
18158 paddress (gdbarch
, highpc
),
18159 sect_offset_str (sect_off
),
18160 objfile_name (objfile
));
18169 /* Find a cached partial DIE at OFFSET in CU. */
18171 struct partial_die_info
*
18172 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18174 struct partial_die_info
*lookup_die
= NULL
;
18175 struct partial_die_info
part_die (sect_off
);
18177 lookup_die
= ((struct partial_die_info
*)
18178 htab_find_with_hash (partial_dies
, &part_die
,
18179 to_underlying (sect_off
)));
18184 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18185 except in the case of .debug_types DIEs which do not reference
18186 outside their CU (they do however referencing other types via
18187 DW_FORM_ref_sig8). */
18189 static const struct cu_partial_die_info
18190 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18192 struct dwarf2_per_objfile
*dwarf2_per_objfile
18193 = cu
->per_cu
->dwarf2_per_objfile
;
18194 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18195 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18196 struct partial_die_info
*pd
= NULL
;
18198 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18199 && cu
->header
.offset_in_cu_p (sect_off
))
18201 pd
= cu
->find_partial_die (sect_off
);
18204 /* We missed recording what we needed.
18205 Load all dies and try again. */
18206 per_cu
= cu
->per_cu
;
18210 /* TUs don't reference other CUs/TUs (except via type signatures). */
18211 if (cu
->per_cu
->is_debug_types
)
18213 error (_("Dwarf Error: Type Unit at offset %s contains"
18214 " external reference to offset %s [in module %s].\n"),
18215 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18216 bfd_get_filename (objfile
->obfd
));
18218 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18219 dwarf2_per_objfile
);
18221 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18222 load_partial_comp_unit (per_cu
);
18224 per_cu
->cu
->last_used
= 0;
18225 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18228 /* If we didn't find it, and not all dies have been loaded,
18229 load them all and try again. */
18231 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18233 per_cu
->load_all_dies
= 1;
18235 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18236 THIS_CU->cu may already be in use. So we can't just free it and
18237 replace its DIEs with the ones we read in. Instead, we leave those
18238 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18239 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18241 load_partial_comp_unit (per_cu
);
18243 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18247 internal_error (__FILE__
, __LINE__
,
18248 _("could not find partial DIE %s "
18249 "in cache [from module %s]\n"),
18250 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18251 return { per_cu
->cu
, pd
};
18254 /* See if we can figure out if the class lives in a namespace. We do
18255 this by looking for a member function; its demangled name will
18256 contain namespace info, if there is any. */
18259 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18260 struct dwarf2_cu
*cu
)
18262 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18263 what template types look like, because the demangler
18264 frequently doesn't give the same name as the debug info. We
18265 could fix this by only using the demangled name to get the
18266 prefix (but see comment in read_structure_type). */
18268 struct partial_die_info
*real_pdi
;
18269 struct partial_die_info
*child_pdi
;
18271 /* If this DIE (this DIE's specification, if any) has a parent, then
18272 we should not do this. We'll prepend the parent's fully qualified
18273 name when we create the partial symbol. */
18275 real_pdi
= struct_pdi
;
18276 while (real_pdi
->has_specification
)
18278 auto res
= find_partial_die (real_pdi
->spec_offset
,
18279 real_pdi
->spec_is_dwz
, cu
);
18280 real_pdi
= res
.pdi
;
18284 if (real_pdi
->die_parent
!= NULL
)
18287 for (child_pdi
= struct_pdi
->die_child
;
18289 child_pdi
= child_pdi
->die_sibling
)
18291 if (child_pdi
->tag
== DW_TAG_subprogram
18292 && child_pdi
->linkage_name
!= NULL
)
18294 gdb::unique_xmalloc_ptr
<char> actual_class_name
18295 (language_class_name_from_physname (cu
->language_defn
,
18296 child_pdi
->linkage_name
));
18297 if (actual_class_name
!= NULL
)
18299 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18300 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18307 /* Return true if a DIE with TAG may have the DW_AT_const_value
18311 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18315 case DW_TAG_constant
:
18316 case DW_TAG_enumerator
:
18317 case DW_TAG_formal_parameter
:
18318 case DW_TAG_template_value_param
:
18319 case DW_TAG_variable
:
18327 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18329 /* Once we've fixed up a die, there's no point in doing so again.
18330 This also avoids a memory leak if we were to call
18331 guess_partial_die_structure_name multiple times. */
18335 /* If we found a reference attribute and the DIE has no name, try
18336 to find a name in the referred to DIE. */
18338 if (name
== NULL
&& has_specification
)
18340 struct partial_die_info
*spec_die
;
18342 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18343 spec_die
= res
.pdi
;
18346 spec_die
->fixup (cu
);
18348 if (spec_die
->name
)
18350 name
= spec_die
->name
;
18352 /* Copy DW_AT_external attribute if it is set. */
18353 if (spec_die
->is_external
)
18354 is_external
= spec_die
->is_external
;
18358 if (!has_const_value
&& has_specification
18359 && can_have_DW_AT_const_value_p (tag
))
18361 struct partial_die_info
*spec_die
;
18363 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18364 spec_die
= res
.pdi
;
18367 spec_die
->fixup (cu
);
18369 if (spec_die
->has_const_value
)
18371 /* Copy DW_AT_const_value attribute if it is set. */
18372 has_const_value
= spec_die
->has_const_value
;
18376 /* Set default names for some unnamed DIEs. */
18378 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18379 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18381 /* If there is no parent die to provide a namespace, and there are
18382 children, see if we can determine the namespace from their linkage
18384 if (cu
->language
== language_cplus
18385 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18386 && die_parent
== NULL
18388 && (tag
== DW_TAG_class_type
18389 || tag
== DW_TAG_structure_type
18390 || tag
== DW_TAG_union_type
))
18391 guess_partial_die_structure_name (this, cu
);
18393 /* GCC might emit a nameless struct or union that has a linkage
18394 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18396 && (tag
== DW_TAG_class_type
18397 || tag
== DW_TAG_interface_type
18398 || tag
== DW_TAG_structure_type
18399 || tag
== DW_TAG_union_type
)
18400 && linkage_name
!= NULL
)
18402 gdb::unique_xmalloc_ptr
<char> demangled
18403 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18404 if (demangled
!= nullptr)
18408 /* Strip any leading namespaces/classes, keep only the base name.
18409 DW_AT_name for named DIEs does not contain the prefixes. */
18410 base
= strrchr (demangled
.get (), ':');
18411 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18414 base
= demangled
.get ();
18416 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18417 name
= objfile
->intern (base
);
18424 /* Read the .debug_loclists header contents from the given SECTION in the
18427 read_loclist_header (struct loclist_header
*header
,
18428 struct dwarf2_section_info
*section
)
18430 unsigned int bytes_read
;
18431 bfd
*abfd
= section
->get_bfd_owner ();
18432 const gdb_byte
*info_ptr
= section
->buffer
;
18433 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
18434 info_ptr
+= bytes_read
;
18435 header
->version
= read_2_bytes (abfd
, info_ptr
);
18437 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
18439 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
18441 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
18444 /* Return the DW_AT_loclists_base value for the CU. */
18446 lookup_loclist_base (struct dwarf2_cu
*cu
)
18448 /* For the .dwo unit, the loclist_base points to the first offset following
18449 the header. The header consists of the following entities-
18450 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
18452 2. version (2 bytes)
18453 3. address size (1 byte)
18454 4. segment selector size (1 byte)
18455 5. offset entry count (4 bytes)
18456 These sizes are derived as per the DWARFv5 standard. */
18457 if (cu
->dwo_unit
!= nullptr)
18459 if (cu
->header
.initial_length_size
== 4)
18460 return LOCLIST_HEADER_SIZE32
;
18461 return LOCLIST_HEADER_SIZE64
;
18463 return cu
->loclist_base
;
18466 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
18467 array of offsets in the .debug_loclists section. */
18469 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
18471 struct dwarf2_per_objfile
*dwarf2_per_objfile
18472 = cu
->per_cu
->dwarf2_per_objfile
;
18473 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18474 bfd
*abfd
= objfile
->obfd
;
18475 ULONGEST loclist_base
= lookup_loclist_base (cu
);
18476 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18478 section
->read (objfile
);
18479 if (section
->buffer
== NULL
)
18480 complaint (_("DW_FORM_loclistx used without .debug_loclists "
18481 "section [in module %s]"), objfile_name (objfile
));
18482 struct loclist_header header
;
18483 read_loclist_header (&header
, section
);
18484 if (loclist_index
>= header
.offset_entry_count
)
18485 complaint (_("DW_FORM_loclistx pointing outside of "
18486 ".debug_loclists offset array [in module %s]"),
18487 objfile_name (objfile
));
18488 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
18490 complaint (_("DW_FORM_loclistx pointing outside of "
18491 ".debug_loclists section [in module %s]"),
18492 objfile_name (objfile
));
18493 const gdb_byte
*info_ptr
18494 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
18496 if (cu
->header
.offset_size
== 4)
18497 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
18499 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
18502 /* Process the attributes that had to be skipped in the first round. These
18503 attributes are the ones that need str_offsets_base or addr_base attributes.
18504 They could not have been processed in the first round, because at the time
18505 the values of str_offsets_base or addr_base may not have been known. */
18507 read_attribute_reprocess (const struct die_reader_specs
*reader
,
18508 struct attribute
*attr
)
18510 struct dwarf2_cu
*cu
= reader
->cu
;
18511 switch (attr
->form
)
18513 case DW_FORM_addrx
:
18514 case DW_FORM_GNU_addr_index
:
18515 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18517 case DW_FORM_loclistx
:
18518 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
18521 case DW_FORM_strx1
:
18522 case DW_FORM_strx2
:
18523 case DW_FORM_strx3
:
18524 case DW_FORM_strx4
:
18525 case DW_FORM_GNU_str_index
:
18527 unsigned int str_index
= DW_UNSND (attr
);
18528 if (reader
->dwo_file
!= NULL
)
18530 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18531 DW_STRING_IS_CANONICAL (attr
) = 0;
18535 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18536 DW_STRING_IS_CANONICAL (attr
) = 0;
18541 gdb_assert_not_reached (_("Unexpected DWARF form."));
18545 /* Read an attribute value described by an attribute form. */
18547 static const gdb_byte
*
18548 read_attribute_value (const struct die_reader_specs
*reader
,
18549 struct attribute
*attr
, unsigned form
,
18550 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18551 bool *need_reprocess
)
18553 struct dwarf2_cu
*cu
= reader
->cu
;
18554 struct dwarf2_per_objfile
*dwarf2_per_objfile
18555 = cu
->per_cu
->dwarf2_per_objfile
;
18556 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18557 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18558 bfd
*abfd
= reader
->abfd
;
18559 struct comp_unit_head
*cu_header
= &cu
->header
;
18560 unsigned int bytes_read
;
18561 struct dwarf_block
*blk
;
18562 *need_reprocess
= false;
18564 attr
->form
= (enum dwarf_form
) form
;
18567 case DW_FORM_ref_addr
:
18568 if (cu
->header
.version
== 2)
18569 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18572 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18574 info_ptr
+= bytes_read
;
18576 case DW_FORM_GNU_ref_alt
:
18577 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18578 info_ptr
+= bytes_read
;
18581 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18582 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18583 info_ptr
+= bytes_read
;
18585 case DW_FORM_block2
:
18586 blk
= dwarf_alloc_block (cu
);
18587 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18589 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18590 info_ptr
+= blk
->size
;
18591 DW_BLOCK (attr
) = blk
;
18593 case DW_FORM_block4
:
18594 blk
= dwarf_alloc_block (cu
);
18595 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18597 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18598 info_ptr
+= blk
->size
;
18599 DW_BLOCK (attr
) = blk
;
18601 case DW_FORM_data2
:
18602 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18605 case DW_FORM_data4
:
18606 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18609 case DW_FORM_data8
:
18610 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18613 case DW_FORM_data16
:
18614 blk
= dwarf_alloc_block (cu
);
18616 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18618 DW_BLOCK (attr
) = blk
;
18620 case DW_FORM_sec_offset
:
18621 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18622 info_ptr
+= bytes_read
;
18624 case DW_FORM_loclistx
:
18626 *need_reprocess
= true;
18627 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18628 info_ptr
+= bytes_read
;
18631 case DW_FORM_string
:
18632 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18633 DW_STRING_IS_CANONICAL (attr
) = 0;
18634 info_ptr
+= bytes_read
;
18637 if (!cu
->per_cu
->is_dwz
)
18639 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18640 abfd
, info_ptr
, cu_header
,
18642 DW_STRING_IS_CANONICAL (attr
) = 0;
18643 info_ptr
+= bytes_read
;
18647 case DW_FORM_line_strp
:
18648 if (!cu
->per_cu
->is_dwz
)
18651 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
18653 DW_STRING_IS_CANONICAL (attr
) = 0;
18654 info_ptr
+= bytes_read
;
18658 case DW_FORM_GNU_strp_alt
:
18660 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18661 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18664 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
18665 DW_STRING_IS_CANONICAL (attr
) = 0;
18666 info_ptr
+= bytes_read
;
18669 case DW_FORM_exprloc
:
18670 case DW_FORM_block
:
18671 blk
= dwarf_alloc_block (cu
);
18672 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18673 info_ptr
+= bytes_read
;
18674 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18675 info_ptr
+= blk
->size
;
18676 DW_BLOCK (attr
) = blk
;
18678 case DW_FORM_block1
:
18679 blk
= dwarf_alloc_block (cu
);
18680 blk
->size
= read_1_byte (abfd
, info_ptr
);
18682 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18683 info_ptr
+= blk
->size
;
18684 DW_BLOCK (attr
) = blk
;
18686 case DW_FORM_data1
:
18687 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18691 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18694 case DW_FORM_flag_present
:
18695 DW_UNSND (attr
) = 1;
18697 case DW_FORM_sdata
:
18698 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18699 info_ptr
+= bytes_read
;
18701 case DW_FORM_udata
:
18702 case DW_FORM_rnglistx
:
18703 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18704 info_ptr
+= bytes_read
;
18707 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18708 + read_1_byte (abfd
, info_ptr
));
18712 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18713 + read_2_bytes (abfd
, info_ptr
));
18717 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18718 + read_4_bytes (abfd
, info_ptr
));
18722 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18723 + read_8_bytes (abfd
, info_ptr
));
18726 case DW_FORM_ref_sig8
:
18727 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18730 case DW_FORM_ref_udata
:
18731 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18732 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18733 info_ptr
+= bytes_read
;
18735 case DW_FORM_indirect
:
18736 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18737 info_ptr
+= bytes_read
;
18738 if (form
== DW_FORM_implicit_const
)
18740 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18741 info_ptr
+= bytes_read
;
18743 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18744 info_ptr
, need_reprocess
);
18746 case DW_FORM_implicit_const
:
18747 DW_SND (attr
) = implicit_const
;
18749 case DW_FORM_addrx
:
18750 case DW_FORM_GNU_addr_index
:
18751 *need_reprocess
= true;
18752 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18753 info_ptr
+= bytes_read
;
18756 case DW_FORM_strx1
:
18757 case DW_FORM_strx2
:
18758 case DW_FORM_strx3
:
18759 case DW_FORM_strx4
:
18760 case DW_FORM_GNU_str_index
:
18762 ULONGEST str_index
;
18763 if (form
== DW_FORM_strx1
)
18765 str_index
= read_1_byte (abfd
, info_ptr
);
18768 else if (form
== DW_FORM_strx2
)
18770 str_index
= read_2_bytes (abfd
, info_ptr
);
18773 else if (form
== DW_FORM_strx3
)
18775 str_index
= read_3_bytes (abfd
, info_ptr
);
18778 else if (form
== DW_FORM_strx4
)
18780 str_index
= read_4_bytes (abfd
, info_ptr
);
18785 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18786 info_ptr
+= bytes_read
;
18788 *need_reprocess
= true;
18789 DW_UNSND (attr
) = str_index
;
18793 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18794 dwarf_form_name (form
),
18795 bfd_get_filename (abfd
));
18799 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18800 attr
->form
= DW_FORM_GNU_ref_alt
;
18802 /* We have seen instances where the compiler tried to emit a byte
18803 size attribute of -1 which ended up being encoded as an unsigned
18804 0xffffffff. Although 0xffffffff is technically a valid size value,
18805 an object of this size seems pretty unlikely so we can relatively
18806 safely treat these cases as if the size attribute was invalid and
18807 treat them as zero by default. */
18808 if (attr
->name
== DW_AT_byte_size
18809 && form
== DW_FORM_data4
18810 && DW_UNSND (attr
) >= 0xffffffff)
18813 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18814 hex_string (DW_UNSND (attr
)));
18815 DW_UNSND (attr
) = 0;
18821 /* Read an attribute described by an abbreviated attribute. */
18823 static const gdb_byte
*
18824 read_attribute (const struct die_reader_specs
*reader
,
18825 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18826 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18828 attr
->name
= abbrev
->name
;
18829 return read_attribute_value (reader
, attr
, abbrev
->form
,
18830 abbrev
->implicit_const
, info_ptr
,
18834 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18836 static const char *
18837 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18838 LONGEST str_offset
)
18840 return dwarf2_per_objfile
->str
.read_string (dwarf2_per_objfile
->objfile
,
18841 str_offset
, "DW_FORM_strp");
18844 /* Return pointer to string at .debug_str offset as read from BUF.
18845 BUF is assumed to be in a compilation unit described by CU_HEADER.
18846 Return *BYTES_READ_PTR count of bytes read from BUF. */
18848 static const char *
18849 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18850 const gdb_byte
*buf
,
18851 const struct comp_unit_head
*cu_header
,
18852 unsigned int *bytes_read_ptr
)
18854 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18856 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
18862 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
18863 const struct comp_unit_head
*cu_header
,
18864 unsigned int *bytes_read_ptr
)
18866 bfd
*abfd
= objfile
->obfd
;
18867 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18869 return line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
18872 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18873 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18874 ADDR_SIZE is the size of addresses from the CU header. */
18877 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18878 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18881 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18882 bfd
*abfd
= objfile
->obfd
;
18883 const gdb_byte
*info_ptr
;
18884 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18886 dwarf2_per_objfile
->addr
.read (objfile
);
18887 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18888 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18889 objfile_name (objfile
));
18890 if (addr_base_or_zero
+ addr_index
* addr_size
18891 >= dwarf2_per_objfile
->addr
.size
)
18892 error (_("DW_FORM_addr_index pointing outside of "
18893 ".debug_addr section [in module %s]"),
18894 objfile_name (objfile
));
18895 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18896 + addr_base_or_zero
+ addr_index
* addr_size
);
18897 if (addr_size
== 4)
18898 return bfd_get_32 (abfd
, info_ptr
);
18900 return bfd_get_64 (abfd
, info_ptr
);
18903 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18906 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18908 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18909 cu
->addr_base
, cu
->header
.addr_size
);
18912 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18915 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18916 unsigned int *bytes_read
)
18918 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18919 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18921 return read_addr_index (cu
, addr_index
);
18927 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
18929 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18930 struct dwarf2_cu
*cu
= per_cu
->cu
;
18931 gdb::optional
<ULONGEST
> addr_base
;
18934 /* We need addr_base and addr_size.
18935 If we don't have PER_CU->cu, we have to get it.
18936 Nasty, but the alternative is storing the needed info in PER_CU,
18937 which at this point doesn't seem justified: it's not clear how frequently
18938 it would get used and it would increase the size of every PER_CU.
18939 Entry points like dwarf2_per_cu_addr_size do a similar thing
18940 so we're not in uncharted territory here.
18941 Alas we need to be a bit more complicated as addr_base is contained
18944 We don't need to read the entire CU(/TU).
18945 We just need the header and top level die.
18947 IWBN to use the aging mechanism to let us lazily later discard the CU.
18948 For now we skip this optimization. */
18952 addr_base
= cu
->addr_base
;
18953 addr_size
= cu
->header
.addr_size
;
18957 cutu_reader
reader (per_cu
, NULL
, 0, false);
18958 addr_base
= reader
.cu
->addr_base
;
18959 addr_size
= reader
.cu
->header
.addr_size
;
18962 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18966 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18967 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18970 static const char *
18971 read_str_index (struct dwarf2_cu
*cu
,
18972 struct dwarf2_section_info
*str_section
,
18973 struct dwarf2_section_info
*str_offsets_section
,
18974 ULONGEST str_offsets_base
, ULONGEST str_index
)
18976 struct dwarf2_per_objfile
*dwarf2_per_objfile
18977 = cu
->per_cu
->dwarf2_per_objfile
;
18978 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18979 const char *objf_name
= objfile_name (objfile
);
18980 bfd
*abfd
= objfile
->obfd
;
18981 const gdb_byte
*info_ptr
;
18982 ULONGEST str_offset
;
18983 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18985 str_section
->read (objfile
);
18986 str_offsets_section
->read (objfile
);
18987 if (str_section
->buffer
== NULL
)
18988 error (_("%s used without %s section"
18989 " in CU at offset %s [in module %s]"),
18990 form_name
, str_section
->get_name (),
18991 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18992 if (str_offsets_section
->buffer
== NULL
)
18993 error (_("%s used without %s section"
18994 " in CU at offset %s [in module %s]"),
18995 form_name
, str_section
->get_name (),
18996 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18997 info_ptr
= (str_offsets_section
->buffer
18999 + str_index
* cu
->header
.offset_size
);
19000 if (cu
->header
.offset_size
== 4)
19001 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19003 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19004 if (str_offset
>= str_section
->size
)
19005 error (_("Offset from %s pointing outside of"
19006 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19007 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19008 return (const char *) (str_section
->buffer
+ str_offset
);
19011 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19013 static const char *
19014 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19016 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19017 ? reader
->cu
->header
.addr_size
: 0;
19018 return read_str_index (reader
->cu
,
19019 &reader
->dwo_file
->sections
.str
,
19020 &reader
->dwo_file
->sections
.str_offsets
,
19021 str_offsets_base
, str_index
);
19024 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19026 static const char *
19027 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19029 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19030 const char *objf_name
= objfile_name (objfile
);
19031 static const char form_name
[] = "DW_FORM_GNU_str_index";
19032 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19034 if (!cu
->str_offsets_base
.has_value ())
19035 error (_("%s used in Fission stub without %s"
19036 " in CU at offset 0x%lx [in module %s]"),
19037 form_name
, str_offsets_attr_name
,
19038 (long) cu
->header
.offset_size
, objf_name
);
19040 return read_str_index (cu
,
19041 &cu
->per_cu
->dwarf2_per_objfile
->str
,
19042 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
19043 *cu
->str_offsets_base
, str_index
);
19046 /* Return the length of an LEB128 number in BUF. */
19049 leb128_size (const gdb_byte
*buf
)
19051 const gdb_byte
*begin
= buf
;
19057 if ((byte
& 128) == 0)
19058 return buf
- begin
;
19063 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19072 cu
->language
= language_c
;
19075 case DW_LANG_C_plus_plus
:
19076 case DW_LANG_C_plus_plus_11
:
19077 case DW_LANG_C_plus_plus_14
:
19078 cu
->language
= language_cplus
;
19081 cu
->language
= language_d
;
19083 case DW_LANG_Fortran77
:
19084 case DW_LANG_Fortran90
:
19085 case DW_LANG_Fortran95
:
19086 case DW_LANG_Fortran03
:
19087 case DW_LANG_Fortran08
:
19088 cu
->language
= language_fortran
;
19091 cu
->language
= language_go
;
19093 case DW_LANG_Mips_Assembler
:
19094 cu
->language
= language_asm
;
19096 case DW_LANG_Ada83
:
19097 case DW_LANG_Ada95
:
19098 cu
->language
= language_ada
;
19100 case DW_LANG_Modula2
:
19101 cu
->language
= language_m2
;
19103 case DW_LANG_Pascal83
:
19104 cu
->language
= language_pascal
;
19107 cu
->language
= language_objc
;
19110 case DW_LANG_Rust_old
:
19111 cu
->language
= language_rust
;
19113 case DW_LANG_Cobol74
:
19114 case DW_LANG_Cobol85
:
19116 cu
->language
= language_minimal
;
19119 cu
->language_defn
= language_def (cu
->language
);
19122 /* Return the named attribute or NULL if not there. */
19124 static struct attribute
*
19125 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19130 struct attribute
*spec
= NULL
;
19132 for (i
= 0; i
< die
->num_attrs
; ++i
)
19134 if (die
->attrs
[i
].name
== name
)
19135 return &die
->attrs
[i
];
19136 if (die
->attrs
[i
].name
== DW_AT_specification
19137 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19138 spec
= &die
->attrs
[i
];
19144 die
= follow_die_ref (die
, spec
, &cu
);
19150 /* Return the string associated with a string-typed attribute, or NULL if it
19151 is either not found or is of an incorrect type. */
19153 static const char *
19154 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19156 struct attribute
*attr
;
19157 const char *str
= NULL
;
19159 attr
= dwarf2_attr (die
, name
, cu
);
19163 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19164 || attr
->form
== DW_FORM_string
19165 || attr
->form
== DW_FORM_strx
19166 || attr
->form
== DW_FORM_strx1
19167 || attr
->form
== DW_FORM_strx2
19168 || attr
->form
== DW_FORM_strx3
19169 || attr
->form
== DW_FORM_strx4
19170 || attr
->form
== DW_FORM_GNU_str_index
19171 || attr
->form
== DW_FORM_GNU_strp_alt
)
19172 str
= DW_STRING (attr
);
19174 complaint (_("string type expected for attribute %s for "
19175 "DIE at %s in module %s"),
19176 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19177 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19183 /* Return the dwo name or NULL if not present. If present, it is in either
19184 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19185 static const char *
19186 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19188 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19189 if (dwo_name
== nullptr)
19190 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19194 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19195 and holds a non-zero value. This function should only be used for
19196 DW_FORM_flag or DW_FORM_flag_present attributes. */
19199 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19201 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19203 return (attr
&& DW_UNSND (attr
));
19207 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19209 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19210 which value is non-zero. However, we have to be careful with
19211 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19212 (via dwarf2_flag_true_p) follows this attribute. So we may
19213 end up accidently finding a declaration attribute that belongs
19214 to a different DIE referenced by the specification attribute,
19215 even though the given DIE does not have a declaration attribute. */
19216 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19217 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19220 /* Return the die giving the specification for DIE, if there is
19221 one. *SPEC_CU is the CU containing DIE on input, and the CU
19222 containing the return value on output. If there is no
19223 specification, but there is an abstract origin, that is
19226 static struct die_info
*
19227 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19229 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19232 if (spec_attr
== NULL
)
19233 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19235 if (spec_attr
== NULL
)
19238 return follow_die_ref (die
, spec_attr
, spec_cu
);
19241 /* Stub for free_line_header to match void * callback types. */
19244 free_line_header_voidp (void *arg
)
19246 struct line_header
*lh
= (struct line_header
*) arg
;
19251 /* A convenience function to find the proper .debug_line section for a CU. */
19253 static struct dwarf2_section_info
*
19254 get_debug_line_section (struct dwarf2_cu
*cu
)
19256 struct dwarf2_section_info
*section
;
19257 struct dwarf2_per_objfile
*dwarf2_per_objfile
19258 = cu
->per_cu
->dwarf2_per_objfile
;
19260 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19262 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19263 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19264 else if (cu
->per_cu
->is_dwz
)
19266 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19268 section
= &dwz
->line
;
19271 section
= &dwarf2_per_objfile
->line
;
19276 /* Read the statement program header starting at OFFSET in
19277 .debug_line, or .debug_line.dwo. Return a pointer
19278 to a struct line_header, allocated using xmalloc.
19279 Returns NULL if there is a problem reading the header, e.g., if it
19280 has a version we don't understand.
19282 NOTE: the strings in the include directory and file name tables of
19283 the returned object point into the dwarf line section buffer,
19284 and must not be freed. */
19286 static line_header_up
19287 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19289 struct dwarf2_section_info
*section
;
19290 struct dwarf2_per_objfile
*dwarf2_per_objfile
19291 = cu
->per_cu
->dwarf2_per_objfile
;
19293 section
= get_debug_line_section (cu
);
19294 section
->read (dwarf2_per_objfile
->objfile
);
19295 if (section
->buffer
== NULL
)
19297 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19298 complaint (_("missing .debug_line.dwo section"));
19300 complaint (_("missing .debug_line section"));
19304 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19305 dwarf2_per_objfile
, section
,
19309 /* Subroutine of dwarf_decode_lines to simplify it.
19310 Return the file name of the psymtab for the given file_entry.
19311 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19312 If space for the result is malloc'd, *NAME_HOLDER will be set.
19313 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19315 static const char *
19316 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19317 const dwarf2_psymtab
*pst
,
19318 const char *comp_dir
,
19319 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19321 const char *include_name
= fe
.name
;
19322 const char *include_name_to_compare
= include_name
;
19323 const char *pst_filename
;
19326 const char *dir_name
= fe
.include_dir (lh
);
19328 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19329 if (!IS_ABSOLUTE_PATH (include_name
)
19330 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19332 /* Avoid creating a duplicate psymtab for PST.
19333 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19334 Before we do the comparison, however, we need to account
19335 for DIR_NAME and COMP_DIR.
19336 First prepend dir_name (if non-NULL). If we still don't
19337 have an absolute path prepend comp_dir (if non-NULL).
19338 However, the directory we record in the include-file's
19339 psymtab does not contain COMP_DIR (to match the
19340 corresponding symtab(s)).
19345 bash$ gcc -g ./hello.c
19346 include_name = "hello.c"
19348 DW_AT_comp_dir = comp_dir = "/tmp"
19349 DW_AT_name = "./hello.c"
19353 if (dir_name
!= NULL
)
19355 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19356 include_name
, (char *) NULL
));
19357 include_name
= name_holder
->get ();
19358 include_name_to_compare
= include_name
;
19360 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19362 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19363 include_name
, (char *) NULL
));
19364 include_name_to_compare
= hold_compare
.get ();
19368 pst_filename
= pst
->filename
;
19369 gdb::unique_xmalloc_ptr
<char> copied_name
;
19370 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19372 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19373 pst_filename
, (char *) NULL
));
19374 pst_filename
= copied_name
.get ();
19377 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19381 return include_name
;
19384 /* State machine to track the state of the line number program. */
19386 class lnp_state_machine
19389 /* Initialize a machine state for the start of a line number
19391 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19392 bool record_lines_p
);
19394 file_entry
*current_file ()
19396 /* lh->file_names is 0-based, but the file name numbers in the
19397 statement program are 1-based. */
19398 return m_line_header
->file_name_at (m_file
);
19401 /* Record the line in the state machine. END_SEQUENCE is true if
19402 we're processing the end of a sequence. */
19403 void record_line (bool end_sequence
);
19405 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19406 nop-out rest of the lines in this sequence. */
19407 void check_line_address (struct dwarf2_cu
*cu
,
19408 const gdb_byte
*line_ptr
,
19409 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19411 void handle_set_discriminator (unsigned int discriminator
)
19413 m_discriminator
= discriminator
;
19414 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19417 /* Handle DW_LNE_set_address. */
19418 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19421 address
+= baseaddr
;
19422 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19425 /* Handle DW_LNS_advance_pc. */
19426 void handle_advance_pc (CORE_ADDR adjust
);
19428 /* Handle a special opcode. */
19429 void handle_special_opcode (unsigned char op_code
);
19431 /* Handle DW_LNS_advance_line. */
19432 void handle_advance_line (int line_delta
)
19434 advance_line (line_delta
);
19437 /* Handle DW_LNS_set_file. */
19438 void handle_set_file (file_name_index file
);
19440 /* Handle DW_LNS_negate_stmt. */
19441 void handle_negate_stmt ()
19443 m_is_stmt
= !m_is_stmt
;
19446 /* Handle DW_LNS_const_add_pc. */
19447 void handle_const_add_pc ();
19449 /* Handle DW_LNS_fixed_advance_pc. */
19450 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19452 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19456 /* Handle DW_LNS_copy. */
19457 void handle_copy ()
19459 record_line (false);
19460 m_discriminator
= 0;
19463 /* Handle DW_LNE_end_sequence. */
19464 void handle_end_sequence ()
19466 m_currently_recording_lines
= true;
19470 /* Advance the line by LINE_DELTA. */
19471 void advance_line (int line_delta
)
19473 m_line
+= line_delta
;
19475 if (line_delta
!= 0)
19476 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19479 struct dwarf2_cu
*m_cu
;
19481 gdbarch
*m_gdbarch
;
19483 /* True if we're recording lines.
19484 Otherwise we're building partial symtabs and are just interested in
19485 finding include files mentioned by the line number program. */
19486 bool m_record_lines_p
;
19488 /* The line number header. */
19489 line_header
*m_line_header
;
19491 /* These are part of the standard DWARF line number state machine,
19492 and initialized according to the DWARF spec. */
19494 unsigned char m_op_index
= 0;
19495 /* The line table index of the current file. */
19496 file_name_index m_file
= 1;
19497 unsigned int m_line
= 1;
19499 /* These are initialized in the constructor. */
19501 CORE_ADDR m_address
;
19503 unsigned int m_discriminator
;
19505 /* Additional bits of state we need to track. */
19507 /* The last file that we called dwarf2_start_subfile for.
19508 This is only used for TLLs. */
19509 unsigned int m_last_file
= 0;
19510 /* The last file a line number was recorded for. */
19511 struct subfile
*m_last_subfile
= NULL
;
19513 /* When true, record the lines we decode. */
19514 bool m_currently_recording_lines
= false;
19516 /* The last line number that was recorded, used to coalesce
19517 consecutive entries for the same line. This can happen, for
19518 example, when discriminators are present. PR 17276. */
19519 unsigned int m_last_line
= 0;
19520 bool m_line_has_non_zero_discriminator
= false;
19524 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19526 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19527 / m_line_header
->maximum_ops_per_instruction
)
19528 * m_line_header
->minimum_instruction_length
);
19529 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19530 m_op_index
= ((m_op_index
+ adjust
)
19531 % m_line_header
->maximum_ops_per_instruction
);
19535 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19537 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19538 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19539 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19540 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19541 / m_line_header
->maximum_ops_per_instruction
)
19542 * m_line_header
->minimum_instruction_length
);
19543 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19544 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19545 % m_line_header
->maximum_ops_per_instruction
);
19547 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19548 advance_line (line_delta
);
19549 record_line (false);
19550 m_discriminator
= 0;
19554 lnp_state_machine::handle_set_file (file_name_index file
)
19558 const file_entry
*fe
= current_file ();
19560 dwarf2_debug_line_missing_file_complaint ();
19561 else if (m_record_lines_p
)
19563 const char *dir
= fe
->include_dir (m_line_header
);
19565 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19566 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19567 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19572 lnp_state_machine::handle_const_add_pc ()
19575 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19578 = (((m_op_index
+ adjust
)
19579 / m_line_header
->maximum_ops_per_instruction
)
19580 * m_line_header
->minimum_instruction_length
);
19582 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19583 m_op_index
= ((m_op_index
+ adjust
)
19584 % m_line_header
->maximum_ops_per_instruction
);
19587 /* Return non-zero if we should add LINE to the line number table.
19588 LINE is the line to add, LAST_LINE is the last line that was added,
19589 LAST_SUBFILE is the subfile for LAST_LINE.
19590 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19591 had a non-zero discriminator.
19593 We have to be careful in the presence of discriminators.
19594 E.g., for this line:
19596 for (i = 0; i < 100000; i++);
19598 clang can emit four line number entries for that one line,
19599 each with a different discriminator.
19600 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19602 However, we want gdb to coalesce all four entries into one.
19603 Otherwise the user could stepi into the middle of the line and
19604 gdb would get confused about whether the pc really was in the
19605 middle of the line.
19607 Things are further complicated by the fact that two consecutive
19608 line number entries for the same line is a heuristic used by gcc
19609 to denote the end of the prologue. So we can't just discard duplicate
19610 entries, we have to be selective about it. The heuristic we use is
19611 that we only collapse consecutive entries for the same line if at least
19612 one of those entries has a non-zero discriminator. PR 17276.
19614 Note: Addresses in the line number state machine can never go backwards
19615 within one sequence, thus this coalescing is ok. */
19618 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19619 unsigned int line
, unsigned int last_line
,
19620 int line_has_non_zero_discriminator
,
19621 struct subfile
*last_subfile
)
19623 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19625 if (line
!= last_line
)
19627 /* Same line for the same file that we've seen already.
19628 As a last check, for pr 17276, only record the line if the line
19629 has never had a non-zero discriminator. */
19630 if (!line_has_non_zero_discriminator
)
19635 /* Use the CU's builder to record line number LINE beginning at
19636 address ADDRESS in the line table of subfile SUBFILE. */
19639 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19640 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
19641 struct dwarf2_cu
*cu
)
19643 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19645 if (dwarf_line_debug
)
19647 fprintf_unfiltered (gdb_stdlog
,
19648 "Recording line %u, file %s, address %s\n",
19649 line
, lbasename (subfile
->name
),
19650 paddress (gdbarch
, address
));
19654 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
19657 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19658 Mark the end of a set of line number records.
19659 The arguments are the same as for dwarf_record_line_1.
19660 If SUBFILE is NULL the request is ignored. */
19663 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19664 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19666 if (subfile
== NULL
)
19669 if (dwarf_line_debug
)
19671 fprintf_unfiltered (gdb_stdlog
,
19672 "Finishing current line, file %s, address %s\n",
19673 lbasename (subfile
->name
),
19674 paddress (gdbarch
, address
));
19677 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
19681 lnp_state_machine::record_line (bool end_sequence
)
19683 if (dwarf_line_debug
)
19685 fprintf_unfiltered (gdb_stdlog
,
19686 "Processing actual line %u: file %u,"
19687 " address %s, is_stmt %u, discrim %u%s\n",
19689 paddress (m_gdbarch
, m_address
),
19690 m_is_stmt
, m_discriminator
,
19691 (end_sequence
? "\t(end sequence)" : ""));
19694 file_entry
*fe
= current_file ();
19697 dwarf2_debug_line_missing_file_complaint ();
19698 /* For now we ignore lines not starting on an instruction boundary.
19699 But not when processing end_sequence for compatibility with the
19700 previous version of the code. */
19701 else if (m_op_index
== 0 || end_sequence
)
19703 fe
->included_p
= 1;
19704 if (m_record_lines_p
)
19706 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19709 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19710 m_currently_recording_lines
? m_cu
: nullptr);
19715 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
19717 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19718 m_line_has_non_zero_discriminator
,
19721 buildsym_compunit
*builder
= m_cu
->get_builder ();
19722 dwarf_record_line_1 (m_gdbarch
,
19723 builder
->get_current_subfile (),
19724 m_line
, m_address
, is_stmt
,
19725 m_currently_recording_lines
? m_cu
: nullptr);
19727 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19728 m_last_line
= m_line
;
19734 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
19735 line_header
*lh
, bool record_lines_p
)
19739 m_record_lines_p
= record_lines_p
;
19740 m_line_header
= lh
;
19742 m_currently_recording_lines
= true;
19744 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
19745 was a line entry for it so that the backend has a chance to adjust it
19746 and also record it in case it needs it. This is currently used by MIPS
19747 code, cf. `mips_adjust_dwarf2_line'. */
19748 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
19749 m_is_stmt
= lh
->default_is_stmt
;
19750 m_discriminator
= 0;
19754 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
19755 const gdb_byte
*line_ptr
,
19756 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
19758 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
19759 the pc range of the CU. However, we restrict the test to only ADDRESS
19760 values of zero to preserve GDB's previous behaviour which is to handle
19761 the specific case of a function being GC'd by the linker. */
19763 if (address
== 0 && address
< unrelocated_lowpc
)
19765 /* This line table is for a function which has been
19766 GCd by the linker. Ignore it. PR gdb/12528 */
19768 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19769 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
19771 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
19772 line_offset
, objfile_name (objfile
));
19773 m_currently_recording_lines
= false;
19774 /* Note: m_currently_recording_lines is left as false until we see
19775 DW_LNE_end_sequence. */
19779 /* Subroutine of dwarf_decode_lines to simplify it.
19780 Process the line number information in LH.
19781 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
19782 program in order to set included_p for every referenced header. */
19785 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
19786 const int decode_for_pst_p
, CORE_ADDR lowpc
)
19788 const gdb_byte
*line_ptr
, *extended_end
;
19789 const gdb_byte
*line_end
;
19790 unsigned int bytes_read
, extended_len
;
19791 unsigned char op_code
, extended_op
;
19792 CORE_ADDR baseaddr
;
19793 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19794 bfd
*abfd
= objfile
->obfd
;
19795 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19796 /* True if we're recording line info (as opposed to building partial
19797 symtabs and just interested in finding include files mentioned by
19798 the line number program). */
19799 bool record_lines_p
= !decode_for_pst_p
;
19801 baseaddr
= objfile
->text_section_offset ();
19803 line_ptr
= lh
->statement_program_start
;
19804 line_end
= lh
->statement_program_end
;
19806 /* Read the statement sequences until there's nothing left. */
19807 while (line_ptr
< line_end
)
19809 /* The DWARF line number program state machine. Reset the state
19810 machine at the start of each sequence. */
19811 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
19812 bool end_sequence
= false;
19814 if (record_lines_p
)
19816 /* Start a subfile for the current file of the state
19818 const file_entry
*fe
= state_machine
.current_file ();
19821 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
19824 /* Decode the table. */
19825 while (line_ptr
< line_end
&& !end_sequence
)
19827 op_code
= read_1_byte (abfd
, line_ptr
);
19830 if (op_code
>= lh
->opcode_base
)
19832 /* Special opcode. */
19833 state_machine
.handle_special_opcode (op_code
);
19835 else switch (op_code
)
19837 case DW_LNS_extended_op
:
19838 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
19840 line_ptr
+= bytes_read
;
19841 extended_end
= line_ptr
+ extended_len
;
19842 extended_op
= read_1_byte (abfd
, line_ptr
);
19844 switch (extended_op
)
19846 case DW_LNE_end_sequence
:
19847 state_machine
.handle_end_sequence ();
19848 end_sequence
= true;
19850 case DW_LNE_set_address
:
19853 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
19854 line_ptr
+= bytes_read
;
19856 state_machine
.check_line_address (cu
, line_ptr
,
19857 lowpc
- baseaddr
, address
);
19858 state_machine
.handle_set_address (baseaddr
, address
);
19861 case DW_LNE_define_file
:
19863 const char *cur_file
;
19864 unsigned int mod_time
, length
;
19867 cur_file
= read_direct_string (abfd
, line_ptr
,
19869 line_ptr
+= bytes_read
;
19870 dindex
= (dir_index
)
19871 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19872 line_ptr
+= bytes_read
;
19874 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19875 line_ptr
+= bytes_read
;
19877 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19878 line_ptr
+= bytes_read
;
19879 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
19882 case DW_LNE_set_discriminator
:
19884 /* The discriminator is not interesting to the
19885 debugger; just ignore it. We still need to
19886 check its value though:
19887 if there are consecutive entries for the same
19888 (non-prologue) line we want to coalesce them.
19891 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19892 line_ptr
+= bytes_read
;
19894 state_machine
.handle_set_discriminator (discr
);
19898 complaint (_("mangled .debug_line section"));
19901 /* Make sure that we parsed the extended op correctly. If e.g.
19902 we expected a different address size than the producer used,
19903 we may have read the wrong number of bytes. */
19904 if (line_ptr
!= extended_end
)
19906 complaint (_("mangled .debug_line section"));
19911 state_machine
.handle_copy ();
19913 case DW_LNS_advance_pc
:
19916 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19917 line_ptr
+= bytes_read
;
19919 state_machine
.handle_advance_pc (adjust
);
19922 case DW_LNS_advance_line
:
19925 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
19926 line_ptr
+= bytes_read
;
19928 state_machine
.handle_advance_line (line_delta
);
19931 case DW_LNS_set_file
:
19933 file_name_index file
19934 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
19936 line_ptr
+= bytes_read
;
19938 state_machine
.handle_set_file (file
);
19941 case DW_LNS_set_column
:
19942 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19943 line_ptr
+= bytes_read
;
19945 case DW_LNS_negate_stmt
:
19946 state_machine
.handle_negate_stmt ();
19948 case DW_LNS_set_basic_block
:
19950 /* Add to the address register of the state machine the
19951 address increment value corresponding to special opcode
19952 255. I.e., this value is scaled by the minimum
19953 instruction length since special opcode 255 would have
19954 scaled the increment. */
19955 case DW_LNS_const_add_pc
:
19956 state_machine
.handle_const_add_pc ();
19958 case DW_LNS_fixed_advance_pc
:
19960 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
19963 state_machine
.handle_fixed_advance_pc (addr_adj
);
19968 /* Unknown standard opcode, ignore it. */
19971 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
19973 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19974 line_ptr
+= bytes_read
;
19981 dwarf2_debug_line_missing_end_sequence_complaint ();
19983 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
19984 in which case we still finish recording the last line). */
19985 state_machine
.record_line (true);
19989 /* Decode the Line Number Program (LNP) for the given line_header
19990 structure and CU. The actual information extracted and the type
19991 of structures created from the LNP depends on the value of PST.
19993 1. If PST is NULL, then this procedure uses the data from the program
19994 to create all necessary symbol tables, and their linetables.
19996 2. If PST is not NULL, this procedure reads the program to determine
19997 the list of files included by the unit represented by PST, and
19998 builds all the associated partial symbol tables.
20000 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20001 It is used for relative paths in the line table.
20002 NOTE: When processing partial symtabs (pst != NULL),
20003 comp_dir == pst->dirname.
20005 NOTE: It is important that psymtabs have the same file name (via strcmp)
20006 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20007 symtab we don't use it in the name of the psymtabs we create.
20008 E.g. expand_line_sal requires this when finding psymtabs to expand.
20009 A good testcase for this is mb-inline.exp.
20011 LOWPC is the lowest address in CU (or 0 if not known).
20013 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20014 for its PC<->lines mapping information. Otherwise only the filename
20015 table is read in. */
20018 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20019 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20020 CORE_ADDR lowpc
, int decode_mapping
)
20022 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20023 const int decode_for_pst_p
= (pst
!= NULL
);
20025 if (decode_mapping
)
20026 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20028 if (decode_for_pst_p
)
20030 /* Now that we're done scanning the Line Header Program, we can
20031 create the psymtab of each included file. */
20032 for (auto &file_entry
: lh
->file_names ())
20033 if (file_entry
.included_p
== 1)
20035 gdb::unique_xmalloc_ptr
<char> name_holder
;
20036 const char *include_name
=
20037 psymtab_include_file_name (lh
, file_entry
, pst
,
20038 comp_dir
, &name_holder
);
20039 if (include_name
!= NULL
)
20040 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20045 /* Make sure a symtab is created for every file, even files
20046 which contain only variables (i.e. no code with associated
20048 buildsym_compunit
*builder
= cu
->get_builder ();
20049 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20051 for (auto &fe
: lh
->file_names ())
20053 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20054 if (builder
->get_current_subfile ()->symtab
== NULL
)
20056 builder
->get_current_subfile ()->symtab
20057 = allocate_symtab (cust
,
20058 builder
->get_current_subfile ()->name
);
20060 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20065 /* Start a subfile for DWARF. FILENAME is the name of the file and
20066 DIRNAME the name of the source directory which contains FILENAME
20067 or NULL if not known.
20068 This routine tries to keep line numbers from identical absolute and
20069 relative file names in a common subfile.
20071 Using the `list' example from the GDB testsuite, which resides in
20072 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20073 of /srcdir/list0.c yields the following debugging information for list0.c:
20075 DW_AT_name: /srcdir/list0.c
20076 DW_AT_comp_dir: /compdir
20077 files.files[0].name: list0.h
20078 files.files[0].dir: /srcdir
20079 files.files[1].name: list0.c
20080 files.files[1].dir: /srcdir
20082 The line number information for list0.c has to end up in a single
20083 subfile, so that `break /srcdir/list0.c:1' works as expected.
20084 start_subfile will ensure that this happens provided that we pass the
20085 concatenation of files.files[1].dir and files.files[1].name as the
20089 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20090 const char *dirname
)
20092 gdb::unique_xmalloc_ptr
<char> copy
;
20094 /* In order not to lose the line information directory,
20095 we concatenate it to the filename when it makes sense.
20096 Note that the Dwarf3 standard says (speaking of filenames in line
20097 information): ``The directory index is ignored for file names
20098 that represent full path names''. Thus ignoring dirname in the
20099 `else' branch below isn't an issue. */
20101 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20103 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20104 filename
= copy
.get ();
20107 cu
->get_builder ()->start_subfile (filename
);
20110 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20111 buildsym_compunit constructor. */
20113 struct compunit_symtab
*
20114 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20117 gdb_assert (m_builder
== nullptr);
20119 m_builder
.reset (new struct buildsym_compunit
20120 (per_cu
->dwarf2_per_objfile
->objfile
,
20121 name
, comp_dir
, language
, low_pc
));
20123 list_in_scope
= get_builder ()->get_file_symbols ();
20125 get_builder ()->record_debugformat ("DWARF 2");
20126 get_builder ()->record_producer (producer
);
20128 processing_has_namespace_info
= false;
20130 return get_builder ()->get_compunit_symtab ();
20134 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20135 struct dwarf2_cu
*cu
)
20137 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20138 struct comp_unit_head
*cu_header
= &cu
->header
;
20140 /* NOTE drow/2003-01-30: There used to be a comment and some special
20141 code here to turn a symbol with DW_AT_external and a
20142 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20143 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20144 with some versions of binutils) where shared libraries could have
20145 relocations against symbols in their debug information - the
20146 minimal symbol would have the right address, but the debug info
20147 would not. It's no longer necessary, because we will explicitly
20148 apply relocations when we read in the debug information now. */
20150 /* A DW_AT_location attribute with no contents indicates that a
20151 variable has been optimized away. */
20152 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20154 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20158 /* Handle one degenerate form of location expression specially, to
20159 preserve GDB's previous behavior when section offsets are
20160 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20161 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20163 if (attr
->form_is_block ()
20164 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20165 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20166 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20167 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20168 && (DW_BLOCK (attr
)->size
20169 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20171 unsigned int dummy
;
20173 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20174 SET_SYMBOL_VALUE_ADDRESS
20175 (sym
, cu
->header
.read_address (objfile
->obfd
,
20176 DW_BLOCK (attr
)->data
+ 1,
20179 SET_SYMBOL_VALUE_ADDRESS
20180 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20182 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20183 fixup_symbol_section (sym
, objfile
);
20184 SET_SYMBOL_VALUE_ADDRESS
20186 SYMBOL_VALUE_ADDRESS (sym
)
20187 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20191 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20192 expression evaluator, and use LOC_COMPUTED only when necessary
20193 (i.e. when the value of a register or memory location is
20194 referenced, or a thread-local block, etc.). Then again, it might
20195 not be worthwhile. I'm assuming that it isn't unless performance
20196 or memory numbers show me otherwise. */
20198 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20200 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20201 cu
->has_loclist
= true;
20204 /* Given a pointer to a DWARF information entry, figure out if we need
20205 to make a symbol table entry for it, and if so, create a new entry
20206 and return a pointer to it.
20207 If TYPE is NULL, determine symbol type from the die, otherwise
20208 used the passed type.
20209 If SPACE is not NULL, use it to hold the new symbol. If it is
20210 NULL, allocate a new symbol on the objfile's obstack. */
20212 static struct symbol
*
20213 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20214 struct symbol
*space
)
20216 struct dwarf2_per_objfile
*dwarf2_per_objfile
20217 = cu
->per_cu
->dwarf2_per_objfile
;
20218 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20219 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20220 struct symbol
*sym
= NULL
;
20222 struct attribute
*attr
= NULL
;
20223 struct attribute
*attr2
= NULL
;
20224 CORE_ADDR baseaddr
;
20225 struct pending
**list_to_add
= NULL
;
20227 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20229 baseaddr
= objfile
->text_section_offset ();
20231 name
= dwarf2_name (die
, cu
);
20234 const char *linkagename
;
20235 int suppress_add
= 0;
20240 sym
= allocate_symbol (objfile
);
20241 OBJSTAT (objfile
, n_syms
++);
20243 /* Cache this symbol's name and the name's demangled form (if any). */
20244 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20245 linkagename
= dwarf2_physname (name
, die
, cu
);
20246 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20248 /* Fortran does not have mangling standard and the mangling does differ
20249 between gfortran, iFort etc. */
20250 if (cu
->language
== language_fortran
20251 && symbol_get_demangled_name (sym
) == NULL
)
20252 symbol_set_demangled_name (sym
,
20253 dwarf2_full_name (name
, die
, cu
),
20256 /* Default assumptions.
20257 Use the passed type or decode it from the die. */
20258 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20259 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20261 SYMBOL_TYPE (sym
) = type
;
20263 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20264 attr
= dwarf2_attr (die
,
20265 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20267 if (attr
!= nullptr)
20269 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20272 attr
= dwarf2_attr (die
,
20273 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20275 if (attr
!= nullptr)
20277 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20278 struct file_entry
*fe
;
20280 if (cu
->line_header
!= NULL
)
20281 fe
= cu
->line_header
->file_name_at (file_index
);
20286 complaint (_("file index out of range"));
20288 symbol_set_symtab (sym
, fe
->symtab
);
20294 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20295 if (attr
!= nullptr)
20299 addr
= attr
->value_as_address ();
20300 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20301 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20303 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20304 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20305 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20306 add_symbol_to_list (sym
, cu
->list_in_scope
);
20308 case DW_TAG_subprogram
:
20309 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20311 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20312 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20313 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20314 || cu
->language
== language_ada
20315 || cu
->language
== language_fortran
)
20317 /* Subprograms marked external are stored as a global symbol.
20318 Ada and Fortran subprograms, whether marked external or
20319 not, are always stored as a global symbol, because we want
20320 to be able to access them globally. For instance, we want
20321 to be able to break on a nested subprogram without having
20322 to specify the context. */
20323 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20327 list_to_add
= cu
->list_in_scope
;
20330 case DW_TAG_inlined_subroutine
:
20331 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20333 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20334 SYMBOL_INLINED (sym
) = 1;
20335 list_to_add
= cu
->list_in_scope
;
20337 case DW_TAG_template_value_param
:
20339 /* Fall through. */
20340 case DW_TAG_constant
:
20341 case DW_TAG_variable
:
20342 case DW_TAG_member
:
20343 /* Compilation with minimal debug info may result in
20344 variables with missing type entries. Change the
20345 misleading `void' type to something sensible. */
20346 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20347 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20349 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20350 /* In the case of DW_TAG_member, we should only be called for
20351 static const members. */
20352 if (die
->tag
== DW_TAG_member
)
20354 /* dwarf2_add_field uses die_is_declaration,
20355 so we do the same. */
20356 gdb_assert (die_is_declaration (die
, cu
));
20359 if (attr
!= nullptr)
20361 dwarf2_const_value (attr
, sym
, cu
);
20362 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20365 if (attr2
&& (DW_UNSND (attr2
) != 0))
20366 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20368 list_to_add
= cu
->list_in_scope
;
20372 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20373 if (attr
!= nullptr)
20375 var_decode_location (attr
, sym
, cu
);
20376 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20378 /* Fortran explicitly imports any global symbols to the local
20379 scope by DW_TAG_common_block. */
20380 if (cu
->language
== language_fortran
&& die
->parent
20381 && die
->parent
->tag
== DW_TAG_common_block
)
20384 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20385 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20386 && !dwarf2_per_objfile
->has_section_at_zero
)
20388 /* When a static variable is eliminated by the linker,
20389 the corresponding debug information is not stripped
20390 out, but the variable address is set to null;
20391 do not add such variables into symbol table. */
20393 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20395 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20396 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20397 && dwarf2_per_objfile
->can_copy
)
20399 /* A global static variable might be subject to
20400 copy relocation. We first check for a local
20401 minsym, though, because maybe the symbol was
20402 marked hidden, in which case this would not
20404 bound_minimal_symbol found
20405 = (lookup_minimal_symbol_linkage
20406 (sym
->linkage_name (), objfile
));
20407 if (found
.minsym
!= nullptr)
20408 sym
->maybe_copied
= 1;
20411 /* A variable with DW_AT_external is never static,
20412 but it may be block-scoped. */
20414 = ((cu
->list_in_scope
20415 == cu
->get_builder ()->get_file_symbols ())
20416 ? cu
->get_builder ()->get_global_symbols ()
20417 : cu
->list_in_scope
);
20420 list_to_add
= cu
->list_in_scope
;
20424 /* We do not know the address of this symbol.
20425 If it is an external symbol and we have type information
20426 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20427 The address of the variable will then be determined from
20428 the minimal symbol table whenever the variable is
20430 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20432 /* Fortran explicitly imports any global symbols to the local
20433 scope by DW_TAG_common_block. */
20434 if (cu
->language
== language_fortran
&& die
->parent
20435 && die
->parent
->tag
== DW_TAG_common_block
)
20437 /* SYMBOL_CLASS doesn't matter here because
20438 read_common_block is going to reset it. */
20440 list_to_add
= cu
->list_in_scope
;
20442 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20443 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20445 /* A variable with DW_AT_external is never static, but it
20446 may be block-scoped. */
20448 = ((cu
->list_in_scope
20449 == cu
->get_builder ()->get_file_symbols ())
20450 ? cu
->get_builder ()->get_global_symbols ()
20451 : cu
->list_in_scope
);
20453 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20455 else if (!die_is_declaration (die
, cu
))
20457 /* Use the default LOC_OPTIMIZED_OUT class. */
20458 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20460 list_to_add
= cu
->list_in_scope
;
20464 case DW_TAG_formal_parameter
:
20466 /* If we are inside a function, mark this as an argument. If
20467 not, we might be looking at an argument to an inlined function
20468 when we do not have enough information to show inlined frames;
20469 pretend it's a local variable in that case so that the user can
20471 struct context_stack
*curr
20472 = cu
->get_builder ()->get_current_context_stack ();
20473 if (curr
!= nullptr && curr
->name
!= nullptr)
20474 SYMBOL_IS_ARGUMENT (sym
) = 1;
20475 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20476 if (attr
!= nullptr)
20478 var_decode_location (attr
, sym
, cu
);
20480 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20481 if (attr
!= nullptr)
20483 dwarf2_const_value (attr
, sym
, cu
);
20486 list_to_add
= cu
->list_in_scope
;
20489 case DW_TAG_unspecified_parameters
:
20490 /* From varargs functions; gdb doesn't seem to have any
20491 interest in this information, so just ignore it for now.
20494 case DW_TAG_template_type_param
:
20496 /* Fall through. */
20497 case DW_TAG_class_type
:
20498 case DW_TAG_interface_type
:
20499 case DW_TAG_structure_type
:
20500 case DW_TAG_union_type
:
20501 case DW_TAG_set_type
:
20502 case DW_TAG_enumeration_type
:
20503 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20504 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20507 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20508 really ever be static objects: otherwise, if you try
20509 to, say, break of a class's method and you're in a file
20510 which doesn't mention that class, it won't work unless
20511 the check for all static symbols in lookup_symbol_aux
20512 saves you. See the OtherFileClass tests in
20513 gdb.c++/namespace.exp. */
20517 buildsym_compunit
*builder
= cu
->get_builder ();
20519 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20520 && cu
->language
== language_cplus
20521 ? builder
->get_global_symbols ()
20522 : cu
->list_in_scope
);
20524 /* The semantics of C++ state that "struct foo {
20525 ... }" also defines a typedef for "foo". */
20526 if (cu
->language
== language_cplus
20527 || cu
->language
== language_ada
20528 || cu
->language
== language_d
20529 || cu
->language
== language_rust
)
20531 /* The symbol's name is already allocated along
20532 with this objfile, so we don't need to
20533 duplicate it for the type. */
20534 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20535 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20540 case DW_TAG_typedef
:
20541 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20542 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20543 list_to_add
= cu
->list_in_scope
;
20545 case DW_TAG_base_type
:
20546 case DW_TAG_subrange_type
:
20547 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20548 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20549 list_to_add
= cu
->list_in_scope
;
20551 case DW_TAG_enumerator
:
20552 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20553 if (attr
!= nullptr)
20555 dwarf2_const_value (attr
, sym
, cu
);
20558 /* NOTE: carlton/2003-11-10: See comment above in the
20559 DW_TAG_class_type, etc. block. */
20562 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20563 && cu
->language
== language_cplus
20564 ? cu
->get_builder ()->get_global_symbols ()
20565 : cu
->list_in_scope
);
20568 case DW_TAG_imported_declaration
:
20569 case DW_TAG_namespace
:
20570 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20571 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20573 case DW_TAG_module
:
20574 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20575 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20576 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20578 case DW_TAG_common_block
:
20579 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20580 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20581 add_symbol_to_list (sym
, cu
->list_in_scope
);
20584 /* Not a tag we recognize. Hopefully we aren't processing
20585 trash data, but since we must specifically ignore things
20586 we don't recognize, there is nothing else we should do at
20588 complaint (_("unsupported tag: '%s'"),
20589 dwarf_tag_name (die
->tag
));
20595 sym
->hash_next
= objfile
->template_symbols
;
20596 objfile
->template_symbols
= sym
;
20597 list_to_add
= NULL
;
20600 if (list_to_add
!= NULL
)
20601 add_symbol_to_list (sym
, list_to_add
);
20603 /* For the benefit of old versions of GCC, check for anonymous
20604 namespaces based on the demangled name. */
20605 if (!cu
->processing_has_namespace_info
20606 && cu
->language
== language_cplus
)
20607 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20612 /* Given an attr with a DW_FORM_dataN value in host byte order,
20613 zero-extend it as appropriate for the symbol's type. The DWARF
20614 standard (v4) is not entirely clear about the meaning of using
20615 DW_FORM_dataN for a constant with a signed type, where the type is
20616 wider than the data. The conclusion of a discussion on the DWARF
20617 list was that this is unspecified. We choose to always zero-extend
20618 because that is the interpretation long in use by GCC. */
20621 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20622 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20624 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20625 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20626 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20627 LONGEST l
= DW_UNSND (attr
);
20629 if (bits
< sizeof (*value
) * 8)
20631 l
&= ((LONGEST
) 1 << bits
) - 1;
20634 else if (bits
== sizeof (*value
) * 8)
20638 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20639 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20646 /* Read a constant value from an attribute. Either set *VALUE, or if
20647 the value does not fit in *VALUE, set *BYTES - either already
20648 allocated on the objfile obstack, or newly allocated on OBSTACK,
20649 or, set *BATON, if we translated the constant to a location
20653 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20654 const char *name
, struct obstack
*obstack
,
20655 struct dwarf2_cu
*cu
,
20656 LONGEST
*value
, const gdb_byte
**bytes
,
20657 struct dwarf2_locexpr_baton
**baton
)
20659 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20660 struct comp_unit_head
*cu_header
= &cu
->header
;
20661 struct dwarf_block
*blk
;
20662 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20663 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20669 switch (attr
->form
)
20672 case DW_FORM_addrx
:
20673 case DW_FORM_GNU_addr_index
:
20677 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20678 dwarf2_const_value_length_mismatch_complaint (name
,
20679 cu_header
->addr_size
,
20680 TYPE_LENGTH (type
));
20681 /* Symbols of this form are reasonably rare, so we just
20682 piggyback on the existing location code rather than writing
20683 a new implementation of symbol_computed_ops. */
20684 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20685 (*baton
)->per_cu
= cu
->per_cu
;
20686 gdb_assert ((*baton
)->per_cu
);
20688 (*baton
)->size
= 2 + cu_header
->addr_size
;
20689 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20690 (*baton
)->data
= data
;
20692 data
[0] = DW_OP_addr
;
20693 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20694 byte_order
, DW_ADDR (attr
));
20695 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20698 case DW_FORM_string
:
20701 case DW_FORM_GNU_str_index
:
20702 case DW_FORM_GNU_strp_alt
:
20703 /* DW_STRING is already allocated on the objfile obstack, point
20705 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20707 case DW_FORM_block1
:
20708 case DW_FORM_block2
:
20709 case DW_FORM_block4
:
20710 case DW_FORM_block
:
20711 case DW_FORM_exprloc
:
20712 case DW_FORM_data16
:
20713 blk
= DW_BLOCK (attr
);
20714 if (TYPE_LENGTH (type
) != blk
->size
)
20715 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20716 TYPE_LENGTH (type
));
20717 *bytes
= blk
->data
;
20720 /* The DW_AT_const_value attributes are supposed to carry the
20721 symbol's value "represented as it would be on the target
20722 architecture." By the time we get here, it's already been
20723 converted to host endianness, so we just need to sign- or
20724 zero-extend it as appropriate. */
20725 case DW_FORM_data1
:
20726 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20728 case DW_FORM_data2
:
20729 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20731 case DW_FORM_data4
:
20732 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
20734 case DW_FORM_data8
:
20735 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
20738 case DW_FORM_sdata
:
20739 case DW_FORM_implicit_const
:
20740 *value
= DW_SND (attr
);
20743 case DW_FORM_udata
:
20744 *value
= DW_UNSND (attr
);
20748 complaint (_("unsupported const value attribute form: '%s'"),
20749 dwarf_form_name (attr
->form
));
20756 /* Copy constant value from an attribute to a symbol. */
20759 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
20760 struct dwarf2_cu
*cu
)
20762 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20764 const gdb_byte
*bytes
;
20765 struct dwarf2_locexpr_baton
*baton
;
20767 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
20768 sym
->print_name (),
20769 &objfile
->objfile_obstack
, cu
,
20770 &value
, &bytes
, &baton
);
20774 SYMBOL_LOCATION_BATON (sym
) = baton
;
20775 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
20777 else if (bytes
!= NULL
)
20779 SYMBOL_VALUE_BYTES (sym
) = bytes
;
20780 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
20784 SYMBOL_VALUE (sym
) = value
;
20785 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
20789 /* Return the type of the die in question using its DW_AT_type attribute. */
20791 static struct type
*
20792 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20794 struct attribute
*type_attr
;
20796 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
20799 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20800 /* A missing DW_AT_type represents a void type. */
20801 return objfile_type (objfile
)->builtin_void
;
20804 return lookup_die_type (die
, type_attr
, cu
);
20807 /* True iff CU's producer generates GNAT Ada auxiliary information
20808 that allows to find parallel types through that information instead
20809 of having to do expensive parallel lookups by type name. */
20812 need_gnat_info (struct dwarf2_cu
*cu
)
20814 /* Assume that the Ada compiler was GNAT, which always produces
20815 the auxiliary information. */
20816 return (cu
->language
== language_ada
);
20819 /* Return the auxiliary type of the die in question using its
20820 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
20821 attribute is not present. */
20823 static struct type
*
20824 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20826 struct attribute
*type_attr
;
20828 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
20832 return lookup_die_type (die
, type_attr
, cu
);
20835 /* If DIE has a descriptive_type attribute, then set the TYPE's
20836 descriptive type accordingly. */
20839 set_descriptive_type (struct type
*type
, struct die_info
*die
,
20840 struct dwarf2_cu
*cu
)
20842 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
20844 if (descriptive_type
)
20846 ALLOCATE_GNAT_AUX_TYPE (type
);
20847 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
20851 /* Return the containing type of the die in question using its
20852 DW_AT_containing_type attribute. */
20854 static struct type
*
20855 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20857 struct attribute
*type_attr
;
20858 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20860 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
20862 error (_("Dwarf Error: Problem turning containing type into gdb type "
20863 "[in module %s]"), objfile_name (objfile
));
20865 return lookup_die_type (die
, type_attr
, cu
);
20868 /* Return an error marker type to use for the ill formed type in DIE/CU. */
20870 static struct type
*
20871 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
20873 struct dwarf2_per_objfile
*dwarf2_per_objfile
20874 = cu
->per_cu
->dwarf2_per_objfile
;
20875 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20878 std::string message
20879 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
20880 objfile_name (objfile
),
20881 sect_offset_str (cu
->header
.sect_off
),
20882 sect_offset_str (die
->sect_off
));
20883 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
20885 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
20888 /* Look up the type of DIE in CU using its type attribute ATTR.
20889 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
20890 DW_AT_containing_type.
20891 If there is no type substitute an error marker. */
20893 static struct type
*
20894 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
20895 struct dwarf2_cu
*cu
)
20897 struct dwarf2_per_objfile
*dwarf2_per_objfile
20898 = cu
->per_cu
->dwarf2_per_objfile
;
20899 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20900 struct type
*this_type
;
20902 gdb_assert (attr
->name
== DW_AT_type
20903 || attr
->name
== DW_AT_GNAT_descriptive_type
20904 || attr
->name
== DW_AT_containing_type
);
20906 /* First see if we have it cached. */
20908 if (attr
->form
== DW_FORM_GNU_ref_alt
)
20910 struct dwarf2_per_cu_data
*per_cu
;
20911 sect_offset sect_off
= attr
->get_ref_die_offset ();
20913 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
20914 dwarf2_per_objfile
);
20915 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
20917 else if (attr
->form_is_ref ())
20919 sect_offset sect_off
= attr
->get_ref_die_offset ();
20921 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
20923 else if (attr
->form
== DW_FORM_ref_sig8
)
20925 ULONGEST signature
= DW_SIGNATURE (attr
);
20927 return get_signatured_type (die
, signature
, cu
);
20931 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
20932 " at %s [in module %s]"),
20933 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
20934 objfile_name (objfile
));
20935 return build_error_marker_type (cu
, die
);
20938 /* If not cached we need to read it in. */
20940 if (this_type
== NULL
)
20942 struct die_info
*type_die
= NULL
;
20943 struct dwarf2_cu
*type_cu
= cu
;
20945 if (attr
->form_is_ref ())
20946 type_die
= follow_die_ref (die
, attr
, &type_cu
);
20947 if (type_die
== NULL
)
20948 return build_error_marker_type (cu
, die
);
20949 /* If we find the type now, it's probably because the type came
20950 from an inter-CU reference and the type's CU got expanded before
20952 this_type
= read_type_die (type_die
, type_cu
);
20955 /* If we still don't have a type use an error marker. */
20957 if (this_type
== NULL
)
20958 return build_error_marker_type (cu
, die
);
20963 /* Return the type in DIE, CU.
20964 Returns NULL for invalid types.
20966 This first does a lookup in die_type_hash,
20967 and only reads the die in if necessary.
20969 NOTE: This can be called when reading in partial or full symbols. */
20971 static struct type
*
20972 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
20974 struct type
*this_type
;
20976 this_type
= get_die_type (die
, cu
);
20980 return read_type_die_1 (die
, cu
);
20983 /* Read the type in DIE, CU.
20984 Returns NULL for invalid types. */
20986 static struct type
*
20987 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
20989 struct type
*this_type
= NULL
;
20993 case DW_TAG_class_type
:
20994 case DW_TAG_interface_type
:
20995 case DW_TAG_structure_type
:
20996 case DW_TAG_union_type
:
20997 this_type
= read_structure_type (die
, cu
);
20999 case DW_TAG_enumeration_type
:
21000 this_type
= read_enumeration_type (die
, cu
);
21002 case DW_TAG_subprogram
:
21003 case DW_TAG_subroutine_type
:
21004 case DW_TAG_inlined_subroutine
:
21005 this_type
= read_subroutine_type (die
, cu
);
21007 case DW_TAG_array_type
:
21008 this_type
= read_array_type (die
, cu
);
21010 case DW_TAG_set_type
:
21011 this_type
= read_set_type (die
, cu
);
21013 case DW_TAG_pointer_type
:
21014 this_type
= read_tag_pointer_type (die
, cu
);
21016 case DW_TAG_ptr_to_member_type
:
21017 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21019 case DW_TAG_reference_type
:
21020 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21022 case DW_TAG_rvalue_reference_type
:
21023 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21025 case DW_TAG_const_type
:
21026 this_type
= read_tag_const_type (die
, cu
);
21028 case DW_TAG_volatile_type
:
21029 this_type
= read_tag_volatile_type (die
, cu
);
21031 case DW_TAG_restrict_type
:
21032 this_type
= read_tag_restrict_type (die
, cu
);
21034 case DW_TAG_string_type
:
21035 this_type
= read_tag_string_type (die
, cu
);
21037 case DW_TAG_typedef
:
21038 this_type
= read_typedef (die
, cu
);
21040 case DW_TAG_subrange_type
:
21041 this_type
= read_subrange_type (die
, cu
);
21043 case DW_TAG_base_type
:
21044 this_type
= read_base_type (die
, cu
);
21046 case DW_TAG_unspecified_type
:
21047 this_type
= read_unspecified_type (die
, cu
);
21049 case DW_TAG_namespace
:
21050 this_type
= read_namespace_type (die
, cu
);
21052 case DW_TAG_module
:
21053 this_type
= read_module_type (die
, cu
);
21055 case DW_TAG_atomic_type
:
21056 this_type
= read_tag_atomic_type (die
, cu
);
21059 complaint (_("unexpected tag in read_type_die: '%s'"),
21060 dwarf_tag_name (die
->tag
));
21067 /* See if we can figure out if the class lives in a namespace. We do
21068 this by looking for a member function; its demangled name will
21069 contain namespace info, if there is any.
21070 Return the computed name or NULL.
21071 Space for the result is allocated on the objfile's obstack.
21072 This is the full-die version of guess_partial_die_structure_name.
21073 In this case we know DIE has no useful parent. */
21075 static const char *
21076 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21078 struct die_info
*spec_die
;
21079 struct dwarf2_cu
*spec_cu
;
21080 struct die_info
*child
;
21081 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21084 spec_die
= die_specification (die
, &spec_cu
);
21085 if (spec_die
!= NULL
)
21091 for (child
= die
->child
;
21093 child
= child
->sibling
)
21095 if (child
->tag
== DW_TAG_subprogram
)
21097 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21099 if (linkage_name
!= NULL
)
21101 gdb::unique_xmalloc_ptr
<char> actual_name
21102 (language_class_name_from_physname (cu
->language_defn
,
21104 const char *name
= NULL
;
21106 if (actual_name
!= NULL
)
21108 const char *die_name
= dwarf2_name (die
, cu
);
21110 if (die_name
!= NULL
21111 && strcmp (die_name
, actual_name
.get ()) != 0)
21113 /* Strip off the class name from the full name.
21114 We want the prefix. */
21115 int die_name_len
= strlen (die_name
);
21116 int actual_name_len
= strlen (actual_name
.get ());
21117 const char *ptr
= actual_name
.get ();
21119 /* Test for '::' as a sanity check. */
21120 if (actual_name_len
> die_name_len
+ 2
21121 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21122 name
= obstack_strndup (
21123 &objfile
->per_bfd
->storage_obstack
,
21124 ptr
, actual_name_len
- die_name_len
- 2);
21135 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21136 prefix part in such case. See
21137 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21139 static const char *
21140 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21142 struct attribute
*attr
;
21145 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21146 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21149 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21152 attr
= dw2_linkage_name_attr (die
, cu
);
21153 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21156 /* dwarf2_name had to be already called. */
21157 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21159 /* Strip the base name, keep any leading namespaces/classes. */
21160 base
= strrchr (DW_STRING (attr
), ':');
21161 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21164 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21165 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21167 &base
[-1] - DW_STRING (attr
));
21170 /* Return the name of the namespace/class that DIE is defined within,
21171 or "" if we can't tell. The caller should not xfree the result.
21173 For example, if we're within the method foo() in the following
21183 then determine_prefix on foo's die will return "N::C". */
21185 static const char *
21186 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21188 struct dwarf2_per_objfile
*dwarf2_per_objfile
21189 = cu
->per_cu
->dwarf2_per_objfile
;
21190 struct die_info
*parent
, *spec_die
;
21191 struct dwarf2_cu
*spec_cu
;
21192 struct type
*parent_type
;
21193 const char *retval
;
21195 if (cu
->language
!= language_cplus
21196 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21197 && cu
->language
!= language_rust
)
21200 retval
= anonymous_struct_prefix (die
, cu
);
21204 /* We have to be careful in the presence of DW_AT_specification.
21205 For example, with GCC 3.4, given the code
21209 // Definition of N::foo.
21213 then we'll have a tree of DIEs like this:
21215 1: DW_TAG_compile_unit
21216 2: DW_TAG_namespace // N
21217 3: DW_TAG_subprogram // declaration of N::foo
21218 4: DW_TAG_subprogram // definition of N::foo
21219 DW_AT_specification // refers to die #3
21221 Thus, when processing die #4, we have to pretend that we're in
21222 the context of its DW_AT_specification, namely the contex of die
21225 spec_die
= die_specification (die
, &spec_cu
);
21226 if (spec_die
== NULL
)
21227 parent
= die
->parent
;
21230 parent
= spec_die
->parent
;
21234 if (parent
== NULL
)
21236 else if (parent
->building_fullname
)
21239 const char *parent_name
;
21241 /* It has been seen on RealView 2.2 built binaries,
21242 DW_TAG_template_type_param types actually _defined_ as
21243 children of the parent class:
21246 template class <class Enum> Class{};
21247 Class<enum E> class_e;
21249 1: DW_TAG_class_type (Class)
21250 2: DW_TAG_enumeration_type (E)
21251 3: DW_TAG_enumerator (enum1:0)
21252 3: DW_TAG_enumerator (enum2:1)
21254 2: DW_TAG_template_type_param
21255 DW_AT_type DW_FORM_ref_udata (E)
21257 Besides being broken debug info, it can put GDB into an
21258 infinite loop. Consider:
21260 When we're building the full name for Class<E>, we'll start
21261 at Class, and go look over its template type parameters,
21262 finding E. We'll then try to build the full name of E, and
21263 reach here. We're now trying to build the full name of E,
21264 and look over the parent DIE for containing scope. In the
21265 broken case, if we followed the parent DIE of E, we'd again
21266 find Class, and once again go look at its template type
21267 arguments, etc., etc. Simply don't consider such parent die
21268 as source-level parent of this die (it can't be, the language
21269 doesn't allow it), and break the loop here. */
21270 name
= dwarf2_name (die
, cu
);
21271 parent_name
= dwarf2_name (parent
, cu
);
21272 complaint (_("template param type '%s' defined within parent '%s'"),
21273 name
? name
: "<unknown>",
21274 parent_name
? parent_name
: "<unknown>");
21278 switch (parent
->tag
)
21280 case DW_TAG_namespace
:
21281 parent_type
= read_type_die (parent
, cu
);
21282 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21283 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21284 Work around this problem here. */
21285 if (cu
->language
== language_cplus
21286 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21288 /* We give a name to even anonymous namespaces. */
21289 return TYPE_NAME (parent_type
);
21290 case DW_TAG_class_type
:
21291 case DW_TAG_interface_type
:
21292 case DW_TAG_structure_type
:
21293 case DW_TAG_union_type
:
21294 case DW_TAG_module
:
21295 parent_type
= read_type_die (parent
, cu
);
21296 if (TYPE_NAME (parent_type
) != NULL
)
21297 return TYPE_NAME (parent_type
);
21299 /* An anonymous structure is only allowed non-static data
21300 members; no typedefs, no member functions, et cetera.
21301 So it does not need a prefix. */
21303 case DW_TAG_compile_unit
:
21304 case DW_TAG_partial_unit
:
21305 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21306 if (cu
->language
== language_cplus
21307 && !dwarf2_per_objfile
->types
.empty ()
21308 && die
->child
!= NULL
21309 && (die
->tag
== DW_TAG_class_type
21310 || die
->tag
== DW_TAG_structure_type
21311 || die
->tag
== DW_TAG_union_type
))
21313 const char *name
= guess_full_die_structure_name (die
, cu
);
21318 case DW_TAG_subprogram
:
21319 /* Nested subroutines in Fortran get a prefix with the name
21320 of the parent's subroutine. */
21321 if (cu
->language
== language_fortran
)
21323 if ((die
->tag
== DW_TAG_subprogram
)
21324 && (dwarf2_name (parent
, cu
) != NULL
))
21325 return dwarf2_name (parent
, cu
);
21327 return determine_prefix (parent
, cu
);
21328 case DW_TAG_enumeration_type
:
21329 parent_type
= read_type_die (parent
, cu
);
21330 if (TYPE_DECLARED_CLASS (parent_type
))
21332 if (TYPE_NAME (parent_type
) != NULL
)
21333 return TYPE_NAME (parent_type
);
21336 /* Fall through. */
21338 return determine_prefix (parent
, cu
);
21342 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21343 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21344 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21345 an obconcat, otherwise allocate storage for the result. The CU argument is
21346 used to determine the language and hence, the appropriate separator. */
21348 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21351 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21352 int physname
, struct dwarf2_cu
*cu
)
21354 const char *lead
= "";
21357 if (suffix
== NULL
|| suffix
[0] == '\0'
21358 || prefix
== NULL
|| prefix
[0] == '\0')
21360 else if (cu
->language
== language_d
)
21362 /* For D, the 'main' function could be defined in any module, but it
21363 should never be prefixed. */
21364 if (strcmp (suffix
, "D main") == 0)
21372 else if (cu
->language
== language_fortran
&& physname
)
21374 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21375 DW_AT_MIPS_linkage_name is preferred and used instead. */
21383 if (prefix
== NULL
)
21385 if (suffix
== NULL
)
21392 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21394 strcpy (retval
, lead
);
21395 strcat (retval
, prefix
);
21396 strcat (retval
, sep
);
21397 strcat (retval
, suffix
);
21402 /* We have an obstack. */
21403 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21407 /* Get name of a die, return NULL if not found. */
21409 static const char *
21410 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21411 struct objfile
*objfile
)
21413 if (name
&& cu
->language
== language_cplus
)
21415 std::string canon_name
= cp_canonicalize_string (name
);
21417 if (!canon_name
.empty ())
21419 if (canon_name
!= name
)
21420 name
= objfile
->intern (canon_name
);
21427 /* Get name of a die, return NULL if not found.
21428 Anonymous namespaces are converted to their magic string. */
21430 static const char *
21431 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21433 struct attribute
*attr
;
21434 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21436 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21437 if ((!attr
|| !DW_STRING (attr
))
21438 && die
->tag
!= DW_TAG_namespace
21439 && die
->tag
!= DW_TAG_class_type
21440 && die
->tag
!= DW_TAG_interface_type
21441 && die
->tag
!= DW_TAG_structure_type
21442 && die
->tag
!= DW_TAG_union_type
)
21447 case DW_TAG_compile_unit
:
21448 case DW_TAG_partial_unit
:
21449 /* Compilation units have a DW_AT_name that is a filename, not
21450 a source language identifier. */
21451 case DW_TAG_enumeration_type
:
21452 case DW_TAG_enumerator
:
21453 /* These tags always have simple identifiers already; no need
21454 to canonicalize them. */
21455 return DW_STRING (attr
);
21457 case DW_TAG_namespace
:
21458 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21459 return DW_STRING (attr
);
21460 return CP_ANONYMOUS_NAMESPACE_STR
;
21462 case DW_TAG_class_type
:
21463 case DW_TAG_interface_type
:
21464 case DW_TAG_structure_type
:
21465 case DW_TAG_union_type
:
21466 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21467 structures or unions. These were of the form "._%d" in GCC 4.1,
21468 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21469 and GCC 4.4. We work around this problem by ignoring these. */
21470 if (attr
&& DW_STRING (attr
)
21471 && (startswith (DW_STRING (attr
), "._")
21472 || startswith (DW_STRING (attr
), "<anonymous")))
21475 /* GCC might emit a nameless typedef that has a linkage name. See
21476 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21477 if (!attr
|| DW_STRING (attr
) == NULL
)
21479 attr
= dw2_linkage_name_attr (die
, cu
);
21480 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21483 /* Avoid demangling DW_STRING (attr) the second time on a second
21484 call for the same DIE. */
21485 if (!DW_STRING_IS_CANONICAL (attr
))
21487 gdb::unique_xmalloc_ptr
<char> demangled
21488 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21489 if (demangled
== nullptr)
21492 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21493 DW_STRING_IS_CANONICAL (attr
) = 1;
21496 /* Strip any leading namespaces/classes, keep only the base name.
21497 DW_AT_name for named DIEs does not contain the prefixes. */
21498 const char *base
= strrchr (DW_STRING (attr
), ':');
21499 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21502 return DW_STRING (attr
);
21510 if (!DW_STRING_IS_CANONICAL (attr
))
21512 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21514 DW_STRING_IS_CANONICAL (attr
) = 1;
21516 return DW_STRING (attr
);
21519 /* Return the die that this die in an extension of, or NULL if there
21520 is none. *EXT_CU is the CU containing DIE on input, and the CU
21521 containing the return value on output. */
21523 static struct die_info
*
21524 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21526 struct attribute
*attr
;
21528 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21532 return follow_die_ref (die
, attr
, ext_cu
);
21536 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21540 print_spaces (indent
, f
);
21541 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21542 dwarf_tag_name (die
->tag
), die
->abbrev
,
21543 sect_offset_str (die
->sect_off
));
21545 if (die
->parent
!= NULL
)
21547 print_spaces (indent
, f
);
21548 fprintf_unfiltered (f
, " parent at offset: %s\n",
21549 sect_offset_str (die
->parent
->sect_off
));
21552 print_spaces (indent
, f
);
21553 fprintf_unfiltered (f
, " has children: %s\n",
21554 dwarf_bool_name (die
->child
!= NULL
));
21556 print_spaces (indent
, f
);
21557 fprintf_unfiltered (f
, " attributes:\n");
21559 for (i
= 0; i
< die
->num_attrs
; ++i
)
21561 print_spaces (indent
, f
);
21562 fprintf_unfiltered (f
, " %s (%s) ",
21563 dwarf_attr_name (die
->attrs
[i
].name
),
21564 dwarf_form_name (die
->attrs
[i
].form
));
21566 switch (die
->attrs
[i
].form
)
21569 case DW_FORM_addrx
:
21570 case DW_FORM_GNU_addr_index
:
21571 fprintf_unfiltered (f
, "address: ");
21572 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21574 case DW_FORM_block2
:
21575 case DW_FORM_block4
:
21576 case DW_FORM_block
:
21577 case DW_FORM_block1
:
21578 fprintf_unfiltered (f
, "block: size %s",
21579 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21581 case DW_FORM_exprloc
:
21582 fprintf_unfiltered (f
, "expression: size %s",
21583 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21585 case DW_FORM_data16
:
21586 fprintf_unfiltered (f
, "constant of 16 bytes");
21588 case DW_FORM_ref_addr
:
21589 fprintf_unfiltered (f
, "ref address: ");
21590 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21592 case DW_FORM_GNU_ref_alt
:
21593 fprintf_unfiltered (f
, "alt ref address: ");
21594 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21600 case DW_FORM_ref_udata
:
21601 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21602 (long) (DW_UNSND (&die
->attrs
[i
])));
21604 case DW_FORM_data1
:
21605 case DW_FORM_data2
:
21606 case DW_FORM_data4
:
21607 case DW_FORM_data8
:
21608 case DW_FORM_udata
:
21609 case DW_FORM_sdata
:
21610 fprintf_unfiltered (f
, "constant: %s",
21611 pulongest (DW_UNSND (&die
->attrs
[i
])));
21613 case DW_FORM_sec_offset
:
21614 fprintf_unfiltered (f
, "section offset: %s",
21615 pulongest (DW_UNSND (&die
->attrs
[i
])));
21617 case DW_FORM_ref_sig8
:
21618 fprintf_unfiltered (f
, "signature: %s",
21619 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21621 case DW_FORM_string
:
21623 case DW_FORM_line_strp
:
21625 case DW_FORM_GNU_str_index
:
21626 case DW_FORM_GNU_strp_alt
:
21627 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21628 DW_STRING (&die
->attrs
[i
])
21629 ? DW_STRING (&die
->attrs
[i
]) : "",
21630 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21633 if (DW_UNSND (&die
->attrs
[i
]))
21634 fprintf_unfiltered (f
, "flag: TRUE");
21636 fprintf_unfiltered (f
, "flag: FALSE");
21638 case DW_FORM_flag_present
:
21639 fprintf_unfiltered (f
, "flag: TRUE");
21641 case DW_FORM_indirect
:
21642 /* The reader will have reduced the indirect form to
21643 the "base form" so this form should not occur. */
21644 fprintf_unfiltered (f
,
21645 "unexpected attribute form: DW_FORM_indirect");
21647 case DW_FORM_implicit_const
:
21648 fprintf_unfiltered (f
, "constant: %s",
21649 plongest (DW_SND (&die
->attrs
[i
])));
21652 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
21653 die
->attrs
[i
].form
);
21656 fprintf_unfiltered (f
, "\n");
21661 dump_die_for_error (struct die_info
*die
)
21663 dump_die_shallow (gdb_stderr
, 0, die
);
21667 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
21669 int indent
= level
* 4;
21671 gdb_assert (die
!= NULL
);
21673 if (level
>= max_level
)
21676 dump_die_shallow (f
, indent
, die
);
21678 if (die
->child
!= NULL
)
21680 print_spaces (indent
, f
);
21681 fprintf_unfiltered (f
, " Children:");
21682 if (level
+ 1 < max_level
)
21684 fprintf_unfiltered (f
, "\n");
21685 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
21689 fprintf_unfiltered (f
,
21690 " [not printed, max nesting level reached]\n");
21694 if (die
->sibling
!= NULL
&& level
> 0)
21696 dump_die_1 (f
, level
, max_level
, die
->sibling
);
21700 /* This is called from the pdie macro in gdbinit.in.
21701 It's not static so gcc will keep a copy callable from gdb. */
21704 dump_die (struct die_info
*die
, int max_level
)
21706 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
21710 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
21714 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
21715 to_underlying (die
->sect_off
),
21721 /* Follow reference or signature attribute ATTR of SRC_DIE.
21722 On entry *REF_CU is the CU of SRC_DIE.
21723 On exit *REF_CU is the CU of the result. */
21725 static struct die_info
*
21726 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21727 struct dwarf2_cu
**ref_cu
)
21729 struct die_info
*die
;
21731 if (attr
->form_is_ref ())
21732 die
= follow_die_ref (src_die
, attr
, ref_cu
);
21733 else if (attr
->form
== DW_FORM_ref_sig8
)
21734 die
= follow_die_sig (src_die
, attr
, ref_cu
);
21737 dump_die_for_error (src_die
);
21738 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
21739 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
21745 /* Follow reference OFFSET.
21746 On entry *REF_CU is the CU of the source die referencing OFFSET.
21747 On exit *REF_CU is the CU of the result.
21748 Returns NULL if OFFSET is invalid. */
21750 static struct die_info
*
21751 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
21752 struct dwarf2_cu
**ref_cu
)
21754 struct die_info temp_die
;
21755 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
21756 struct dwarf2_per_objfile
*dwarf2_per_objfile
21757 = cu
->per_cu
->dwarf2_per_objfile
;
21759 gdb_assert (cu
->per_cu
!= NULL
);
21763 if (cu
->per_cu
->is_debug_types
)
21765 /* .debug_types CUs cannot reference anything outside their CU.
21766 If they need to, they have to reference a signatured type via
21767 DW_FORM_ref_sig8. */
21768 if (!cu
->header
.offset_in_cu_p (sect_off
))
21771 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
21772 || !cu
->header
.offset_in_cu_p (sect_off
))
21774 struct dwarf2_per_cu_data
*per_cu
;
21776 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
21777 dwarf2_per_objfile
);
21779 /* If necessary, add it to the queue and load its DIEs. */
21780 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
21781 load_full_comp_unit (per_cu
, false, cu
->language
);
21783 target_cu
= per_cu
->cu
;
21785 else if (cu
->dies
== NULL
)
21787 /* We're loading full DIEs during partial symbol reading. */
21788 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
21789 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
21792 *ref_cu
= target_cu
;
21793 temp_die
.sect_off
= sect_off
;
21795 if (target_cu
!= cu
)
21796 target_cu
->ancestor
= cu
;
21798 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
21800 to_underlying (sect_off
));
21803 /* Follow reference attribute ATTR of SRC_DIE.
21804 On entry *REF_CU is the CU of SRC_DIE.
21805 On exit *REF_CU is the CU of the result. */
21807 static struct die_info
*
21808 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
21809 struct dwarf2_cu
**ref_cu
)
21811 sect_offset sect_off
= attr
->get_ref_die_offset ();
21812 struct dwarf2_cu
*cu
= *ref_cu
;
21813 struct die_info
*die
;
21815 die
= follow_die_offset (sect_off
,
21816 (attr
->form
== DW_FORM_GNU_ref_alt
21817 || cu
->per_cu
->is_dwz
),
21820 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
21821 "at %s [in module %s]"),
21822 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
21823 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
21830 struct dwarf2_locexpr_baton
21831 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
21832 dwarf2_per_cu_data
*per_cu
,
21833 CORE_ADDR (*get_frame_pc
) (void *baton
),
21834 void *baton
, bool resolve_abstract_p
)
21836 struct dwarf2_cu
*cu
;
21837 struct die_info
*die
;
21838 struct attribute
*attr
;
21839 struct dwarf2_locexpr_baton retval
;
21840 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
21841 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21843 if (per_cu
->cu
== NULL
)
21844 load_cu (per_cu
, false);
21848 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21849 Instead just throw an error, not much else we can do. */
21850 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21851 sect_offset_str (sect_off
), objfile_name (objfile
));
21854 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21856 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21857 sect_offset_str (sect_off
), objfile_name (objfile
));
21859 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21860 if (!attr
&& resolve_abstract_p
21861 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
21862 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
21864 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21865 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
21866 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21868 for (const auto &cand_off
21869 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
21871 struct dwarf2_cu
*cand_cu
= cu
;
21872 struct die_info
*cand
21873 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
21876 || cand
->parent
->tag
!= DW_TAG_subprogram
)
21879 CORE_ADDR pc_low
, pc_high
;
21880 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
21881 if (pc_low
== ((CORE_ADDR
) -1))
21883 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
21884 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
21885 if (!(pc_low
<= pc
&& pc
< pc_high
))
21889 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21896 /* DWARF: "If there is no such attribute, then there is no effect.".
21897 DATA is ignored if SIZE is 0. */
21899 retval
.data
= NULL
;
21902 else if (attr
->form_is_section_offset ())
21904 struct dwarf2_loclist_baton loclist_baton
;
21905 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21908 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
21910 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
21912 retval
.size
= size
;
21916 if (!attr
->form_is_block ())
21917 error (_("Dwarf Error: DIE at %s referenced in module %s "
21918 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
21919 sect_offset_str (sect_off
), objfile_name (objfile
));
21921 retval
.data
= DW_BLOCK (attr
)->data
;
21922 retval
.size
= DW_BLOCK (attr
)->size
;
21924 retval
.per_cu
= cu
->per_cu
;
21926 age_cached_comp_units (dwarf2_per_objfile
);
21933 struct dwarf2_locexpr_baton
21934 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
21935 dwarf2_per_cu_data
*per_cu
,
21936 CORE_ADDR (*get_frame_pc
) (void *baton
),
21939 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
21941 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
21944 /* Write a constant of a given type as target-ordered bytes into
21947 static const gdb_byte
*
21948 write_constant_as_bytes (struct obstack
*obstack
,
21949 enum bfd_endian byte_order
,
21956 *len
= TYPE_LENGTH (type
);
21957 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21958 store_unsigned_integer (result
, *len
, byte_order
, value
);
21966 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
21967 dwarf2_per_cu_data
*per_cu
,
21971 struct dwarf2_cu
*cu
;
21972 struct die_info
*die
;
21973 struct attribute
*attr
;
21974 const gdb_byte
*result
= NULL
;
21977 enum bfd_endian byte_order
;
21978 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
21980 if (per_cu
->cu
== NULL
)
21981 load_cu (per_cu
, false);
21985 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21986 Instead just throw an error, not much else we can do. */
21987 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21988 sect_offset_str (sect_off
), objfile_name (objfile
));
21991 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21993 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21994 sect_offset_str (sect_off
), objfile_name (objfile
));
21996 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22000 byte_order
= (bfd_big_endian (objfile
->obfd
)
22001 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22003 switch (attr
->form
)
22006 case DW_FORM_addrx
:
22007 case DW_FORM_GNU_addr_index
:
22011 *len
= cu
->header
.addr_size
;
22012 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22013 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22017 case DW_FORM_string
:
22020 case DW_FORM_GNU_str_index
:
22021 case DW_FORM_GNU_strp_alt
:
22022 /* DW_STRING is already allocated on the objfile obstack, point
22024 result
= (const gdb_byte
*) DW_STRING (attr
);
22025 *len
= strlen (DW_STRING (attr
));
22027 case DW_FORM_block1
:
22028 case DW_FORM_block2
:
22029 case DW_FORM_block4
:
22030 case DW_FORM_block
:
22031 case DW_FORM_exprloc
:
22032 case DW_FORM_data16
:
22033 result
= DW_BLOCK (attr
)->data
;
22034 *len
= DW_BLOCK (attr
)->size
;
22037 /* The DW_AT_const_value attributes are supposed to carry the
22038 symbol's value "represented as it would be on the target
22039 architecture." By the time we get here, it's already been
22040 converted to host endianness, so we just need to sign- or
22041 zero-extend it as appropriate. */
22042 case DW_FORM_data1
:
22043 type
= die_type (die
, cu
);
22044 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22045 if (result
== NULL
)
22046 result
= write_constant_as_bytes (obstack
, byte_order
,
22049 case DW_FORM_data2
:
22050 type
= die_type (die
, cu
);
22051 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22052 if (result
== NULL
)
22053 result
= write_constant_as_bytes (obstack
, byte_order
,
22056 case DW_FORM_data4
:
22057 type
= die_type (die
, cu
);
22058 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22059 if (result
== NULL
)
22060 result
= write_constant_as_bytes (obstack
, byte_order
,
22063 case DW_FORM_data8
:
22064 type
= die_type (die
, cu
);
22065 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22066 if (result
== NULL
)
22067 result
= write_constant_as_bytes (obstack
, byte_order
,
22071 case DW_FORM_sdata
:
22072 case DW_FORM_implicit_const
:
22073 type
= die_type (die
, cu
);
22074 result
= write_constant_as_bytes (obstack
, byte_order
,
22075 type
, DW_SND (attr
), len
);
22078 case DW_FORM_udata
:
22079 type
= die_type (die
, cu
);
22080 result
= write_constant_as_bytes (obstack
, byte_order
,
22081 type
, DW_UNSND (attr
), len
);
22085 complaint (_("unsupported const value attribute form: '%s'"),
22086 dwarf_form_name (attr
->form
));
22096 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22097 dwarf2_per_cu_data
*per_cu
)
22099 struct dwarf2_cu
*cu
;
22100 struct die_info
*die
;
22102 if (per_cu
->cu
== NULL
)
22103 load_cu (per_cu
, false);
22108 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22112 return die_type (die
, cu
);
22118 dwarf2_get_die_type (cu_offset die_offset
,
22119 struct dwarf2_per_cu_data
*per_cu
)
22121 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22122 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22125 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22126 On entry *REF_CU is the CU of SRC_DIE.
22127 On exit *REF_CU is the CU of the result.
22128 Returns NULL if the referenced DIE isn't found. */
22130 static struct die_info
*
22131 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22132 struct dwarf2_cu
**ref_cu
)
22134 struct die_info temp_die
;
22135 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22136 struct die_info
*die
;
22138 /* While it might be nice to assert sig_type->type == NULL here,
22139 we can get here for DW_AT_imported_declaration where we need
22140 the DIE not the type. */
22142 /* If necessary, add it to the queue and load its DIEs. */
22144 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22145 read_signatured_type (sig_type
);
22147 sig_cu
= sig_type
->per_cu
.cu
;
22148 gdb_assert (sig_cu
!= NULL
);
22149 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22150 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22151 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22152 to_underlying (temp_die
.sect_off
));
22155 struct dwarf2_per_objfile
*dwarf2_per_objfile
22156 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22158 /* For .gdb_index version 7 keep track of included TUs.
22159 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22160 if (dwarf2_per_objfile
->index_table
!= NULL
22161 && dwarf2_per_objfile
->index_table
->version
<= 7)
22163 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22168 sig_cu
->ancestor
= cu
;
22176 /* Follow signatured type referenced by ATTR in SRC_DIE.
22177 On entry *REF_CU is the CU of SRC_DIE.
22178 On exit *REF_CU is the CU of the result.
22179 The result is the DIE of the type.
22180 If the referenced type cannot be found an error is thrown. */
22182 static struct die_info
*
22183 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22184 struct dwarf2_cu
**ref_cu
)
22186 ULONGEST signature
= DW_SIGNATURE (attr
);
22187 struct signatured_type
*sig_type
;
22188 struct die_info
*die
;
22190 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22192 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22193 /* sig_type will be NULL if the signatured type is missing from
22195 if (sig_type
== NULL
)
22197 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22198 " from DIE at %s [in module %s]"),
22199 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22200 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22203 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22206 dump_die_for_error (src_die
);
22207 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22208 " from DIE at %s [in module %s]"),
22209 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22210 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22216 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22217 reading in and processing the type unit if necessary. */
22219 static struct type
*
22220 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22221 struct dwarf2_cu
*cu
)
22223 struct dwarf2_per_objfile
*dwarf2_per_objfile
22224 = cu
->per_cu
->dwarf2_per_objfile
;
22225 struct signatured_type
*sig_type
;
22226 struct dwarf2_cu
*type_cu
;
22227 struct die_info
*type_die
;
22230 sig_type
= lookup_signatured_type (cu
, signature
);
22231 /* sig_type will be NULL if the signatured type is missing from
22233 if (sig_type
== NULL
)
22235 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22236 " from DIE at %s [in module %s]"),
22237 hex_string (signature
), sect_offset_str (die
->sect_off
),
22238 objfile_name (dwarf2_per_objfile
->objfile
));
22239 return build_error_marker_type (cu
, die
);
22242 /* If we already know the type we're done. */
22243 if (sig_type
->type
!= NULL
)
22244 return sig_type
->type
;
22247 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22248 if (type_die
!= NULL
)
22250 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22251 is created. This is important, for example, because for c++ classes
22252 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22253 type
= read_type_die (type_die
, type_cu
);
22256 complaint (_("Dwarf Error: Cannot build signatured type %s"
22257 " referenced from DIE at %s [in module %s]"),
22258 hex_string (signature
), sect_offset_str (die
->sect_off
),
22259 objfile_name (dwarf2_per_objfile
->objfile
));
22260 type
= build_error_marker_type (cu
, die
);
22265 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22266 " from DIE at %s [in module %s]"),
22267 hex_string (signature
), sect_offset_str (die
->sect_off
),
22268 objfile_name (dwarf2_per_objfile
->objfile
));
22269 type
= build_error_marker_type (cu
, die
);
22271 sig_type
->type
= type
;
22276 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22277 reading in and processing the type unit if necessary. */
22279 static struct type
*
22280 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22281 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22283 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22284 if (attr
->form_is_ref ())
22286 struct dwarf2_cu
*type_cu
= cu
;
22287 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22289 return read_type_die (type_die
, type_cu
);
22291 else if (attr
->form
== DW_FORM_ref_sig8
)
22293 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22297 struct dwarf2_per_objfile
*dwarf2_per_objfile
22298 = cu
->per_cu
->dwarf2_per_objfile
;
22300 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22301 " at %s [in module %s]"),
22302 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22303 objfile_name (dwarf2_per_objfile
->objfile
));
22304 return build_error_marker_type (cu
, die
);
22308 /* Load the DIEs associated with type unit PER_CU into memory. */
22311 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22313 struct signatured_type
*sig_type
;
22315 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22316 gdb_assert (! per_cu
->type_unit_group_p ());
22318 /* We have the per_cu, but we need the signatured_type.
22319 Fortunately this is an easy translation. */
22320 gdb_assert (per_cu
->is_debug_types
);
22321 sig_type
= (struct signatured_type
*) per_cu
;
22323 gdb_assert (per_cu
->cu
== NULL
);
22325 read_signatured_type (sig_type
);
22327 gdb_assert (per_cu
->cu
!= NULL
);
22330 /* Read in a signatured type and build its CU and DIEs.
22331 If the type is a stub for the real type in a DWO file,
22332 read in the real type from the DWO file as well. */
22335 read_signatured_type (struct signatured_type
*sig_type
)
22337 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22339 gdb_assert (per_cu
->is_debug_types
);
22340 gdb_assert (per_cu
->cu
== NULL
);
22342 cutu_reader
reader (per_cu
, NULL
, 0, false);
22344 if (!reader
.dummy_p
)
22346 struct dwarf2_cu
*cu
= reader
.cu
;
22347 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22349 gdb_assert (cu
->die_hash
== NULL
);
22351 htab_create_alloc_ex (cu
->header
.length
/ 12,
22355 &cu
->comp_unit_obstack
,
22356 hashtab_obstack_allocate
,
22357 dummy_obstack_deallocate
);
22359 if (reader
.comp_unit_die
->has_children
)
22360 reader
.comp_unit_die
->child
22361 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22362 reader
.comp_unit_die
);
22363 cu
->dies
= reader
.comp_unit_die
;
22364 /* comp_unit_die is not stored in die_hash, no need. */
22366 /* We try not to read any attributes in this function, because
22367 not all CUs needed for references have been loaded yet, and
22368 symbol table processing isn't initialized. But we have to
22369 set the CU language, or we won't be able to build types
22370 correctly. Similarly, if we do not read the producer, we can
22371 not apply producer-specific interpretation. */
22372 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22377 sig_type
->per_cu
.tu_read
= 1;
22380 /* Decode simple location descriptions.
22381 Given a pointer to a dwarf block that defines a location, compute
22382 the location and return the value.
22384 NOTE drow/2003-11-18: This function is called in two situations
22385 now: for the address of static or global variables (partial symbols
22386 only) and for offsets into structures which are expected to be
22387 (more or less) constant. The partial symbol case should go away,
22388 and only the constant case should remain. That will let this
22389 function complain more accurately. A few special modes are allowed
22390 without complaint for global variables (for instance, global
22391 register values and thread-local values).
22393 A location description containing no operations indicates that the
22394 object is optimized out. The return value is 0 for that case.
22395 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22396 callers will only want a very basic result and this can become a
22399 Note that stack[0] is unused except as a default error return. */
22402 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22404 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22406 size_t size
= blk
->size
;
22407 const gdb_byte
*data
= blk
->data
;
22408 CORE_ADDR stack
[64];
22410 unsigned int bytes_read
, unsnd
;
22416 stack
[++stacki
] = 0;
22455 stack
[++stacki
] = op
- DW_OP_lit0
;
22490 stack
[++stacki
] = op
- DW_OP_reg0
;
22492 dwarf2_complex_location_expr_complaint ();
22496 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22498 stack
[++stacki
] = unsnd
;
22500 dwarf2_complex_location_expr_complaint ();
22504 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22509 case DW_OP_const1u
:
22510 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22514 case DW_OP_const1s
:
22515 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22519 case DW_OP_const2u
:
22520 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22524 case DW_OP_const2s
:
22525 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22529 case DW_OP_const4u
:
22530 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22534 case DW_OP_const4s
:
22535 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22539 case DW_OP_const8u
:
22540 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22545 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22551 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22556 stack
[stacki
+ 1] = stack
[stacki
];
22561 stack
[stacki
- 1] += stack
[stacki
];
22565 case DW_OP_plus_uconst
:
22566 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22572 stack
[stacki
- 1] -= stack
[stacki
];
22577 /* If we're not the last op, then we definitely can't encode
22578 this using GDB's address_class enum. This is valid for partial
22579 global symbols, although the variable's address will be bogus
22582 dwarf2_complex_location_expr_complaint ();
22585 case DW_OP_GNU_push_tls_address
:
22586 case DW_OP_form_tls_address
:
22587 /* The top of the stack has the offset from the beginning
22588 of the thread control block at which the variable is located. */
22589 /* Nothing should follow this operator, so the top of stack would
22591 /* This is valid for partial global symbols, but the variable's
22592 address will be bogus in the psymtab. Make it always at least
22593 non-zero to not look as a variable garbage collected by linker
22594 which have DW_OP_addr 0. */
22596 dwarf2_complex_location_expr_complaint ();
22600 case DW_OP_GNU_uninit
:
22604 case DW_OP_GNU_addr_index
:
22605 case DW_OP_GNU_const_index
:
22606 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
22613 const char *name
= get_DW_OP_name (op
);
22616 complaint (_("unsupported stack op: '%s'"),
22619 complaint (_("unsupported stack op: '%02x'"),
22623 return (stack
[stacki
]);
22626 /* Enforce maximum stack depth of SIZE-1 to avoid writing
22627 outside of the allocated space. Also enforce minimum>0. */
22628 if (stacki
>= ARRAY_SIZE (stack
) - 1)
22630 complaint (_("location description stack overflow"));
22636 complaint (_("location description stack underflow"));
22640 return (stack
[stacki
]);
22643 /* memory allocation interface */
22645 static struct dwarf_block
*
22646 dwarf_alloc_block (struct dwarf2_cu
*cu
)
22648 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
22651 static struct die_info
*
22652 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
22654 struct die_info
*die
;
22655 size_t size
= sizeof (struct die_info
);
22658 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
22660 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
22661 memset (die
, 0, sizeof (struct die_info
));
22667 /* Macro support. */
22669 /* An overload of dwarf_decode_macros that finds the correct section
22670 and ensures it is read in before calling the other overload. */
22673 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22674 int section_is_gnu
)
22676 struct dwarf2_per_objfile
*dwarf2_per_objfile
22677 = cu
->per_cu
->dwarf2_per_objfile
;
22678 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22679 const struct line_header
*lh
= cu
->line_header
;
22680 unsigned int offset_size
= cu
->header
.offset_size
;
22681 struct dwarf2_section_info
*section
;
22682 const char *section_name
;
22684 if (cu
->dwo_unit
!= nullptr)
22686 if (section_is_gnu
)
22688 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22689 section_name
= ".debug_macro.dwo";
22693 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22694 section_name
= ".debug_macinfo.dwo";
22699 if (section_is_gnu
)
22701 section
= &dwarf2_per_objfile
->macro
;
22702 section_name
= ".debug_macro";
22706 section
= &dwarf2_per_objfile
->macinfo
;
22707 section_name
= ".debug_macinfo";
22711 section
->read (objfile
);
22712 if (section
->buffer
== nullptr)
22714 complaint (_("missing %s section"), section_name
);
22718 buildsym_compunit
*builder
= cu
->get_builder ();
22720 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
22721 offset_size
, offset
, section_is_gnu
);
22724 /* Return the .debug_loc section to use for CU.
22725 For DWO files use .debug_loc.dwo. */
22727 static struct dwarf2_section_info
*
22728 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22730 struct dwarf2_per_objfile
*dwarf2_per_objfile
22731 = cu
->per_cu
->dwarf2_per_objfile
;
22735 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22737 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22739 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22740 : &dwarf2_per_objfile
->loc
);
22743 /* A helper function that fills in a dwarf2_loclist_baton. */
22746 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22747 struct dwarf2_loclist_baton
*baton
,
22748 const struct attribute
*attr
)
22750 struct dwarf2_per_objfile
*dwarf2_per_objfile
22751 = cu
->per_cu
->dwarf2_per_objfile
;
22752 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22754 section
->read (dwarf2_per_objfile
->objfile
);
22756 baton
->per_cu
= cu
->per_cu
;
22757 gdb_assert (baton
->per_cu
);
22758 /* We don't know how long the location list is, but make sure we
22759 don't run off the edge of the section. */
22760 baton
->size
= section
->size
- DW_UNSND (attr
);
22761 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22762 if (cu
->base_address
.has_value ())
22763 baton
->base_address
= *cu
->base_address
;
22765 baton
->base_address
= 0;
22766 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22770 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22771 struct dwarf2_cu
*cu
, int is_block
)
22773 struct dwarf2_per_objfile
*dwarf2_per_objfile
22774 = cu
->per_cu
->dwarf2_per_objfile
;
22775 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22776 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22778 if (attr
->form_is_section_offset ()
22779 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22780 the section. If so, fall through to the complaint in the
22782 && DW_UNSND (attr
) < section
->get_size (objfile
))
22784 struct dwarf2_loclist_baton
*baton
;
22786 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22788 fill_in_loclist_baton (cu
, baton
, attr
);
22790 if (!cu
->base_address
.has_value ())
22791 complaint (_("Location list used without "
22792 "specifying the CU base address."));
22794 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22795 ? dwarf2_loclist_block_index
22796 : dwarf2_loclist_index
);
22797 SYMBOL_LOCATION_BATON (sym
) = baton
;
22801 struct dwarf2_locexpr_baton
*baton
;
22803 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22804 baton
->per_cu
= cu
->per_cu
;
22805 gdb_assert (baton
->per_cu
);
22807 if (attr
->form_is_block ())
22809 /* Note that we're just copying the block's data pointer
22810 here, not the actual data. We're still pointing into the
22811 info_buffer for SYM's objfile; right now we never release
22812 that buffer, but when we do clean up properly this may
22814 baton
->size
= DW_BLOCK (attr
)->size
;
22815 baton
->data
= DW_BLOCK (attr
)->data
;
22819 dwarf2_invalid_attrib_class_complaint ("location description",
22820 sym
->natural_name ());
22824 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22825 ? dwarf2_locexpr_block_index
22826 : dwarf2_locexpr_index
);
22827 SYMBOL_LOCATION_BATON (sym
) = baton
;
22834 dwarf2_per_cu_data::objfile () const
22836 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22838 /* Return the master objfile, so that we can report and look up the
22839 correct file containing this variable. */
22840 if (objfile
->separate_debug_objfile_backlink
)
22841 objfile
= objfile
->separate_debug_objfile_backlink
;
22846 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22847 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22848 CU_HEADERP first. */
22850 static const struct comp_unit_head
*
22851 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22852 const struct dwarf2_per_cu_data
*per_cu
)
22854 const gdb_byte
*info_ptr
;
22857 return &per_cu
->cu
->header
;
22859 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
22861 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22862 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22863 rcuh_kind::COMPILE
);
22871 dwarf2_per_cu_data::addr_size () const
22873 struct comp_unit_head cu_header_local
;
22874 const struct comp_unit_head
*cu_headerp
;
22876 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22878 return cu_headerp
->addr_size
;
22884 dwarf2_per_cu_data::offset_size () const
22886 struct comp_unit_head cu_header_local
;
22887 const struct comp_unit_head
*cu_headerp
;
22889 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22891 return cu_headerp
->offset_size
;
22897 dwarf2_per_cu_data::ref_addr_size () const
22899 struct comp_unit_head cu_header_local
;
22900 const struct comp_unit_head
*cu_headerp
;
22902 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22904 if (cu_headerp
->version
== 2)
22905 return cu_headerp
->addr_size
;
22907 return cu_headerp
->offset_size
;
22913 dwarf2_per_cu_data::text_offset () const
22915 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22917 return objfile
->text_section_offset ();
22923 dwarf2_per_cu_data::addr_type () const
22925 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22926 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
22927 struct type
*addr_type
= lookup_pointer_type (void_type
);
22928 int addr_size
= this->addr_size ();
22930 if (TYPE_LENGTH (addr_type
) == addr_size
)
22933 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
22937 /* A helper function for dwarf2_find_containing_comp_unit that returns
22938 the index of the result, and that searches a vector. It will
22939 return a result even if the offset in question does not actually
22940 occur in any CU. This is separate so that it can be unit
22944 dwarf2_find_containing_comp_unit
22945 (sect_offset sect_off
,
22946 unsigned int offset_in_dwz
,
22947 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
22952 high
= all_comp_units
.size () - 1;
22955 struct dwarf2_per_cu_data
*mid_cu
;
22956 int mid
= low
+ (high
- low
) / 2;
22958 mid_cu
= all_comp_units
[mid
];
22959 if (mid_cu
->is_dwz
> offset_in_dwz
22960 || (mid_cu
->is_dwz
== offset_in_dwz
22961 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
22966 gdb_assert (low
== high
);
22970 /* Locate the .debug_info compilation unit from CU's objfile which contains
22971 the DIE at OFFSET. Raises an error on failure. */
22973 static struct dwarf2_per_cu_data
*
22974 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
22975 unsigned int offset_in_dwz
,
22976 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
22979 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22980 dwarf2_per_objfile
->all_comp_units
);
22981 struct dwarf2_per_cu_data
*this_cu
22982 = dwarf2_per_objfile
->all_comp_units
[low
];
22984 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
22986 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
22987 error (_("Dwarf Error: could not find partial DIE containing "
22988 "offset %s [in module %s]"),
22989 sect_offset_str (sect_off
),
22990 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
22992 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
22994 return dwarf2_per_objfile
->all_comp_units
[low
-1];
22998 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
22999 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23000 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23001 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23008 namespace selftests
{
23009 namespace find_containing_comp_unit
{
23014 struct dwarf2_per_cu_data one
{};
23015 struct dwarf2_per_cu_data two
{};
23016 struct dwarf2_per_cu_data three
{};
23017 struct dwarf2_per_cu_data four
{};
23020 two
.sect_off
= sect_offset (one
.length
);
23025 four
.sect_off
= sect_offset (three
.length
);
23029 std::vector
<dwarf2_per_cu_data
*> units
;
23030 units
.push_back (&one
);
23031 units
.push_back (&two
);
23032 units
.push_back (&three
);
23033 units
.push_back (&four
);
23037 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23038 SELF_CHECK (units
[result
] == &one
);
23039 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23040 SELF_CHECK (units
[result
] == &one
);
23041 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23042 SELF_CHECK (units
[result
] == &two
);
23044 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23045 SELF_CHECK (units
[result
] == &three
);
23046 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23047 SELF_CHECK (units
[result
] == &three
);
23048 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23049 SELF_CHECK (units
[result
] == &four
);
23055 #endif /* GDB_SELF_TEST */
23057 /* Initialize dwarf2_cu CU, owned by PER_CU. */
23059 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
23060 : per_cu (per_cu_
),
23062 has_loclist (false),
23063 checked_producer (false),
23064 producer_is_gxx_lt_4_6 (false),
23065 producer_is_gcc_lt_4_3 (false),
23066 producer_is_icc (false),
23067 producer_is_icc_lt_14 (false),
23068 producer_is_codewarrior (false),
23069 processing_has_namespace_info (false)
23074 /* Destroy a dwarf2_cu. */
23076 dwarf2_cu::~dwarf2_cu ()
23081 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23084 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23085 enum language pretend_language
)
23087 struct attribute
*attr
;
23089 /* Set the language we're debugging. */
23090 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23091 if (attr
!= nullptr)
23092 set_cu_language (DW_UNSND (attr
), cu
);
23095 cu
->language
= pretend_language
;
23096 cu
->language_defn
= language_def (cu
->language
);
23099 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23102 /* Increase the age counter on each cached compilation unit, and free
23103 any that are too old. */
23106 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23108 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23110 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
23111 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23112 while (per_cu
!= NULL
)
23114 per_cu
->cu
->last_used
++;
23115 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23116 dwarf2_mark (per_cu
->cu
);
23117 per_cu
= per_cu
->cu
->read_in_chain
;
23120 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23121 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23122 while (per_cu
!= NULL
)
23124 struct dwarf2_per_cu_data
*next_cu
;
23126 next_cu
= per_cu
->cu
->read_in_chain
;
23128 if (!per_cu
->cu
->mark
)
23131 *last_chain
= next_cu
;
23134 last_chain
= &per_cu
->cu
->read_in_chain
;
23140 /* Remove a single compilation unit from the cache. */
23143 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23145 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23146 struct dwarf2_per_objfile
*dwarf2_per_objfile
23147 = target_per_cu
->dwarf2_per_objfile
;
23149 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23150 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23151 while (per_cu
!= NULL
)
23153 struct dwarf2_per_cu_data
*next_cu
;
23155 next_cu
= per_cu
->cu
->read_in_chain
;
23157 if (per_cu
== target_per_cu
)
23161 *last_chain
= next_cu
;
23165 last_chain
= &per_cu
->cu
->read_in_chain
;
23171 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23172 We store these in a hash table separate from the DIEs, and preserve them
23173 when the DIEs are flushed out of cache.
23175 The CU "per_cu" pointer is needed because offset alone is not enough to
23176 uniquely identify the type. A file may have multiple .debug_types sections,
23177 or the type may come from a DWO file. Furthermore, while it's more logical
23178 to use per_cu->section+offset, with Fission the section with the data is in
23179 the DWO file but we don't know that section at the point we need it.
23180 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23181 because we can enter the lookup routine, get_die_type_at_offset, from
23182 outside this file, and thus won't necessarily have PER_CU->cu.
23183 Fortunately, PER_CU is stable for the life of the objfile. */
23185 struct dwarf2_per_cu_offset_and_type
23187 const struct dwarf2_per_cu_data
*per_cu
;
23188 sect_offset sect_off
;
23192 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23195 per_cu_offset_and_type_hash (const void *item
)
23197 const struct dwarf2_per_cu_offset_and_type
*ofs
23198 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23200 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23203 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23206 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23208 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23209 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23210 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23211 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23213 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23214 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23217 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23218 table if necessary. For convenience, return TYPE.
23220 The DIEs reading must have careful ordering to:
23221 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23222 reading current DIE.
23223 * Not trying to dereference contents of still incompletely read in types
23224 while reading in other DIEs.
23225 * Enable referencing still incompletely read in types just by a pointer to
23226 the type without accessing its fields.
23228 Therefore caller should follow these rules:
23229 * Try to fetch any prerequisite types we may need to build this DIE type
23230 before building the type and calling set_die_type.
23231 * After building type call set_die_type for current DIE as soon as
23232 possible before fetching more types to complete the current type.
23233 * Make the type as complete as possible before fetching more types. */
23235 static struct type
*
23236 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23238 struct dwarf2_per_objfile
*dwarf2_per_objfile
23239 = cu
->per_cu
->dwarf2_per_objfile
;
23240 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23241 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23242 struct attribute
*attr
;
23243 struct dynamic_prop prop
;
23245 /* For Ada types, make sure that the gnat-specific data is always
23246 initialized (if not already set). There are a few types where
23247 we should not be doing so, because the type-specific area is
23248 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23249 where the type-specific area is used to store the floatformat).
23250 But this is not a problem, because the gnat-specific information
23251 is actually not needed for these types. */
23252 if (need_gnat_info (cu
)
23253 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23254 && TYPE_CODE (type
) != TYPE_CODE_FLT
23255 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23256 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23257 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23258 && !HAVE_GNAT_AUX_INFO (type
))
23259 INIT_GNAT_SPECIFIC (type
);
23261 /* Read DW_AT_allocated and set in type. */
23262 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23263 if (attr
!= NULL
&& attr
->form_is_block ())
23265 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23266 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23267 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
23269 else if (attr
!= NULL
)
23271 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23272 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23273 sect_offset_str (die
->sect_off
));
23276 /* Read DW_AT_associated and set in type. */
23277 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23278 if (attr
!= NULL
&& attr
->form_is_block ())
23280 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23281 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23282 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
23284 else if (attr
!= NULL
)
23286 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23287 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23288 sect_offset_str (die
->sect_off
));
23291 /* Read DW_AT_data_location and set in type. */
23292 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23293 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23294 cu
->per_cu
->addr_type ()))
23295 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
23297 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23298 dwarf2_per_objfile
->die_type_hash
23299 = htab_up (htab_create_alloc (127,
23300 per_cu_offset_and_type_hash
,
23301 per_cu_offset_and_type_eq
,
23302 NULL
, xcalloc
, xfree
));
23304 ofs
.per_cu
= cu
->per_cu
;
23305 ofs
.sect_off
= die
->sect_off
;
23307 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23308 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23310 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23311 sect_offset_str (die
->sect_off
));
23312 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23313 struct dwarf2_per_cu_offset_and_type
);
23318 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23319 or return NULL if the die does not have a saved type. */
23321 static struct type
*
23322 get_die_type_at_offset (sect_offset sect_off
,
23323 struct dwarf2_per_cu_data
*per_cu
)
23325 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23326 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23328 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23331 ofs
.per_cu
= per_cu
;
23332 ofs
.sect_off
= sect_off
;
23333 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23334 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23341 /* Look up the type for DIE in CU in die_type_hash,
23342 or return NULL if DIE does not have a saved type. */
23344 static struct type
*
23345 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23347 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23350 /* Add a dependence relationship from CU to REF_PER_CU. */
23353 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23354 struct dwarf2_per_cu_data
*ref_per_cu
)
23358 if (cu
->dependencies
== NULL
)
23360 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23361 NULL
, &cu
->comp_unit_obstack
,
23362 hashtab_obstack_allocate
,
23363 dummy_obstack_deallocate
);
23365 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23367 *slot
= ref_per_cu
;
23370 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23371 Set the mark field in every compilation unit in the
23372 cache that we must keep because we are keeping CU. */
23375 dwarf2_mark_helper (void **slot
, void *data
)
23377 struct dwarf2_per_cu_data
*per_cu
;
23379 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23381 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23382 reading of the chain. As such dependencies remain valid it is not much
23383 useful to track and undo them during QUIT cleanups. */
23384 if (per_cu
->cu
== NULL
)
23387 if (per_cu
->cu
->mark
)
23389 per_cu
->cu
->mark
= true;
23391 if (per_cu
->cu
->dependencies
!= NULL
)
23392 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23397 /* Set the mark field in CU and in every other compilation unit in the
23398 cache that we must keep because we are keeping CU. */
23401 dwarf2_mark (struct dwarf2_cu
*cu
)
23406 if (cu
->dependencies
!= NULL
)
23407 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23411 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23415 per_cu
->cu
->mark
= false;
23416 per_cu
= per_cu
->cu
->read_in_chain
;
23420 /* Trivial hash function for partial_die_info: the hash value of a DIE
23421 is its offset in .debug_info for this objfile. */
23424 partial_die_hash (const void *item
)
23426 const struct partial_die_info
*part_die
23427 = (const struct partial_die_info
*) item
;
23429 return to_underlying (part_die
->sect_off
);
23432 /* Trivial comparison function for partial_die_info structures: two DIEs
23433 are equal if they have the same offset. */
23436 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23438 const struct partial_die_info
*part_die_lhs
23439 = (const struct partial_die_info
*) item_lhs
;
23440 const struct partial_die_info
*part_die_rhs
23441 = (const struct partial_die_info
*) item_rhs
;
23443 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23446 struct cmd_list_element
*set_dwarf_cmdlist
;
23447 struct cmd_list_element
*show_dwarf_cmdlist
;
23450 set_dwarf_cmd (const char *args
, int from_tty
)
23452 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23457 show_dwarf_cmd (const char *args
, int from_tty
)
23459 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23463 show_check_physname (struct ui_file
*file
, int from_tty
,
23464 struct cmd_list_element
*c
, const char *value
)
23466 fprintf_filtered (file
,
23467 _("Whether to check \"physname\" is %s.\n"),
23471 void _initialize_dwarf2_read ();
23473 _initialize_dwarf2_read ()
23475 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23476 Set DWARF specific variables.\n\
23477 Configure DWARF variables such as the cache size."),
23478 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23479 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23481 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23482 Show DWARF specific variables.\n\
23483 Show DWARF variables such as the cache size."),
23484 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23485 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23487 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23488 &dwarf_max_cache_age
, _("\
23489 Set the upper bound on the age of cached DWARF compilation units."), _("\
23490 Show the upper bound on the age of cached DWARF compilation units."), _("\
23491 A higher limit means that cached compilation units will be stored\n\
23492 in memory longer, and more total memory will be used. Zero disables\n\
23493 caching, which can slow down startup."),
23495 show_dwarf_max_cache_age
,
23496 &set_dwarf_cmdlist
,
23497 &show_dwarf_cmdlist
);
23499 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23500 Set debugging of the DWARF reader."), _("\
23501 Show debugging of the DWARF reader."), _("\
23502 When enabled (non-zero), debugging messages are printed during DWARF\n\
23503 reading and symtab expansion. A value of 1 (one) provides basic\n\
23504 information. A value greater than 1 provides more verbose information."),
23507 &setdebuglist
, &showdebuglist
);
23509 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23510 Set debugging of the DWARF DIE reader."), _("\
23511 Show debugging of the DWARF DIE reader."), _("\
23512 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23513 The value is the maximum depth to print."),
23516 &setdebuglist
, &showdebuglist
);
23518 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23519 Set debugging of the dwarf line reader."), _("\
23520 Show debugging of the dwarf line reader."), _("\
23521 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23522 A value of 1 (one) provides basic information.\n\
23523 A value greater than 1 provides more verbose information."),
23526 &setdebuglist
, &showdebuglist
);
23528 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23529 Set cross-checking of \"physname\" code against demangler."), _("\
23530 Show cross-checking of \"physname\" code against demangler."), _("\
23531 When enabled, GDB's internal \"physname\" code is checked against\n\
23533 NULL
, show_check_physname
,
23534 &setdebuglist
, &showdebuglist
);
23536 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23537 no_class
, &use_deprecated_index_sections
, _("\
23538 Set whether to use deprecated gdb_index sections."), _("\
23539 Show whether to use deprecated gdb_index sections."), _("\
23540 When enabled, deprecated .gdb_index sections are used anyway.\n\
23541 Normally they are ignored either because of a missing feature or\n\
23542 performance issue.\n\
23543 Warning: This option must be enabled before gdb reads the file."),
23546 &setlist
, &showlist
);
23548 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23549 &dwarf2_locexpr_funcs
);
23550 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23551 &dwarf2_loclist_funcs
);
23553 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23554 &dwarf2_block_frame_base_locexpr_funcs
);
23555 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23556 &dwarf2_block_frame_base_loclist_funcs
);
23559 selftests::register_test ("dw2_expand_symtabs_matching",
23560 selftests::dw2_expand_symtabs_matching::run_test
);
23561 selftests::register_test ("dwarf2_find_containing_comp_unit",
23562 selftests::find_containing_comp_unit::run_test
);