1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2read.h"
33 #include "dwarf-index-cache.h"
34 #include "dwarf-index-common.h"
35 #include "dwarf2/leb.h"
44 #include "gdb-demangle.h"
45 #include "filenames.h" /* for DOSish file names */
48 #include "complaints.h"
49 #include "dwarf2expr.h"
50 #include "dwarf2loc.h"
51 #include "cp-support.h"
57 #include "typeprint.h"
62 #include "gdbcore.h" /* for gnutarget */
63 #include "gdb/gdb-index.h"
68 #include "namespace.h"
69 #include "gdbsupport/function-view.h"
70 #include "gdbsupport/gdb_optional.h"
71 #include "gdbsupport/underlying.h"
72 #include "gdbsupport/hash_enum.h"
73 #include "filename-seen-cache.h"
77 #include <unordered_map>
78 #include "gdbsupport/selftest.h"
79 #include "rust-lang.h"
80 #include "gdbsupport/pathstuff.h"
82 /* When == 1, print basic high level tracing messages.
83 When > 1, be more verbose.
84 This is in contrast to the low level DIE reading of dwarf_die_debug. */
85 static unsigned int dwarf_read_debug
= 0;
87 /* When non-zero, dump DIEs after they are read in. */
88 static unsigned int dwarf_die_debug
= 0;
90 /* When non-zero, dump line number entries as they are read in. */
91 static unsigned int dwarf_line_debug
= 0;
93 /* When true, cross-check physname against demangler. */
94 static bool check_physname
= false;
96 /* When true, do not reject deprecated .gdb_index sections. */
97 static bool use_deprecated_index_sections
= false;
99 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
101 /* The "aclass" indices for various kinds of computed DWARF symbols. */
103 static int dwarf2_locexpr_index
;
104 static int dwarf2_loclist_index
;
105 static int dwarf2_locexpr_block_index
;
106 static int dwarf2_loclist_block_index
;
108 /* An index into a (C++) symbol name component in a symbol name as
109 recorded in the mapped_index's symbol table. For each C++ symbol
110 in the symbol table, we record one entry for the start of each
111 component in the symbol in a table of name components, and then
112 sort the table, in order to be able to binary search symbol names,
113 ignoring leading namespaces, both completion and regular look up.
114 For example, for symbol "A::B::C", we'll have an entry that points
115 to "A::B::C", another that points to "B::C", and another for "C".
116 Note that function symbols in GDB index have no parameter
117 information, just the function/method names. You can convert a
118 name_component to a "const char *" using the
119 'mapped_index::symbol_name_at(offset_type)' method. */
121 struct name_component
123 /* Offset in the symbol name where the component starts. Stored as
124 a (32-bit) offset instead of a pointer to save memory and improve
125 locality on 64-bit architectures. */
126 offset_type name_offset
;
128 /* The symbol's index in the symbol and constant pool tables of a
133 /* Base class containing bits shared by both .gdb_index and
134 .debug_name indexes. */
136 struct mapped_index_base
138 mapped_index_base () = default;
139 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
141 /* The name_component table (a sorted vector). See name_component's
142 description above. */
143 std::vector
<name_component
> name_components
;
145 /* How NAME_COMPONENTS is sorted. */
146 enum case_sensitivity name_components_casing
;
148 /* Return the number of names in the symbol table. */
149 virtual size_t symbol_name_count () const = 0;
151 /* Get the name of the symbol at IDX in the symbol table. */
152 virtual const char *symbol_name_at (offset_type idx
) const = 0;
154 /* Return whether the name at IDX in the symbol table should be
156 virtual bool symbol_name_slot_invalid (offset_type idx
) const
161 /* Build the symbol name component sorted vector, if we haven't
163 void build_name_components ();
165 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
166 possible matches for LN_NO_PARAMS in the name component
168 std::pair
<std::vector
<name_component
>::const_iterator
,
169 std::vector
<name_component
>::const_iterator
>
170 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
171 enum language lang
) const;
173 /* Prevent deleting/destroying via a base class pointer. */
175 ~mapped_index_base() = default;
178 /* A description of the mapped index. The file format is described in
179 a comment by the code that writes the index. */
180 struct mapped_index final
: public mapped_index_base
182 /* A slot/bucket in the symbol table hash. */
183 struct symbol_table_slot
185 const offset_type name
;
186 const offset_type vec
;
189 /* Index data format version. */
192 /* The address table data. */
193 gdb::array_view
<const gdb_byte
> address_table
;
195 /* The symbol table, implemented as a hash table. */
196 gdb::array_view
<symbol_table_slot
> symbol_table
;
198 /* A pointer to the constant pool. */
199 const char *constant_pool
= nullptr;
201 bool symbol_name_slot_invalid (offset_type idx
) const override
203 const auto &bucket
= this->symbol_table
[idx
];
204 return bucket
.name
== 0 && bucket
.vec
== 0;
207 /* Convenience method to get at the name of the symbol at IDX in the
209 const char *symbol_name_at (offset_type idx
) const override
210 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
212 size_t symbol_name_count () const override
213 { return this->symbol_table
.size (); }
216 /* A description of the mapped .debug_names.
217 Uninitialized map has CU_COUNT 0. */
218 struct mapped_debug_names final
: public mapped_index_base
220 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
221 : dwarf2_per_objfile (dwarf2_per_objfile_
)
224 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
225 bfd_endian dwarf5_byte_order
;
226 bool dwarf5_is_dwarf64
;
227 bool augmentation_is_gdb
;
229 uint32_t cu_count
= 0;
230 uint32_t tu_count
, bucket_count
, name_count
;
231 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
232 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
233 const gdb_byte
*name_table_string_offs_reordered
;
234 const gdb_byte
*name_table_entry_offs_reordered
;
235 const gdb_byte
*entry_pool
;
242 /* Attribute name DW_IDX_*. */
245 /* Attribute form DW_FORM_*. */
248 /* Value if FORM is DW_FORM_implicit_const. */
249 LONGEST implicit_const
;
251 std::vector
<attr
> attr_vec
;
254 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
256 const char *namei_to_name (uint32_t namei
) const;
258 /* Implementation of the mapped_index_base virtual interface, for
259 the name_components cache. */
261 const char *symbol_name_at (offset_type idx
) const override
262 { return namei_to_name (idx
); }
264 size_t symbol_name_count () const override
265 { return this->name_count
; }
268 /* See dwarf2read.h. */
271 get_dwarf2_per_objfile (struct objfile
*objfile
)
273 return dwarf2_objfile_data_key
.get (objfile
);
276 /* Default names of the debugging sections. */
278 /* Note that if the debugging section has been compressed, it might
279 have a name like .zdebug_info. */
281 static const struct dwarf2_debug_sections dwarf2_elf_names
=
283 { ".debug_info", ".zdebug_info" },
284 { ".debug_abbrev", ".zdebug_abbrev" },
285 { ".debug_line", ".zdebug_line" },
286 { ".debug_loc", ".zdebug_loc" },
287 { ".debug_loclists", ".zdebug_loclists" },
288 { ".debug_macinfo", ".zdebug_macinfo" },
289 { ".debug_macro", ".zdebug_macro" },
290 { ".debug_str", ".zdebug_str" },
291 { ".debug_str_offsets", ".zdebug_str_offsets" },
292 { ".debug_line_str", ".zdebug_line_str" },
293 { ".debug_ranges", ".zdebug_ranges" },
294 { ".debug_rnglists", ".zdebug_rnglists" },
295 { ".debug_types", ".zdebug_types" },
296 { ".debug_addr", ".zdebug_addr" },
297 { ".debug_frame", ".zdebug_frame" },
298 { ".eh_frame", NULL
},
299 { ".gdb_index", ".zgdb_index" },
300 { ".debug_names", ".zdebug_names" },
301 { ".debug_aranges", ".zdebug_aranges" },
305 /* List of DWO/DWP sections. */
307 static const struct dwop_section_names
309 struct dwarf2_section_names abbrev_dwo
;
310 struct dwarf2_section_names info_dwo
;
311 struct dwarf2_section_names line_dwo
;
312 struct dwarf2_section_names loc_dwo
;
313 struct dwarf2_section_names loclists_dwo
;
314 struct dwarf2_section_names macinfo_dwo
;
315 struct dwarf2_section_names macro_dwo
;
316 struct dwarf2_section_names str_dwo
;
317 struct dwarf2_section_names str_offsets_dwo
;
318 struct dwarf2_section_names types_dwo
;
319 struct dwarf2_section_names cu_index
;
320 struct dwarf2_section_names tu_index
;
324 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
325 { ".debug_info.dwo", ".zdebug_info.dwo" },
326 { ".debug_line.dwo", ".zdebug_line.dwo" },
327 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
328 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
329 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
330 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
331 { ".debug_str.dwo", ".zdebug_str.dwo" },
332 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
333 { ".debug_types.dwo", ".zdebug_types.dwo" },
334 { ".debug_cu_index", ".zdebug_cu_index" },
335 { ".debug_tu_index", ".zdebug_tu_index" },
338 /* local data types */
340 /* The data in a compilation unit header, after target2host
341 translation, looks like this. */
342 struct comp_unit_head
346 unsigned char addr_size
;
347 unsigned char signed_addr_p
;
348 sect_offset abbrev_sect_off
;
350 /* Size of file offsets; either 4 or 8. */
351 unsigned int offset_size
;
353 /* Size of the length field; either 4 or 12. */
354 unsigned int initial_length_size
;
356 enum dwarf_unit_type unit_type
;
358 /* Offset to the first byte of this compilation unit header in the
359 .debug_info section, for resolving relative reference dies. */
360 sect_offset sect_off
;
362 /* Offset to first die in this cu from the start of the cu.
363 This will be the first byte following the compilation unit header. */
364 cu_offset first_die_cu_offset
;
367 /* 64-bit signature of this unit. For type units, it denotes the signature of
368 the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
369 Also used in DWARF 5, to denote the dwo id when the unit type is
370 DW_UT_skeleton or DW_UT_split_compile. */
373 /* For types, offset in the type's DIE of the type defined by this TU. */
374 cu_offset type_cu_offset_in_tu
;
377 /* Type used for delaying computation of method physnames.
378 See comments for compute_delayed_physnames. */
379 struct delayed_method_info
381 /* The type to which the method is attached, i.e., its parent class. */
384 /* The index of the method in the type's function fieldlists. */
387 /* The index of the method in the fieldlist. */
390 /* The name of the DIE. */
393 /* The DIE associated with this method. */
394 struct die_info
*die
;
397 /* Internal state when decoding a particular compilation unit. */
400 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
403 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
405 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
406 Create the set of symtabs used by this TU, or if this TU is sharing
407 symtabs with another TU and the symtabs have already been created
408 then restore those symtabs in the line header.
409 We don't need the pc/line-number mapping for type units. */
410 void setup_type_unit_groups (struct die_info
*die
);
412 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
413 buildsym_compunit constructor. */
414 struct compunit_symtab
*start_symtab (const char *name
,
415 const char *comp_dir
,
418 /* Reset the builder. */
419 void reset_builder () { m_builder
.reset (); }
421 /* The header of the compilation unit. */
422 struct comp_unit_head header
{};
424 /* Base address of this compilation unit. */
425 CORE_ADDR base_address
= 0;
427 /* Non-zero if base_address has been set. */
430 /* The language we are debugging. */
431 enum language language
= language_unknown
;
432 const struct language_defn
*language_defn
= nullptr;
434 const char *producer
= nullptr;
437 /* The symtab builder for this CU. This is only non-NULL when full
438 symbols are being read. */
439 std::unique_ptr
<buildsym_compunit
> m_builder
;
442 /* The generic symbol table building routines have separate lists for
443 file scope symbols and all all other scopes (local scopes). So
444 we need to select the right one to pass to add_symbol_to_list().
445 We do it by keeping a pointer to the correct list in list_in_scope.
447 FIXME: The original dwarf code just treated the file scope as the
448 first local scope, and all other local scopes as nested local
449 scopes, and worked fine. Check to see if we really need to
450 distinguish these in buildsym.c. */
451 struct pending
**list_in_scope
= nullptr;
453 /* Hash table holding all the loaded partial DIEs
454 with partial_die->offset.SECT_OFF as hash. */
455 htab_t partial_dies
= nullptr;
457 /* Storage for things with the same lifetime as this read-in compilation
458 unit, including partial DIEs. */
459 auto_obstack comp_unit_obstack
;
461 /* When multiple dwarf2_cu structures are living in memory, this field
462 chains them all together, so that they can be released efficiently.
463 We will probably also want a generation counter so that most-recently-used
464 compilation units are cached... */
465 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
467 /* Backlink to our per_cu entry. */
468 struct dwarf2_per_cu_data
*per_cu
;
470 /* How many compilation units ago was this CU last referenced? */
473 /* A hash table of DIE cu_offset for following references with
474 die_info->offset.sect_off as hash. */
475 htab_t die_hash
= nullptr;
477 /* Full DIEs if read in. */
478 struct die_info
*dies
= nullptr;
480 /* A set of pointers to dwarf2_per_cu_data objects for compilation
481 units referenced by this one. Only set during full symbol processing;
482 partial symbol tables do not have dependencies. */
483 htab_t dependencies
= nullptr;
485 /* Header data from the line table, during full symbol processing. */
486 struct line_header
*line_header
= nullptr;
487 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
488 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
489 this is the DW_TAG_compile_unit die for this CU. We'll hold on
490 to the line header as long as this DIE is being processed. See
491 process_die_scope. */
492 die_info
*line_header_die_owner
= nullptr;
494 /* A list of methods which need to have physnames computed
495 after all type information has been read. */
496 std::vector
<delayed_method_info
> method_list
;
498 /* To be copied to symtab->call_site_htab. */
499 htab_t call_site_htab
= nullptr;
501 /* Non-NULL if this CU came from a DWO file.
502 There is an invariant here that is important to remember:
503 Except for attributes copied from the top level DIE in the "main"
504 (or "stub") file in preparation for reading the DWO file
505 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
506 Either there isn't a DWO file (in which case this is NULL and the point
507 is moot), or there is and either we're not going to read it (in which
508 case this is NULL) or there is and we are reading it (in which case this
510 struct dwo_unit
*dwo_unit
= nullptr;
512 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
513 Note this value comes from the Fission stub CU/TU's DIE. */
514 gdb::optional
<ULONGEST
> addr_base
;
516 /* The DW_AT_rnglists_base attribute if present.
517 Note this value comes from the Fission stub CU/TU's DIE.
518 Also note that the value is zero in the non-DWO case so this value can
519 be used without needing to know whether DWO files are in use or not.
520 N.B. This does not apply to DW_AT_ranges appearing in
521 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
522 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
523 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
524 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
525 ULONGEST ranges_base
= 0;
527 /* When reading debug info generated by older versions of rustc, we
528 have to rewrite some union types to be struct types with a
529 variant part. This rewriting must be done after the CU is fully
530 read in, because otherwise at the point of rewriting some struct
531 type might not have been fully processed. So, we keep a list of
532 all such types here and process them after expansion. */
533 std::vector
<struct type
*> rust_unions
;
535 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
536 files, the value is implicitly zero. For DWARF 5 version DWO files, the
537 value is often implicit and is the size of the header of
538 .debug_str_offsets section (8 or 4, depending on the address size). */
539 gdb::optional
<ULONGEST
> str_offsets_base
;
541 /* Mark used when releasing cached dies. */
544 /* This CU references .debug_loc. See the symtab->locations_valid field.
545 This test is imperfect as there may exist optimized debug code not using
546 any location list and still facing inlining issues if handled as
547 unoptimized code. For a future better test see GCC PR other/32998. */
548 bool has_loclist
: 1;
550 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
551 if all the producer_is_* fields are valid. This information is cached
552 because profiling CU expansion showed excessive time spent in
553 producer_is_gxx_lt_4_6. */
554 bool checked_producer
: 1;
555 bool producer_is_gxx_lt_4_6
: 1;
556 bool producer_is_gcc_lt_4_3
: 1;
557 bool producer_is_icc
: 1;
558 bool producer_is_icc_lt_14
: 1;
559 bool producer_is_codewarrior
: 1;
561 /* When true, the file that we're processing is known to have
562 debugging info for C++ namespaces. GCC 3.3.x did not produce
563 this information, but later versions do. */
565 bool processing_has_namespace_info
: 1;
567 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
569 /* If this CU was inherited by another CU (via specification,
570 abstract_origin, etc), this is the ancestor CU. */
573 /* Get the buildsym_compunit for this CU. */
574 buildsym_compunit
*get_builder ()
576 /* If this CU has a builder associated with it, use that. */
577 if (m_builder
!= nullptr)
578 return m_builder
.get ();
580 /* Otherwise, search ancestors for a valid builder. */
581 if (ancestor
!= nullptr)
582 return ancestor
->get_builder ();
588 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
589 This includes type_unit_group and quick_file_names. */
591 struct stmt_list_hash
593 /* The DWO unit this table is from or NULL if there is none. */
594 struct dwo_unit
*dwo_unit
;
596 /* Offset in .debug_line or .debug_line.dwo. */
597 sect_offset line_sect_off
;
600 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
601 an object of this type. */
603 struct type_unit_group
605 /* dwarf2read.c's main "handle" on a TU symtab.
606 To simplify things we create an artificial CU that "includes" all the
607 type units using this stmt_list so that the rest of the code still has
608 a "per_cu" handle on the symtab.
609 This PER_CU is recognized by having no section. */
610 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
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 number of symtabs from the line header.
627 The value here must match line_header.num_file_names. */
628 unsigned int num_symtabs
;
630 /* The symbol tables for this TU (obtained from the files listed in
632 WARNING: The order of entries here must match the order of entries
633 in the line header. After the first TU using this type_unit_group, the
634 line header for the subsequent TUs is recreated from this. This is done
635 because we need to use the same symtabs for each TU using the same
636 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
637 there's no guarantee the line header doesn't have duplicate entries. */
638 struct symtab
**symtabs
;
641 /* These sections are what may appear in a (real or virtual) DWO file. */
645 struct dwarf2_section_info abbrev
;
646 struct dwarf2_section_info line
;
647 struct dwarf2_section_info loc
;
648 struct dwarf2_section_info loclists
;
649 struct dwarf2_section_info macinfo
;
650 struct dwarf2_section_info macro
;
651 struct dwarf2_section_info str
;
652 struct dwarf2_section_info str_offsets
;
653 /* In the case of a virtual DWO file, these two are unused. */
654 struct dwarf2_section_info info
;
655 std::vector
<dwarf2_section_info
> types
;
658 /* CUs/TUs in DWP/DWO files. */
662 /* Backlink to the containing struct dwo_file. */
663 struct dwo_file
*dwo_file
;
665 /* The "id" that distinguishes this CU/TU.
666 .debug_info calls this "dwo_id", .debug_types calls this "signature".
667 Since signatures came first, we stick with it for consistency. */
670 /* The section this CU/TU lives in, in the DWO file. */
671 struct dwarf2_section_info
*section
;
673 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
674 sect_offset sect_off
;
677 /* For types, offset in the type's DIE of the type defined by this TU. */
678 cu_offset type_offset_in_tu
;
681 /* include/dwarf2.h defines the DWP section codes.
682 It defines a max value but it doesn't define a min value, which we
683 use for error checking, so provide one. */
685 enum dwp_v2_section_ids
690 /* Data for one DWO file.
692 This includes virtual DWO files (a virtual DWO file is a DWO file as it
693 appears in a DWP file). DWP files don't really have DWO files per se -
694 comdat folding of types "loses" the DWO file they came from, and from
695 a high level view DWP files appear to contain a mass of random types.
696 However, to maintain consistency with the non-DWP case we pretend DWP
697 files contain virtual DWO files, and we assign each TU with one virtual
698 DWO file (generally based on the line and abbrev section offsets -
699 a heuristic that seems to work in practice). */
703 dwo_file () = default;
704 DISABLE_COPY_AND_ASSIGN (dwo_file
);
706 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
707 For virtual DWO files the name is constructed from the section offsets
708 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
709 from related CU+TUs. */
710 const char *dwo_name
= nullptr;
712 /* The DW_AT_comp_dir attribute. */
713 const char *comp_dir
= nullptr;
715 /* The bfd, when the file is open. Otherwise this is NULL.
716 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
717 gdb_bfd_ref_ptr dbfd
;
719 /* The sections that make up this DWO file.
720 Remember that for virtual DWO files in DWP V2, these are virtual
721 sections (for lack of a better name). */
722 struct dwo_sections sections
{};
724 /* The CUs in the file.
725 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
726 an extension to handle LLVM's Link Time Optimization output (where
727 multiple source files may be compiled into a single object/dwo pair). */
730 /* Table of TUs in the file.
731 Each element is a struct dwo_unit. */
735 /* These sections are what may appear in a DWP file. */
739 /* These are used by both DWP version 1 and 2. */
740 struct dwarf2_section_info str
;
741 struct dwarf2_section_info cu_index
;
742 struct dwarf2_section_info tu_index
;
744 /* These are only used by DWP version 2 files.
745 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
746 sections are referenced by section number, and are not recorded here.
747 In DWP version 2 there is at most one copy of all these sections, each
748 section being (effectively) comprised of the concatenation of all of the
749 individual sections that exist in the version 1 format.
750 To keep the code simple we treat each of these concatenated pieces as a
751 section itself (a virtual section?). */
752 struct dwarf2_section_info abbrev
;
753 struct dwarf2_section_info info
;
754 struct dwarf2_section_info line
;
755 struct dwarf2_section_info loc
;
756 struct dwarf2_section_info macinfo
;
757 struct dwarf2_section_info macro
;
758 struct dwarf2_section_info str_offsets
;
759 struct dwarf2_section_info types
;
762 /* These sections are what may appear in a virtual DWO file in DWP version 1.
763 A virtual DWO file is a DWO file as it appears in a DWP file. */
765 struct virtual_v1_dwo_sections
767 struct dwarf2_section_info abbrev
;
768 struct dwarf2_section_info line
;
769 struct dwarf2_section_info loc
;
770 struct dwarf2_section_info macinfo
;
771 struct dwarf2_section_info macro
;
772 struct dwarf2_section_info str_offsets
;
773 /* Each DWP hash table entry records one CU or one TU.
774 That is recorded here, and copied to dwo_unit.section. */
775 struct dwarf2_section_info info_or_types
;
778 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
779 In version 2, the sections of the DWO files are concatenated together
780 and stored in one section of that name. Thus each ELF section contains
781 several "virtual" sections. */
783 struct virtual_v2_dwo_sections
785 bfd_size_type abbrev_offset
;
786 bfd_size_type abbrev_size
;
788 bfd_size_type line_offset
;
789 bfd_size_type line_size
;
791 bfd_size_type loc_offset
;
792 bfd_size_type loc_size
;
794 bfd_size_type macinfo_offset
;
795 bfd_size_type macinfo_size
;
797 bfd_size_type macro_offset
;
798 bfd_size_type macro_size
;
800 bfd_size_type str_offsets_offset
;
801 bfd_size_type str_offsets_size
;
803 /* Each DWP hash table entry records one CU or one TU.
804 That is recorded here, and copied to dwo_unit.section. */
805 bfd_size_type info_or_types_offset
;
806 bfd_size_type info_or_types_size
;
809 /* Contents of DWP hash tables. */
811 struct dwp_hash_table
813 uint32_t version
, nr_columns
;
814 uint32_t nr_units
, nr_slots
;
815 const gdb_byte
*hash_table
, *unit_table
;
820 const gdb_byte
*indices
;
824 /* This is indexed by column number and gives the id of the section
826 #define MAX_NR_V2_DWO_SECTIONS \
827 (1 /* .debug_info or .debug_types */ \
828 + 1 /* .debug_abbrev */ \
829 + 1 /* .debug_line */ \
830 + 1 /* .debug_loc */ \
831 + 1 /* .debug_str_offsets */ \
832 + 1 /* .debug_macro or .debug_macinfo */)
833 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
834 const gdb_byte
*offsets
;
835 const gdb_byte
*sizes
;
840 /* Data for one DWP file. */
844 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
846 dbfd (std::move (abfd
))
850 /* Name of the file. */
853 /* File format version. */
857 gdb_bfd_ref_ptr dbfd
;
859 /* Section info for this file. */
860 struct dwp_sections sections
{};
862 /* Table of CUs in the file. */
863 const struct dwp_hash_table
*cus
= nullptr;
865 /* Table of TUs in the file. */
866 const struct dwp_hash_table
*tus
= nullptr;
868 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
869 htab_t loaded_cus
{};
870 htab_t loaded_tus
{};
872 /* Table to map ELF section numbers to their sections.
873 This is only needed for the DWP V1 file format. */
874 unsigned int num_sections
= 0;
875 asection
**elf_sections
= nullptr;
879 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
881 /* Struct used to pass misc. parameters to read_die_and_children, et
882 al. which are used for both .debug_info and .debug_types dies.
883 All parameters here are unchanging for the life of the call. This
884 struct exists to abstract away the constant parameters of die reading. */
886 struct die_reader_specs
888 /* The bfd of die_section. */
891 /* The CU of the DIE we are parsing. */
892 struct dwarf2_cu
*cu
;
894 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
895 struct dwo_file
*dwo_file
;
897 /* The section the die comes from.
898 This is either .debug_info or .debug_types, or the .dwo variants. */
899 struct dwarf2_section_info
*die_section
;
901 /* die_section->buffer. */
902 const gdb_byte
*buffer
;
904 /* The end of the buffer. */
905 const gdb_byte
*buffer_end
;
907 /* The value of the DW_AT_comp_dir attribute. */
908 const char *comp_dir
;
910 /* The abbreviation table to use when reading the DIEs. */
911 struct abbrev_table
*abbrev_table
;
914 /* A subclass of die_reader_specs that holds storage and has complex
915 constructor and destructor behavior. */
917 class cutu_reader
: public die_reader_specs
921 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
922 struct abbrev_table
*abbrev_table
,
923 int use_existing_cu
, int keep
,
926 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
927 struct dwarf2_cu
*parent_cu
= nullptr,
928 struct dwo_file
*dwo_file
= nullptr);
932 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
934 const gdb_byte
*info_ptr
= nullptr;
935 struct die_info
*comp_unit_die
= nullptr;
936 int has_children
= 0;
937 bool dummy_p
= false;
940 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
941 int use_existing_cu
, int keep
);
943 struct dwarf2_per_cu_data
*m_this_cu
;
945 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
947 /* The ordinary abbreviation table. */
948 abbrev_table_up m_abbrev_table_holder
;
950 /* The DWO abbreviation table. */
951 abbrev_table_up m_dwo_abbrev_table
;
954 /* dir_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 and
956 typedef int dir_index
;
958 /* file_name_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5
960 typedef int file_name_index
;
964 file_entry () = default;
966 file_entry (const char *name_
, dir_index d_index_
,
967 unsigned int mod_time_
, unsigned int length_
)
970 mod_time (mod_time_
),
974 /* Return the include directory at D_INDEX stored in LH. Returns
975 NULL if D_INDEX is out of bounds. */
976 const char *include_dir (const line_header
*lh
) const;
978 /* The file name. Note this is an observing pointer. The memory is
979 owned by debug_line_buffer. */
982 /* The directory index (1-based). */
983 dir_index d_index
{};
985 unsigned int mod_time
{};
987 unsigned int length
{};
989 /* True if referenced by the Line Number Program. */
992 /* The associated symbol table, if any. */
993 struct symtab
*symtab
{};
996 /* The line number information for a compilation unit (found in the
997 .debug_line section) begins with a "statement program header",
998 which contains the following information. */
1005 /* Add an entry to the include directory table. */
1006 void add_include_dir (const char *include_dir
);
1008 /* Add an entry to the file name table. */
1009 void add_file_name (const char *name
, dir_index d_index
,
1010 unsigned int mod_time
, unsigned int length
);
1012 /* Return the include dir at INDEX (0-based in DWARF 5 and 1-based before).
1013 Returns NULL if INDEX is out of bounds. */
1014 const char *include_dir_at (dir_index index
) const
1020 vec_index
= index
- 1;
1021 if (vec_index
< 0 || vec_index
>= m_include_dirs
.size ())
1023 return m_include_dirs
[vec_index
];
1026 bool is_valid_file_index (int file_index
)
1029 return 0 <= file_index
&& file_index
< file_names_size ();
1030 return 1 <= file_index
&& file_index
<= file_names_size ();
1033 /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before).
1034 Returns NULL if INDEX is out of bounds. */
1035 file_entry
*file_name_at (file_name_index index
)
1041 vec_index
= index
- 1;
1042 if (vec_index
< 0 || vec_index
>= m_file_names
.size ())
1044 return &m_file_names
[vec_index
];
1047 /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
1048 this method should only be used to iterate through all file entries in an
1049 index-agnostic manner. */
1050 std::vector
<file_entry
> &file_names ()
1051 { return m_file_names
; }
1053 /* Offset of line number information in .debug_line section. */
1054 sect_offset sect_off
{};
1056 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1057 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1059 unsigned int total_length
{};
1060 unsigned short version
{};
1061 unsigned int header_length
{};
1062 unsigned char minimum_instruction_length
{};
1063 unsigned char maximum_ops_per_instruction
{};
1064 unsigned char default_is_stmt
{};
1066 unsigned char line_range
{};
1067 unsigned char opcode_base
{};
1069 /* standard_opcode_lengths[i] is the number of operands for the
1070 standard opcode whose value is i. This means that
1071 standard_opcode_lengths[0] is unused, and the last meaningful
1072 element is standard_opcode_lengths[opcode_base - 1]. */
1073 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1075 int file_names_size ()
1076 { return m_file_names
.size(); }
1078 /* The start and end of the statement program following this
1079 header. These point into dwarf2_per_objfile->line_buffer. */
1080 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1083 /* The include_directories table. Note these are observing
1084 pointers. The memory is owned by debug_line_buffer. */
1085 std::vector
<const char *> m_include_dirs
;
1087 /* The file_names table. This is private because the meaning of indexes
1088 differs among DWARF versions (The first valid index is 1 in DWARF 4 and
1089 before, and is 0 in DWARF 5 and later). So the client should use
1090 file_name_at method for access. */
1091 std::vector
<file_entry
> m_file_names
;
1094 typedef std::unique_ptr
<line_header
> line_header_up
;
1097 file_entry::include_dir (const line_header
*lh
) const
1099 return lh
->include_dir_at (d_index
);
1102 /* When we construct a partial symbol table entry we only
1103 need this much information. */
1104 struct partial_die_info
: public allocate_on_obstack
1106 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1108 /* Disable assign but still keep copy ctor, which is needed
1109 load_partial_dies. */
1110 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1112 /* Adjust the partial die before generating a symbol for it. This
1113 function may set the is_external flag or change the DIE's
1115 void fixup (struct dwarf2_cu
*cu
);
1117 /* Read a minimal amount of information into the minimal die
1119 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1120 const struct abbrev_info
&abbrev
,
1121 const gdb_byte
*info_ptr
);
1123 /* Offset of this DIE. */
1124 const sect_offset sect_off
;
1126 /* DWARF-2 tag for this DIE. */
1127 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1129 /* Assorted flags describing the data found in this DIE. */
1130 const unsigned int has_children
: 1;
1132 unsigned int is_external
: 1;
1133 unsigned int is_declaration
: 1;
1134 unsigned int has_type
: 1;
1135 unsigned int has_specification
: 1;
1136 unsigned int has_pc_info
: 1;
1137 unsigned int may_be_inlined
: 1;
1139 /* This DIE has been marked DW_AT_main_subprogram. */
1140 unsigned int main_subprogram
: 1;
1142 /* Flag set if the SCOPE field of this structure has been
1144 unsigned int scope_set
: 1;
1146 /* Flag set if the DIE has a byte_size attribute. */
1147 unsigned int has_byte_size
: 1;
1149 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1150 unsigned int has_const_value
: 1;
1152 /* Flag set if any of the DIE's children are template arguments. */
1153 unsigned int has_template_arguments
: 1;
1155 /* Flag set if fixup has been called on this die. */
1156 unsigned int fixup_called
: 1;
1158 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1159 unsigned int is_dwz
: 1;
1161 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1162 unsigned int spec_is_dwz
: 1;
1164 /* The name of this DIE. Normally the value of DW_AT_name, but
1165 sometimes a default name for unnamed DIEs. */
1166 const char *name
= nullptr;
1168 /* The linkage name, if present. */
1169 const char *linkage_name
= nullptr;
1171 /* The scope to prepend to our children. This is generally
1172 allocated on the comp_unit_obstack, so will disappear
1173 when this compilation unit leaves the cache. */
1174 const char *scope
= nullptr;
1176 /* Some data associated with the partial DIE. The tag determines
1177 which field is live. */
1180 /* The location description associated with this DIE, if any. */
1181 struct dwarf_block
*locdesc
;
1182 /* The offset of an import, for DW_TAG_imported_unit. */
1183 sect_offset sect_off
;
1186 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1187 CORE_ADDR lowpc
= 0;
1188 CORE_ADDR highpc
= 0;
1190 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1191 DW_AT_sibling, if any. */
1192 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1193 could return DW_AT_sibling values to its caller load_partial_dies. */
1194 const gdb_byte
*sibling
= nullptr;
1196 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1197 DW_AT_specification (or DW_AT_abstract_origin or
1198 DW_AT_extension). */
1199 sect_offset spec_offset
{};
1201 /* Pointers to this DIE's parent, first child, and next sibling,
1203 struct partial_die_info
*die_parent
= nullptr;
1204 struct partial_die_info
*die_child
= nullptr;
1205 struct partial_die_info
*die_sibling
= nullptr;
1207 friend struct partial_die_info
*
1208 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1211 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1212 partial_die_info (sect_offset sect_off
)
1213 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1217 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1219 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1224 has_specification
= 0;
1227 main_subprogram
= 0;
1230 has_const_value
= 0;
1231 has_template_arguments
= 0;
1238 /* This data structure holds the information of an abbrev. */
1241 unsigned int number
; /* number identifying abbrev */
1242 enum dwarf_tag tag
; /* dwarf tag */
1243 unsigned short has_children
; /* boolean */
1244 unsigned short num_attrs
; /* number of attributes */
1245 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1246 struct abbrev_info
*next
; /* next in chain */
1251 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1252 ENUM_BITFIELD(dwarf_form
) form
: 16;
1254 /* It is valid only if FORM is DW_FORM_implicit_const. */
1255 LONGEST implicit_const
;
1258 /* Size of abbrev_table.abbrev_hash_table. */
1259 #define ABBREV_HASH_SIZE 121
1261 /* Top level data structure to contain an abbreviation table. */
1265 explicit abbrev_table (sect_offset off
)
1269 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1270 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1273 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1275 /* Allocate space for a struct abbrev_info object in
1277 struct abbrev_info
*alloc_abbrev ();
1279 /* Add an abbreviation to the table. */
1280 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1282 /* Look up an abbrev in the table.
1283 Returns NULL if the abbrev is not found. */
1285 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1288 /* Where the abbrev table came from.
1289 This is used as a sanity check when the table is used. */
1290 const sect_offset sect_off
;
1292 /* Storage for the abbrev table. */
1293 auto_obstack abbrev_obstack
;
1297 /* Hash table of abbrevs.
1298 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1299 It could be statically allocated, but the previous code didn't so we
1301 struct abbrev_info
**m_abbrevs
;
1304 /* Attributes have a name and a value. */
1307 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1308 ENUM_BITFIELD(dwarf_form
) form
: 15;
1310 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1311 field should be in u.str (existing only for DW_STRING) but it is kept
1312 here for better struct attribute alignment. */
1313 unsigned int string_is_canonical
: 1;
1318 struct dwarf_block
*blk
;
1327 /* This data structure holds a complete die structure. */
1330 /* DWARF-2 tag for this DIE. */
1331 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1333 /* Number of attributes */
1334 unsigned char num_attrs
;
1336 /* True if we're presently building the full type name for the
1337 type derived from this DIE. */
1338 unsigned char building_fullname
: 1;
1340 /* True if this die is in process. PR 16581. */
1341 unsigned char in_process
: 1;
1344 unsigned int abbrev
;
1346 /* Offset in .debug_info or .debug_types section. */
1347 sect_offset sect_off
;
1349 /* The dies in a compilation unit form an n-ary tree. PARENT
1350 points to this die's parent; CHILD points to the first child of
1351 this node; and all the children of a given node are chained
1352 together via their SIBLING fields. */
1353 struct die_info
*child
; /* Its first child, if any. */
1354 struct die_info
*sibling
; /* Its next sibling, if any. */
1355 struct die_info
*parent
; /* Its parent, if any. */
1357 /* An array of attributes, with NUM_ATTRS elements. There may be
1358 zero, but it's not common and zero-sized arrays are not
1359 sufficiently portable C. */
1360 struct attribute attrs
[1];
1363 /* Get at parts of an attribute structure. */
1365 #define DW_STRING(attr) ((attr)->u.str)
1366 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1367 #define DW_UNSND(attr) ((attr)->u.unsnd)
1368 #define DW_BLOCK(attr) ((attr)->u.blk)
1369 #define DW_SND(attr) ((attr)->u.snd)
1370 #define DW_ADDR(attr) ((attr)->u.addr)
1371 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1373 /* Blocks are a bunch of untyped bytes. */
1378 /* Valid only if SIZE is not zero. */
1379 const gdb_byte
*data
;
1382 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1383 but this would require a corresponding change in unpack_field_as_long
1385 static int bits_per_byte
= 8;
1387 /* When reading a variant or variant part, we track a bit more
1388 information about the field, and store it in an object of this
1391 struct variant_field
1393 /* If we see a DW_TAG_variant, then this will be the discriminant
1395 ULONGEST discriminant_value
;
1396 /* If we see a DW_TAG_variant, then this will be set if this is the
1398 bool default_branch
;
1399 /* While reading a DW_TAG_variant_part, this will be set if this
1400 field is the discriminant. */
1401 bool is_discriminant
;
1406 int accessibility
= 0;
1408 /* Extra information to describe a variant or variant part. */
1409 struct variant_field variant
{};
1410 struct field field
{};
1415 const char *name
= nullptr;
1416 std::vector
<struct fn_field
> fnfields
;
1419 /* The routines that read and process dies for a C struct or C++ class
1420 pass lists of data member fields and lists of member function fields
1421 in an instance of a field_info structure, as defined below. */
1424 /* List of data member and baseclasses fields. */
1425 std::vector
<struct nextfield
> fields
;
1426 std::vector
<struct nextfield
> baseclasses
;
1428 /* Number of fields (including baseclasses). */
1431 /* Set if the accessibility of one of the fields is not public. */
1432 int non_public_fields
= 0;
1434 /* Member function fieldlist array, contains name of possibly overloaded
1435 member function, number of overloaded member functions and a pointer
1436 to the head of the member function field chain. */
1437 std::vector
<struct fnfieldlist
> fnfieldlists
;
1439 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1440 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1441 std::vector
<struct decl_field
> typedef_field_list
;
1443 /* Nested types defined by this class and the number of elements in this
1445 std::vector
<struct decl_field
> nested_types_list
;
1448 /* One item on the queue of compilation units to read in full symbols
1450 struct dwarf2_queue_item
1452 struct dwarf2_per_cu_data
*per_cu
;
1453 enum language pretend_language
;
1454 struct dwarf2_queue_item
*next
;
1457 /* The current queue. */
1458 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1460 /* Loaded secondary compilation units are kept in memory until they
1461 have not been referenced for the processing of this many
1462 compilation units. Set this to zero to disable caching. Cache
1463 sizes of up to at least twenty will improve startup time for
1464 typical inter-CU-reference binaries, at an obvious memory cost. */
1465 static int dwarf_max_cache_age
= 5;
1467 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1468 struct cmd_list_element
*c
, const char *value
)
1470 fprintf_filtered (file
, _("The upper bound on the age of cached "
1471 "DWARF compilation units is %s.\n"),
1475 /* local function prototypes */
1477 static const char *get_section_name (const struct dwarf2_section_info
*);
1479 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1481 static void dwarf2_find_base_address (struct die_info
*die
,
1482 struct dwarf2_cu
*cu
);
1484 static dwarf2_psymtab
*create_partial_symtab
1485 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1487 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1488 const gdb_byte
*info_ptr
,
1489 struct die_info
*type_unit_die
,
1492 static void dwarf2_build_psymtabs_hard
1493 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1495 static void scan_partial_symbols (struct partial_die_info
*,
1496 CORE_ADDR
*, CORE_ADDR
*,
1497 int, struct dwarf2_cu
*);
1499 static void add_partial_symbol (struct partial_die_info
*,
1500 struct dwarf2_cu
*);
1502 static void add_partial_namespace (struct partial_die_info
*pdi
,
1503 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1504 int set_addrmap
, struct dwarf2_cu
*cu
);
1506 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1507 CORE_ADDR
*highpc
, int set_addrmap
,
1508 struct dwarf2_cu
*cu
);
1510 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1511 struct dwarf2_cu
*cu
);
1513 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1514 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1515 int need_pc
, struct dwarf2_cu
*cu
);
1517 static abbrev_table_up abbrev_table_read_table
1518 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1521 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1523 static struct partial_die_info
*load_partial_dies
1524 (const struct die_reader_specs
*, const gdb_byte
*, int);
1526 /* A pair of partial_die_info and compilation unit. */
1527 struct cu_partial_die_info
1529 /* The compilation unit of the partial_die_info. */
1530 struct dwarf2_cu
*cu
;
1531 /* A partial_die_info. */
1532 struct partial_die_info
*pdi
;
1534 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1540 cu_partial_die_info () = delete;
1543 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1544 struct dwarf2_cu
*);
1546 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1547 struct attribute
*, struct attr_abbrev
*,
1548 const gdb_byte
*, bool *need_reprocess
);
1550 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1551 struct attribute
*attr
);
1553 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1555 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1558 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1560 static LONGEST read_checked_initial_length_and_offset
1561 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1562 unsigned int *, unsigned int *);
1564 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1565 const struct comp_unit_head
*,
1568 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1570 static sect_offset read_abbrev_offset
1571 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1572 struct dwarf2_section_info
*, sect_offset
);
1574 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1576 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1578 static const char *read_indirect_string
1579 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1580 const struct comp_unit_head
*, unsigned int *);
1582 static const char *read_indirect_line_string
1583 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1584 const struct comp_unit_head
*, unsigned int *);
1586 static const char *read_indirect_string_at_offset
1587 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1588 LONGEST str_offset
);
1590 static const char *read_indirect_string_from_dwz
1591 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1593 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1597 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1598 ULONGEST str_index
);
1600 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1601 ULONGEST str_index
);
1603 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1605 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1606 struct dwarf2_cu
*);
1608 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1611 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1612 struct dwarf2_cu
*cu
);
1614 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1616 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1617 struct dwarf2_cu
*cu
);
1619 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1621 static struct die_info
*die_specification (struct die_info
*die
,
1622 struct dwarf2_cu
**);
1624 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1625 struct dwarf2_cu
*cu
);
1627 static void dwarf_decode_lines (struct line_header
*, const char *,
1628 struct dwarf2_cu
*, dwarf2_psymtab
*,
1629 CORE_ADDR
, int decode_mapping
);
1631 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1634 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1635 struct dwarf2_cu
*, struct symbol
* = NULL
);
1637 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1638 struct dwarf2_cu
*);
1640 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1643 struct obstack
*obstack
,
1644 struct dwarf2_cu
*cu
, LONGEST
*value
,
1645 const gdb_byte
**bytes
,
1646 struct dwarf2_locexpr_baton
**baton
);
1648 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1650 static int need_gnat_info (struct dwarf2_cu
*);
1652 static struct type
*die_descriptive_type (struct die_info
*,
1653 struct dwarf2_cu
*);
1655 static void set_descriptive_type (struct type
*, struct die_info
*,
1656 struct dwarf2_cu
*);
1658 static struct type
*die_containing_type (struct die_info
*,
1659 struct dwarf2_cu
*);
1661 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1662 struct dwarf2_cu
*);
1664 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1666 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1668 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1670 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1671 const char *suffix
, int physname
,
1672 struct dwarf2_cu
*cu
);
1674 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1676 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1678 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1680 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1682 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1684 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1686 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1687 struct dwarf2_cu
*, dwarf2_psymtab
*);
1689 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1690 values. Keep the items ordered with increasing constraints compliance. */
1693 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1694 PC_BOUNDS_NOT_PRESENT
,
1696 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1697 were present but they do not form a valid range of PC addresses. */
1700 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1703 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1707 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1708 CORE_ADDR
*, CORE_ADDR
*,
1712 static void get_scope_pc_bounds (struct die_info
*,
1713 CORE_ADDR
*, CORE_ADDR
*,
1714 struct dwarf2_cu
*);
1716 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1717 CORE_ADDR
, struct dwarf2_cu
*);
1719 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1720 struct dwarf2_cu
*);
1722 static void dwarf2_attach_fields_to_type (struct field_info
*,
1723 struct type
*, struct dwarf2_cu
*);
1725 static void dwarf2_add_member_fn (struct field_info
*,
1726 struct die_info
*, struct type
*,
1727 struct dwarf2_cu
*);
1729 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1731 struct dwarf2_cu
*);
1733 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1735 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1737 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1739 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1741 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1743 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1745 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1747 static struct type
*read_module_type (struct die_info
*die
,
1748 struct dwarf2_cu
*cu
);
1750 static const char *namespace_name (struct die_info
*die
,
1751 int *is_anonymous
, struct dwarf2_cu
*);
1753 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1755 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1757 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1758 struct dwarf2_cu
*);
1760 static struct die_info
*read_die_and_siblings_1
1761 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1764 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1765 const gdb_byte
*info_ptr
,
1766 const gdb_byte
**new_info_ptr
,
1767 struct die_info
*parent
);
1769 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1770 struct die_info
**, const gdb_byte
*,
1773 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1774 struct die_info
**, const gdb_byte
*,
1777 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1779 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1782 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1784 static const char *dwarf2_full_name (const char *name
,
1785 struct die_info
*die
,
1786 struct dwarf2_cu
*cu
);
1788 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1789 struct dwarf2_cu
*cu
);
1791 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1792 struct dwarf2_cu
**);
1794 static const char *dwarf_tag_name (unsigned int);
1796 static const char *dwarf_attr_name (unsigned int);
1798 static const char *dwarf_unit_type_name (int unit_type
);
1800 static const char *dwarf_form_name (unsigned int);
1802 static const char *dwarf_bool_name (unsigned int);
1804 static const char *dwarf_type_encoding_name (unsigned int);
1806 static struct die_info
*sibling_die (struct die_info
*);
1808 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1810 static void dump_die_for_error (struct die_info
*);
1812 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1815 /*static*/ void dump_die (struct die_info
*, int max_level
);
1817 static void store_in_ref_table (struct die_info
*,
1818 struct dwarf2_cu
*);
1820 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1822 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1824 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1825 const struct attribute
*,
1826 struct dwarf2_cu
**);
1828 static struct die_info
*follow_die_ref (struct die_info
*,
1829 const struct attribute
*,
1830 struct dwarf2_cu
**);
1832 static struct die_info
*follow_die_sig (struct die_info
*,
1833 const struct attribute
*,
1834 struct dwarf2_cu
**);
1836 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1837 struct dwarf2_cu
*);
1839 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1840 const struct attribute
*,
1841 struct dwarf2_cu
*);
1843 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1845 static void read_signatured_type (struct signatured_type
*);
1847 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1848 struct die_info
*die
, struct dwarf2_cu
*cu
,
1849 struct dynamic_prop
*prop
, struct type
*type
);
1851 /* memory allocation interface */
1853 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1855 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1857 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1859 static int attr_form_is_block (const struct attribute
*);
1861 static int attr_form_is_section_offset (const struct attribute
*);
1863 static int attr_form_is_constant (const struct attribute
*);
1865 static int attr_form_is_ref (const struct attribute
*);
1867 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1868 struct dwarf2_loclist_baton
*baton
,
1869 const struct attribute
*attr
);
1871 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1873 struct dwarf2_cu
*cu
,
1876 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1877 const gdb_byte
*info_ptr
,
1878 struct abbrev_info
*abbrev
);
1880 static hashval_t
partial_die_hash (const void *item
);
1882 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1884 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1885 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1886 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1888 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1889 struct die_info
*comp_unit_die
,
1890 enum language pretend_language
);
1892 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1894 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1896 static struct type
*set_die_type (struct die_info
*, struct type
*,
1897 struct dwarf2_cu
*);
1899 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1901 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1903 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1906 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1909 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1912 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1913 struct dwarf2_per_cu_data
*);
1915 static void dwarf2_mark (struct dwarf2_cu
*);
1917 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1919 static struct type
*get_die_type_at_offset (sect_offset
,
1920 struct dwarf2_per_cu_data
*);
1922 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1924 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1925 enum language pretend_language
);
1927 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1929 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1930 static struct type
*dwarf2_per_cu_addr_sized_int_type
1931 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1932 static struct type
*dwarf2_per_cu_int_type
1933 (struct dwarf2_per_cu_data
*per_cu
, int size_in_bytes
,
1936 /* Class, the destructor of which frees all allocated queue entries. This
1937 will only have work to do if an error was thrown while processing the
1938 dwarf. If no error was thrown then the queue entries should have all
1939 been processed, and freed, as we went along. */
1941 class dwarf2_queue_guard
1944 dwarf2_queue_guard () = default;
1946 /* Free any entries remaining on the queue. There should only be
1947 entries left if we hit an error while processing the dwarf. */
1948 ~dwarf2_queue_guard ()
1950 struct dwarf2_queue_item
*item
, *last
;
1952 item
= dwarf2_queue
;
1955 /* Anything still marked queued is likely to be in an
1956 inconsistent state, so discard it. */
1957 if (item
->per_cu
->queued
)
1959 if (item
->per_cu
->cu
!= NULL
)
1960 free_one_cached_comp_unit (item
->per_cu
);
1961 item
->per_cu
->queued
= 0;
1969 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1973 /* The return type of find_file_and_directory. Note, the enclosed
1974 string pointers are only valid while this object is valid. */
1976 struct file_and_directory
1978 /* The filename. This is never NULL. */
1981 /* The compilation directory. NULL if not known. If we needed to
1982 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1983 points directly to the DW_AT_comp_dir string attribute owned by
1984 the obstack that owns the DIE. */
1985 const char *comp_dir
;
1987 /* If we needed to build a new string for comp_dir, this is what
1988 owns the storage. */
1989 std::string comp_dir_storage
;
1992 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1993 struct dwarf2_cu
*cu
);
1995 static char *file_full_name (int file
, struct line_header
*lh
,
1996 const char *comp_dir
);
1998 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1999 enum class rcuh_kind
{ COMPILE
, TYPE
};
2001 static const gdb_byte
*read_and_check_comp_unit_head
2002 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
2003 struct comp_unit_head
*header
,
2004 struct dwarf2_section_info
*section
,
2005 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
2006 rcuh_kind section_kind
);
2008 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2010 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2012 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2013 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2014 struct dwp_file
*dwp_file
, const char *comp_dir
,
2015 ULONGEST signature
, int is_debug_types
);
2017 static struct dwp_file
*get_dwp_file
2018 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2020 static struct dwo_unit
*lookup_dwo_comp_unit
2021 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2023 static struct dwo_unit
*lookup_dwo_type_unit
2024 (struct signatured_type
*, const char *, const char *);
2026 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2028 /* A unique pointer to a dwo_file. */
2030 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
2032 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2034 static void check_producer (struct dwarf2_cu
*cu
);
2036 static void free_line_header_voidp (void *arg
);
2038 /* Various complaints about symbol reading that don't abort the process. */
2041 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2043 complaint (_("statement list doesn't fit in .debug_line section"));
2047 dwarf2_debug_line_missing_file_complaint (void)
2049 complaint (_(".debug_line section has line data without a file"));
2053 dwarf2_debug_line_missing_end_sequence_complaint (void)
2055 complaint (_(".debug_line section has line "
2056 "program sequence without an end"));
2060 dwarf2_complex_location_expr_complaint (void)
2062 complaint (_("location expression too complex"));
2066 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2069 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
2074 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2076 complaint (_("debug info runs off end of %s section"
2078 get_section_name (section
),
2079 get_section_file_name (section
));
2083 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2085 complaint (_("macro debug info contains a "
2086 "malformed macro definition:\n`%s'"),
2091 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2093 complaint (_("invalid attribute class or form for '%s' in '%s'"),
2097 /* Hash function for line_header_hash. */
2100 line_header_hash (const struct line_header
*ofs
)
2102 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2105 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2108 line_header_hash_voidp (const void *item
)
2110 const struct line_header
*ofs
= (const struct line_header
*) item
;
2112 return line_header_hash (ofs
);
2115 /* Equality function for line_header_hash. */
2118 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2120 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2121 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2123 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2124 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2129 /* Read the given attribute value as an address, taking the attribute's
2130 form into account. */
2133 attr_value_as_address (struct attribute
*attr
)
2137 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_addrx
2138 && attr
->form
!= DW_FORM_GNU_addr_index
)
2140 /* Aside from a few clearly defined exceptions, attributes that
2141 contain an address must always be in DW_FORM_addr form.
2142 Unfortunately, some compilers happen to be violating this
2143 requirement by encoding addresses using other forms, such
2144 as DW_FORM_data4 for example. For those broken compilers,
2145 we try to do our best, without any guarantee of success,
2146 to interpret the address correctly. It would also be nice
2147 to generate a complaint, but that would require us to maintain
2148 a list of legitimate cases where a non-address form is allowed,
2149 as well as update callers to pass in at least the CU's DWARF
2150 version. This is more overhead than what we're willing to
2151 expand for a pretty rare case. */
2152 addr
= DW_UNSND (attr
);
2155 addr
= DW_ADDR (attr
);
2160 /* See declaration. */
2162 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2163 const dwarf2_debug_sections
*names
,
2165 : objfile (objfile_
),
2166 can_copy (can_copy_
)
2169 names
= &dwarf2_elf_names
;
2171 bfd
*obfd
= objfile
->obfd
;
2173 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2174 locate_sections (obfd
, sec
, *names
);
2177 dwarf2_per_objfile::~dwarf2_per_objfile ()
2179 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2180 free_cached_comp_units ();
2182 if (quick_file_names_table
)
2183 htab_delete (quick_file_names_table
);
2185 if (line_header_hash
)
2186 htab_delete (line_header_hash
);
2188 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2189 per_cu
->imported_symtabs_free ();
2191 for (signatured_type
*sig_type
: all_type_units
)
2192 sig_type
->per_cu
.imported_symtabs_free ();
2194 /* Everything else should be on the objfile obstack. */
2197 /* See declaration. */
2200 dwarf2_per_objfile::free_cached_comp_units ()
2202 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2203 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2204 while (per_cu
!= NULL
)
2206 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2209 *last_chain
= next_cu
;
2214 /* A helper class that calls free_cached_comp_units on
2217 class free_cached_comp_units
2221 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2222 : m_per_objfile (per_objfile
)
2226 ~free_cached_comp_units ()
2228 m_per_objfile
->free_cached_comp_units ();
2231 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2235 dwarf2_per_objfile
*m_per_objfile
;
2238 /* Try to locate the sections we need for DWARF 2 debugging
2239 information and return true if we have enough to do something.
2240 NAMES points to the dwarf2 section names, or is NULL if the standard
2241 ELF names are used. CAN_COPY is true for formats where symbol
2242 interposition is possible and so symbol values must follow copy
2243 relocation rules. */
2246 dwarf2_has_info (struct objfile
*objfile
,
2247 const struct dwarf2_debug_sections
*names
,
2250 if (objfile
->flags
& OBJF_READNEVER
)
2253 struct dwarf2_per_objfile
*dwarf2_per_objfile
2254 = get_dwarf2_per_objfile (objfile
);
2256 if (dwarf2_per_objfile
== NULL
)
2257 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2261 return (!dwarf2_per_objfile
->info
.is_virtual
2262 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2263 && !dwarf2_per_objfile
->abbrev
.is_virtual
2264 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2267 /* Return the containing section of virtual section SECTION. */
2269 static struct dwarf2_section_info
*
2270 get_containing_section (const struct dwarf2_section_info
*section
)
2272 gdb_assert (section
->is_virtual
);
2273 return section
->s
.containing_section
;
2276 /* Return the bfd owner of SECTION. */
2279 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2281 if (section
->is_virtual
)
2283 section
= get_containing_section (section
);
2284 gdb_assert (!section
->is_virtual
);
2286 return section
->s
.section
->owner
;
2289 /* Return the bfd section of SECTION.
2290 Returns NULL if the section is not present. */
2293 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2295 if (section
->is_virtual
)
2297 section
= get_containing_section (section
);
2298 gdb_assert (!section
->is_virtual
);
2300 return section
->s
.section
;
2303 /* Return the name of SECTION. */
2306 get_section_name (const struct dwarf2_section_info
*section
)
2308 asection
*sectp
= get_section_bfd_section (section
);
2310 gdb_assert (sectp
!= NULL
);
2311 return bfd_section_name (sectp
);
2314 /* Return the name of the file SECTION is in. */
2317 get_section_file_name (const struct dwarf2_section_info
*section
)
2319 bfd
*abfd
= get_section_bfd_owner (section
);
2321 return bfd_get_filename (abfd
);
2324 /* Return the id of SECTION.
2325 Returns 0 if SECTION doesn't exist. */
2328 get_section_id (const struct dwarf2_section_info
*section
)
2330 asection
*sectp
= get_section_bfd_section (section
);
2337 /* Return the flags of SECTION.
2338 SECTION (or containing section if this is a virtual section) must exist. */
2341 get_section_flags (const struct dwarf2_section_info
*section
)
2343 asection
*sectp
= get_section_bfd_section (section
);
2345 gdb_assert (sectp
!= NULL
);
2346 return bfd_section_flags (sectp
);
2349 /* When loading sections, we look either for uncompressed section or for
2350 compressed section names. */
2353 section_is_p (const char *section_name
,
2354 const struct dwarf2_section_names
*names
)
2356 if (names
->normal
!= NULL
2357 && strcmp (section_name
, names
->normal
) == 0)
2359 if (names
->compressed
!= NULL
2360 && strcmp (section_name
, names
->compressed
) == 0)
2365 /* See declaration. */
2368 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2369 const dwarf2_debug_sections
&names
)
2371 flagword aflag
= bfd_section_flags (sectp
);
2373 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2376 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2377 > bfd_get_file_size (abfd
))
2379 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2380 warning (_("Discarding section %s which has a section size (%s"
2381 ") larger than the file size [in module %s]"),
2382 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2383 bfd_get_filename (abfd
));
2385 else if (section_is_p (sectp
->name
, &names
.info
))
2387 this->info
.s
.section
= sectp
;
2388 this->info
.size
= bfd_section_size (sectp
);
2390 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2392 this->abbrev
.s
.section
= sectp
;
2393 this->abbrev
.size
= bfd_section_size (sectp
);
2395 else if (section_is_p (sectp
->name
, &names
.line
))
2397 this->line
.s
.section
= sectp
;
2398 this->line
.size
= bfd_section_size (sectp
);
2400 else if (section_is_p (sectp
->name
, &names
.loc
))
2402 this->loc
.s
.section
= sectp
;
2403 this->loc
.size
= bfd_section_size (sectp
);
2405 else if (section_is_p (sectp
->name
, &names
.loclists
))
2407 this->loclists
.s
.section
= sectp
;
2408 this->loclists
.size
= bfd_section_size (sectp
);
2410 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2412 this->macinfo
.s
.section
= sectp
;
2413 this->macinfo
.size
= bfd_section_size (sectp
);
2415 else if (section_is_p (sectp
->name
, &names
.macro
))
2417 this->macro
.s
.section
= sectp
;
2418 this->macro
.size
= bfd_section_size (sectp
);
2420 else if (section_is_p (sectp
->name
, &names
.str
))
2422 this->str
.s
.section
= sectp
;
2423 this->str
.size
= bfd_section_size (sectp
);
2425 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
2427 this->str_offsets
.s
.section
= sectp
;
2428 this->str_offsets
.size
= bfd_section_size (sectp
);
2430 else if (section_is_p (sectp
->name
, &names
.line_str
))
2432 this->line_str
.s
.section
= sectp
;
2433 this->line_str
.size
= bfd_section_size (sectp
);
2435 else if (section_is_p (sectp
->name
, &names
.addr
))
2437 this->addr
.s
.section
= sectp
;
2438 this->addr
.size
= bfd_section_size (sectp
);
2440 else if (section_is_p (sectp
->name
, &names
.frame
))
2442 this->frame
.s
.section
= sectp
;
2443 this->frame
.size
= bfd_section_size (sectp
);
2445 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2447 this->eh_frame
.s
.section
= sectp
;
2448 this->eh_frame
.size
= bfd_section_size (sectp
);
2450 else if (section_is_p (sectp
->name
, &names
.ranges
))
2452 this->ranges
.s
.section
= sectp
;
2453 this->ranges
.size
= bfd_section_size (sectp
);
2455 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2457 this->rnglists
.s
.section
= sectp
;
2458 this->rnglists
.size
= bfd_section_size (sectp
);
2460 else if (section_is_p (sectp
->name
, &names
.types
))
2462 struct dwarf2_section_info type_section
;
2464 memset (&type_section
, 0, sizeof (type_section
));
2465 type_section
.s
.section
= sectp
;
2466 type_section
.size
= bfd_section_size (sectp
);
2468 this->types
.push_back (type_section
);
2470 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2472 this->gdb_index
.s
.section
= sectp
;
2473 this->gdb_index
.size
= bfd_section_size (sectp
);
2475 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2477 this->debug_names
.s
.section
= sectp
;
2478 this->debug_names
.size
= bfd_section_size (sectp
);
2480 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2482 this->debug_aranges
.s
.section
= sectp
;
2483 this->debug_aranges
.size
= bfd_section_size (sectp
);
2486 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2487 && bfd_section_vma (sectp
) == 0)
2488 this->has_section_at_zero
= true;
2491 /* A helper function that decides whether a section is empty,
2495 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2497 if (section
->is_virtual
)
2498 return section
->size
== 0;
2499 return section
->s
.section
== NULL
|| section
->size
== 0;
2502 /* See dwarf2read.h. */
2505 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2509 gdb_byte
*buf
, *retbuf
;
2513 info
->buffer
= NULL
;
2514 info
->readin
= true;
2516 if (dwarf2_section_empty_p (info
))
2519 sectp
= get_section_bfd_section (info
);
2521 /* If this is a virtual section we need to read in the real one first. */
2522 if (info
->is_virtual
)
2524 struct dwarf2_section_info
*containing_section
=
2525 get_containing_section (info
);
2527 gdb_assert (sectp
!= NULL
);
2528 if ((sectp
->flags
& SEC_RELOC
) != 0)
2530 error (_("Dwarf Error: DWP format V2 with relocations is not"
2531 " supported in section %s [in module %s]"),
2532 get_section_name (info
), get_section_file_name (info
));
2534 dwarf2_read_section (objfile
, containing_section
);
2535 /* Other code should have already caught virtual sections that don't
2537 gdb_assert (info
->virtual_offset
+ info
->size
2538 <= containing_section
->size
);
2539 /* If the real section is empty or there was a problem reading the
2540 section we shouldn't get here. */
2541 gdb_assert (containing_section
->buffer
!= NULL
);
2542 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2546 /* If the section has relocations, we must read it ourselves.
2547 Otherwise we attach it to the BFD. */
2548 if ((sectp
->flags
& SEC_RELOC
) == 0)
2550 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2554 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2557 /* When debugging .o files, we may need to apply relocations; see
2558 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2559 We never compress sections in .o files, so we only need to
2560 try this when the section is not compressed. */
2561 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2564 info
->buffer
= retbuf
;
2568 abfd
= get_section_bfd_owner (info
);
2569 gdb_assert (abfd
!= NULL
);
2571 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2572 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2574 error (_("Dwarf Error: Can't read DWARF data"
2575 " in section %s [in module %s]"),
2576 bfd_section_name (sectp
), bfd_get_filename (abfd
));
2580 /* A helper function that returns the size of a section in a safe way.
2581 If you are positive that the section has been read before using the
2582 size, then it is safe to refer to the dwarf2_section_info object's
2583 "size" field directly. In other cases, you must call this
2584 function, because for compressed sections the size field is not set
2585 correctly until the section has been read. */
2587 static bfd_size_type
2588 dwarf2_section_size (struct objfile
*objfile
,
2589 struct dwarf2_section_info
*info
)
2592 dwarf2_read_section (objfile
, info
);
2596 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2600 dwarf2_get_section_info (struct objfile
*objfile
,
2601 enum dwarf2_section_enum sect
,
2602 asection
**sectp
, const gdb_byte
**bufp
,
2603 bfd_size_type
*sizep
)
2605 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2606 struct dwarf2_section_info
*info
;
2608 /* We may see an objfile without any DWARF, in which case we just
2619 case DWARF2_DEBUG_FRAME
:
2620 info
= &data
->frame
;
2622 case DWARF2_EH_FRAME
:
2623 info
= &data
->eh_frame
;
2626 gdb_assert_not_reached ("unexpected section");
2629 dwarf2_read_section (objfile
, info
);
2631 *sectp
= get_section_bfd_section (info
);
2632 *bufp
= info
->buffer
;
2633 *sizep
= info
->size
;
2636 /* A helper function to find the sections for a .dwz file. */
2639 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2641 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2643 /* Note that we only support the standard ELF names, because .dwz
2644 is ELF-only (at the time of writing). */
2645 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2647 dwz_file
->abbrev
.s
.section
= sectp
;
2648 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2650 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2652 dwz_file
->info
.s
.section
= sectp
;
2653 dwz_file
->info
.size
= bfd_section_size (sectp
);
2655 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2657 dwz_file
->str
.s
.section
= sectp
;
2658 dwz_file
->str
.size
= bfd_section_size (sectp
);
2660 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2662 dwz_file
->line
.s
.section
= sectp
;
2663 dwz_file
->line
.size
= bfd_section_size (sectp
);
2665 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2667 dwz_file
->macro
.s
.section
= sectp
;
2668 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2670 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2672 dwz_file
->gdb_index
.s
.section
= sectp
;
2673 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2675 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2677 dwz_file
->debug_names
.s
.section
= sectp
;
2678 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2682 /* See dwarf2read.h. */
2685 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2687 const char *filename
;
2688 bfd_size_type buildid_len_arg
;
2692 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2693 return dwarf2_per_objfile
->dwz_file
.get ();
2695 bfd_set_error (bfd_error_no_error
);
2696 gdb::unique_xmalloc_ptr
<char> data
2697 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2698 &buildid_len_arg
, &buildid
));
2701 if (bfd_get_error () == bfd_error_no_error
)
2703 error (_("could not read '.gnu_debugaltlink' section: %s"),
2704 bfd_errmsg (bfd_get_error ()));
2707 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2709 buildid_len
= (size_t) buildid_len_arg
;
2711 filename
= data
.get ();
2713 std::string abs_storage
;
2714 if (!IS_ABSOLUTE_PATH (filename
))
2716 gdb::unique_xmalloc_ptr
<char> abs
2717 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2719 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2720 filename
= abs_storage
.c_str ();
2723 /* First try the file name given in the section. If that doesn't
2724 work, try to use the build-id instead. */
2725 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2726 if (dwz_bfd
!= NULL
)
2728 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2729 dwz_bfd
.reset (nullptr);
2732 if (dwz_bfd
== NULL
)
2733 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2735 if (dwz_bfd
== NULL
)
2736 error (_("could not find '.gnu_debugaltlink' file for %s"),
2737 objfile_name (dwarf2_per_objfile
->objfile
));
2739 std::unique_ptr
<struct dwz_file
> result
2740 (new struct dwz_file (std::move (dwz_bfd
)));
2742 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2745 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2746 result
->dwz_bfd
.get ());
2747 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2748 return dwarf2_per_objfile
->dwz_file
.get ();
2751 /* DWARF quick_symbols_functions support. */
2753 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2754 unique line tables, so we maintain a separate table of all .debug_line
2755 derived entries to support the sharing.
2756 All the quick functions need is the list of file names. We discard the
2757 line_header when we're done and don't need to record it here. */
2758 struct quick_file_names
2760 /* The data used to construct the hash key. */
2761 struct stmt_list_hash hash
;
2763 /* The number of entries in file_names, real_names. */
2764 unsigned int num_file_names
;
2766 /* The file names from the line table, after being run through
2768 const char **file_names
;
2770 /* The file names from the line table after being run through
2771 gdb_realpath. These are computed lazily. */
2772 const char **real_names
;
2775 /* When using the index (and thus not using psymtabs), each CU has an
2776 object of this type. This is used to hold information needed by
2777 the various "quick" methods. */
2778 struct dwarf2_per_cu_quick_data
2780 /* The file table. This can be NULL if there was no file table
2781 or it's currently not read in.
2782 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2783 struct quick_file_names
*file_names
;
2785 /* The corresponding symbol table. This is NULL if symbols for this
2786 CU have not yet been read. */
2787 struct compunit_symtab
*compunit_symtab
;
2789 /* A temporary mark bit used when iterating over all CUs in
2790 expand_symtabs_matching. */
2791 unsigned int mark
: 1;
2793 /* True if we've tried to read the file table and found there isn't one.
2794 There will be no point in trying to read it again next time. */
2795 unsigned int no_file_data
: 1;
2798 /* Utility hash function for a stmt_list_hash. */
2801 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2805 if (stmt_list_hash
->dwo_unit
!= NULL
)
2806 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2807 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2811 /* Utility equality function for a stmt_list_hash. */
2814 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2815 const struct stmt_list_hash
*rhs
)
2817 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2819 if (lhs
->dwo_unit
!= NULL
2820 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2823 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2826 /* Hash function for a quick_file_names. */
2829 hash_file_name_entry (const void *e
)
2831 const struct quick_file_names
*file_data
2832 = (const struct quick_file_names
*) e
;
2834 return hash_stmt_list_entry (&file_data
->hash
);
2837 /* Equality function for a quick_file_names. */
2840 eq_file_name_entry (const void *a
, const void *b
)
2842 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2843 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2845 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2848 /* Delete function for a quick_file_names. */
2851 delete_file_name_entry (void *e
)
2853 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2856 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2858 xfree ((void*) file_data
->file_names
[i
]);
2859 if (file_data
->real_names
)
2860 xfree ((void*) file_data
->real_names
[i
]);
2863 /* The space for the struct itself lives on objfile_obstack,
2864 so we don't free it here. */
2867 /* Create a quick_file_names hash table. */
2870 create_quick_file_names_table (unsigned int nr_initial_entries
)
2872 return htab_create_alloc (nr_initial_entries
,
2873 hash_file_name_entry
, eq_file_name_entry
,
2874 delete_file_name_entry
, xcalloc
, xfree
);
2877 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2878 have to be created afterwards. You should call age_cached_comp_units after
2879 processing PER_CU->CU. dw2_setup must have been already called. */
2882 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2884 if (per_cu
->is_debug_types
)
2885 load_full_type_unit (per_cu
);
2887 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2889 if (per_cu
->cu
== NULL
)
2890 return; /* Dummy CU. */
2892 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2895 /* Read in the symbols for PER_CU. */
2898 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2900 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2902 /* Skip type_unit_groups, reading the type units they contain
2903 is handled elsewhere. */
2904 if (IS_TYPE_UNIT_GROUP (per_cu
))
2907 /* The destructor of dwarf2_queue_guard frees any entries left on
2908 the queue. After this point we're guaranteed to leave this function
2909 with the dwarf queue empty. */
2910 dwarf2_queue_guard q_guard
;
2912 if (dwarf2_per_objfile
->using_index
2913 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2914 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2916 queue_comp_unit (per_cu
, language_minimal
);
2917 load_cu (per_cu
, skip_partial
);
2919 /* If we just loaded a CU from a DWO, and we're working with an index
2920 that may badly handle TUs, load all the TUs in that DWO as well.
2921 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2922 if (!per_cu
->is_debug_types
2923 && per_cu
->cu
!= NULL
2924 && per_cu
->cu
->dwo_unit
!= NULL
2925 && dwarf2_per_objfile
->index_table
!= NULL
2926 && dwarf2_per_objfile
->index_table
->version
<= 7
2927 /* DWP files aren't supported yet. */
2928 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2929 queue_and_load_all_dwo_tus (per_cu
);
2932 process_queue (dwarf2_per_objfile
);
2934 /* Age the cache, releasing compilation units that have not
2935 been used recently. */
2936 age_cached_comp_units (dwarf2_per_objfile
);
2939 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2940 the objfile from which this CU came. Returns the resulting symbol
2943 static struct compunit_symtab
*
2944 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2946 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2948 gdb_assert (dwarf2_per_objfile
->using_index
);
2949 if (!per_cu
->v
.quick
->compunit_symtab
)
2951 free_cached_comp_units
freer (dwarf2_per_objfile
);
2952 scoped_restore decrementer
= increment_reading_symtab ();
2953 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2954 process_cu_includes (dwarf2_per_objfile
);
2957 return per_cu
->v
.quick
->compunit_symtab
;
2960 /* See declaration. */
2962 dwarf2_per_cu_data
*
2963 dwarf2_per_objfile::get_cutu (int index
)
2965 if (index
>= this->all_comp_units
.size ())
2967 index
-= this->all_comp_units
.size ();
2968 gdb_assert (index
< this->all_type_units
.size ());
2969 return &this->all_type_units
[index
]->per_cu
;
2972 return this->all_comp_units
[index
];
2975 /* See declaration. */
2977 dwarf2_per_cu_data
*
2978 dwarf2_per_objfile::get_cu (int index
)
2980 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2982 return this->all_comp_units
[index
];
2985 /* See declaration. */
2988 dwarf2_per_objfile::get_tu (int index
)
2990 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2992 return this->all_type_units
[index
];
2995 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2996 objfile_obstack, and constructed with the specified field
2999 static dwarf2_per_cu_data
*
3000 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3001 struct dwarf2_section_info
*section
,
3003 sect_offset sect_off
, ULONGEST length
)
3005 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3006 dwarf2_per_cu_data
*the_cu
3007 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3008 struct dwarf2_per_cu_data
);
3009 the_cu
->sect_off
= sect_off
;
3010 the_cu
->length
= length
;
3011 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3012 the_cu
->section
= section
;
3013 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3014 struct dwarf2_per_cu_quick_data
);
3015 the_cu
->is_dwz
= is_dwz
;
3019 /* A helper for create_cus_from_index that handles a given list of
3023 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3024 const gdb_byte
*cu_list
, offset_type n_elements
,
3025 struct dwarf2_section_info
*section
,
3028 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
3030 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3032 sect_offset sect_off
3033 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3034 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3037 dwarf2_per_cu_data
*per_cu
3038 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3040 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
3044 /* Read the CU list from the mapped index, and use it to create all
3045 the CU objects for this objfile. */
3048 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3049 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3050 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3052 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3053 dwarf2_per_objfile
->all_comp_units
.reserve
3054 ((cu_list_elements
+ dwz_elements
) / 2);
3056 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3057 &dwarf2_per_objfile
->info
, 0);
3059 if (dwz_elements
== 0)
3062 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3063 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3067 /* Create the signatured type hash table from the index. */
3070 create_signatured_type_table_from_index
3071 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3072 struct dwarf2_section_info
*section
,
3073 const gdb_byte
*bytes
,
3074 offset_type elements
)
3076 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3078 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3079 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3081 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3083 for (offset_type i
= 0; i
< elements
; i
+= 3)
3085 struct signatured_type
*sig_type
;
3088 cu_offset type_offset_in_tu
;
3090 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3091 sect_offset sect_off
3092 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3094 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3096 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3099 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3100 struct signatured_type
);
3101 sig_type
->signature
= signature
;
3102 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3103 sig_type
->per_cu
.is_debug_types
= 1;
3104 sig_type
->per_cu
.section
= section
;
3105 sig_type
->per_cu
.sect_off
= sect_off
;
3106 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3107 sig_type
->per_cu
.v
.quick
3108 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3109 struct dwarf2_per_cu_quick_data
);
3111 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3114 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3117 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3120 /* Create the signatured type hash table from .debug_names. */
3123 create_signatured_type_table_from_debug_names
3124 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3125 const mapped_debug_names
&map
,
3126 struct dwarf2_section_info
*section
,
3127 struct dwarf2_section_info
*abbrev_section
)
3129 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3131 dwarf2_read_section (objfile
, section
);
3132 dwarf2_read_section (objfile
, abbrev_section
);
3134 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3135 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3137 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3139 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3141 struct signatured_type
*sig_type
;
3144 sect_offset sect_off
3145 = (sect_offset
) (extract_unsigned_integer
3146 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3148 map
.dwarf5_byte_order
));
3150 comp_unit_head cu_header
;
3151 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3153 section
->buffer
+ to_underlying (sect_off
),
3156 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3157 struct signatured_type
);
3158 sig_type
->signature
= cu_header
.signature
;
3159 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3160 sig_type
->per_cu
.is_debug_types
= 1;
3161 sig_type
->per_cu
.section
= section
;
3162 sig_type
->per_cu
.sect_off
= sect_off
;
3163 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3164 sig_type
->per_cu
.v
.quick
3165 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3166 struct dwarf2_per_cu_quick_data
);
3168 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3171 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3174 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3177 /* Read the address map data from the mapped index, and use it to
3178 populate the objfile's psymtabs_addrmap. */
3181 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3182 struct mapped_index
*index
)
3184 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3185 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3186 const gdb_byte
*iter
, *end
;
3187 struct addrmap
*mutable_map
;
3190 auto_obstack temp_obstack
;
3192 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3194 iter
= index
->address_table
.data ();
3195 end
= iter
+ index
->address_table
.size ();
3197 baseaddr
= objfile
->text_section_offset ();
3201 ULONGEST hi
, lo
, cu_index
;
3202 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3204 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3206 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3211 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
3212 hex_string (lo
), hex_string (hi
));
3216 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3218 complaint (_(".gdb_index address table has invalid CU number %u"),
3219 (unsigned) cu_index
);
3223 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
3224 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
3225 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3226 dwarf2_per_objfile
->get_cu (cu_index
));
3229 objfile
->partial_symtabs
->psymtabs_addrmap
3230 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3233 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3234 populate the objfile's psymtabs_addrmap. */
3237 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3238 struct dwarf2_section_info
*section
)
3240 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3241 bfd
*abfd
= objfile
->obfd
;
3242 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3243 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
3245 auto_obstack temp_obstack
;
3246 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3248 std::unordered_map
<sect_offset
,
3249 dwarf2_per_cu_data
*,
3250 gdb::hash_enum
<sect_offset
>>
3251 debug_info_offset_to_per_cu
;
3252 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3254 const auto insertpair
3255 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3256 if (!insertpair
.second
)
3258 warning (_("Section .debug_aranges in %s has duplicate "
3259 "debug_info_offset %s, ignoring .debug_aranges."),
3260 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3265 dwarf2_read_section (objfile
, section
);
3267 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3269 const gdb_byte
*addr
= section
->buffer
;
3271 while (addr
< section
->buffer
+ section
->size
)
3273 const gdb_byte
*const entry_addr
= addr
;
3274 unsigned int bytes_read
;
3276 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3280 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3281 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3282 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3283 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3285 warning (_("Section .debug_aranges in %s entry at offset %s "
3286 "length %s exceeds section length %s, "
3287 "ignoring .debug_aranges."),
3288 objfile_name (objfile
),
3289 plongest (entry_addr
- section
->buffer
),
3290 plongest (bytes_read
+ entry_length
),
3291 pulongest (section
->size
));
3295 /* The version number. */
3296 const uint16_t version
= read_2_bytes (abfd
, addr
);
3300 warning (_("Section .debug_aranges in %s entry at offset %s "
3301 "has unsupported version %d, ignoring .debug_aranges."),
3302 objfile_name (objfile
),
3303 plongest (entry_addr
- section
->buffer
), version
);
3307 const uint64_t debug_info_offset
3308 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3309 addr
+= offset_size
;
3310 const auto per_cu_it
3311 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3312 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3314 warning (_("Section .debug_aranges in %s entry at offset %s "
3315 "debug_info_offset %s does not exists, "
3316 "ignoring .debug_aranges."),
3317 objfile_name (objfile
),
3318 plongest (entry_addr
- section
->buffer
),
3319 pulongest (debug_info_offset
));
3322 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3324 const uint8_t address_size
= *addr
++;
3325 if (address_size
< 1 || address_size
> 8)
3327 warning (_("Section .debug_aranges in %s entry at offset %s "
3328 "address_size %u is invalid, ignoring .debug_aranges."),
3329 objfile_name (objfile
),
3330 plongest (entry_addr
- section
->buffer
), address_size
);
3334 const uint8_t segment_selector_size
= *addr
++;
3335 if (segment_selector_size
!= 0)
3337 warning (_("Section .debug_aranges in %s entry at offset %s "
3338 "segment_selector_size %u is not supported, "
3339 "ignoring .debug_aranges."),
3340 objfile_name (objfile
),
3341 plongest (entry_addr
- section
->buffer
),
3342 segment_selector_size
);
3346 /* Must pad to an alignment boundary that is twice the address
3347 size. It is undocumented by the DWARF standard but GCC does
3349 for (size_t padding
= ((-(addr
- section
->buffer
))
3350 & (2 * address_size
- 1));
3351 padding
> 0; padding
--)
3354 warning (_("Section .debug_aranges in %s entry at offset %s "
3355 "padding is not zero, ignoring .debug_aranges."),
3356 objfile_name (objfile
),
3357 plongest (entry_addr
- section
->buffer
));
3363 if (addr
+ 2 * address_size
> entry_end
)
3365 warning (_("Section .debug_aranges in %s entry at offset %s "
3366 "address list is not properly terminated, "
3367 "ignoring .debug_aranges."),
3368 objfile_name (objfile
),
3369 plongest (entry_addr
- section
->buffer
));
3372 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3374 addr
+= address_size
;
3375 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3377 addr
+= address_size
;
3378 if (start
== 0 && length
== 0)
3380 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3382 /* Symbol was eliminated due to a COMDAT group. */
3385 ULONGEST end
= start
+ length
;
3386 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3388 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3390 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3394 objfile
->partial_symtabs
->psymtabs_addrmap
3395 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3398 /* Find a slot in the mapped index INDEX for the object named NAME.
3399 If NAME is found, set *VEC_OUT to point to the CU vector in the
3400 constant pool and return true. If NAME cannot be found, return
3404 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3405 offset_type
**vec_out
)
3408 offset_type slot
, step
;
3409 int (*cmp
) (const char *, const char *);
3411 gdb::unique_xmalloc_ptr
<char> without_params
;
3412 if (current_language
->la_language
== language_cplus
3413 || current_language
->la_language
== language_fortran
3414 || current_language
->la_language
== language_d
)
3416 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3419 if (strchr (name
, '(') != NULL
)
3421 without_params
= cp_remove_params (name
);
3423 if (without_params
!= NULL
)
3424 name
= without_params
.get ();
3428 /* Index version 4 did not support case insensitive searches. But the
3429 indices for case insensitive languages are built in lowercase, therefore
3430 simulate our NAME being searched is also lowercased. */
3431 hash
= mapped_index_string_hash ((index
->version
== 4
3432 && case_sensitivity
== case_sensitive_off
3433 ? 5 : index
->version
),
3436 slot
= hash
& (index
->symbol_table
.size () - 1);
3437 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3438 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3444 const auto &bucket
= index
->symbol_table
[slot
];
3445 if (bucket
.name
== 0 && bucket
.vec
== 0)
3448 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3449 if (!cmp (name
, str
))
3451 *vec_out
= (offset_type
*) (index
->constant_pool
3452 + MAYBE_SWAP (bucket
.vec
));
3456 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3460 /* A helper function that reads the .gdb_index from BUFFER and fills
3461 in MAP. FILENAME is the name of the file containing the data;
3462 it is used for error reporting. DEPRECATED_OK is true if it is
3463 ok to use deprecated sections.
3465 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3466 out parameters that are filled in with information about the CU and
3467 TU lists in the section.
3469 Returns true if all went well, false otherwise. */
3472 read_gdb_index_from_buffer (struct objfile
*objfile
,
3473 const char *filename
,
3475 gdb::array_view
<const gdb_byte
> buffer
,
3476 struct mapped_index
*map
,
3477 const gdb_byte
**cu_list
,
3478 offset_type
*cu_list_elements
,
3479 const gdb_byte
**types_list
,
3480 offset_type
*types_list_elements
)
3482 const gdb_byte
*addr
= &buffer
[0];
3484 /* Version check. */
3485 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3486 /* Versions earlier than 3 emitted every copy of a psymbol. This
3487 causes the index to behave very poorly for certain requests. Version 3
3488 contained incomplete addrmap. So, it seems better to just ignore such
3492 static int warning_printed
= 0;
3493 if (!warning_printed
)
3495 warning (_("Skipping obsolete .gdb_index section in %s."),
3497 warning_printed
= 1;
3501 /* Index version 4 uses a different hash function than index version
3504 Versions earlier than 6 did not emit psymbols for inlined
3505 functions. Using these files will cause GDB not to be able to
3506 set breakpoints on inlined functions by name, so we ignore these
3507 indices unless the user has done
3508 "set use-deprecated-index-sections on". */
3509 if (version
< 6 && !deprecated_ok
)
3511 static int warning_printed
= 0;
3512 if (!warning_printed
)
3515 Skipping deprecated .gdb_index section in %s.\n\
3516 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3517 to use the section anyway."),
3519 warning_printed
= 1;
3523 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3524 of the TU (for symbols coming from TUs),
3525 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3526 Plus gold-generated indices can have duplicate entries for global symbols,
3527 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3528 These are just performance bugs, and we can't distinguish gdb-generated
3529 indices from gold-generated ones, so issue no warning here. */
3531 /* Indexes with higher version than the one supported by GDB may be no
3532 longer backward compatible. */
3536 map
->version
= version
;
3538 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3541 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3542 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3546 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3547 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3548 - MAYBE_SWAP (metadata
[i
]))
3552 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3553 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3555 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3558 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3559 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3561 = gdb::array_view
<mapped_index::symbol_table_slot
>
3562 ((mapped_index::symbol_table_slot
*) symbol_table
,
3563 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3566 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3571 /* Callback types for dwarf2_read_gdb_index. */
3573 typedef gdb::function_view
3574 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3575 get_gdb_index_contents_ftype
;
3576 typedef gdb::function_view
3577 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3578 get_gdb_index_contents_dwz_ftype
;
3580 /* Read .gdb_index. If everything went ok, initialize the "quick"
3581 elements of all the CUs and return 1. Otherwise, return 0. */
3584 dwarf2_read_gdb_index
3585 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3586 get_gdb_index_contents_ftype get_gdb_index_contents
,
3587 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3589 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3590 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3591 struct dwz_file
*dwz
;
3592 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3594 gdb::array_view
<const gdb_byte
> main_index_contents
3595 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3597 if (main_index_contents
.empty ())
3600 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3601 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3602 use_deprecated_index_sections
,
3603 main_index_contents
, map
.get (), &cu_list
,
3604 &cu_list_elements
, &types_list
,
3605 &types_list_elements
))
3608 /* Don't use the index if it's empty. */
3609 if (map
->symbol_table
.empty ())
3612 /* If there is a .dwz file, read it so we can get its CU list as
3614 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3617 struct mapped_index dwz_map
;
3618 const gdb_byte
*dwz_types_ignore
;
3619 offset_type dwz_types_elements_ignore
;
3621 gdb::array_view
<const gdb_byte
> dwz_index_content
3622 = get_gdb_index_contents_dwz (objfile
, dwz
);
3624 if (dwz_index_content
.empty ())
3627 if (!read_gdb_index_from_buffer (objfile
,
3628 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3629 1, dwz_index_content
, &dwz_map
,
3630 &dwz_list
, &dwz_list_elements
,
3632 &dwz_types_elements_ignore
))
3634 warning (_("could not read '.gdb_index' section from %s; skipping"),
3635 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3640 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3641 dwz_list
, dwz_list_elements
);
3643 if (types_list_elements
)
3645 /* We can only handle a single .debug_types when we have an
3647 if (dwarf2_per_objfile
->types
.size () != 1)
3650 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3652 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3653 types_list
, types_list_elements
);
3656 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3658 dwarf2_per_objfile
->index_table
= std::move (map
);
3659 dwarf2_per_objfile
->using_index
= 1;
3660 dwarf2_per_objfile
->quick_file_names_table
=
3661 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3666 /* die_reader_func for dw2_get_file_names. */
3669 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3670 const gdb_byte
*info_ptr
,
3671 struct die_info
*comp_unit_die
,
3674 struct dwarf2_cu
*cu
= reader
->cu
;
3675 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3676 struct dwarf2_per_objfile
*dwarf2_per_objfile
3677 = cu
->per_cu
->dwarf2_per_objfile
;
3678 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3679 struct dwarf2_per_cu_data
*lh_cu
;
3680 struct attribute
*attr
;
3682 struct quick_file_names
*qfn
;
3684 gdb_assert (! this_cu
->is_debug_types
);
3686 /* Our callers never want to match partial units -- instead they
3687 will match the enclosing full CU. */
3688 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3690 this_cu
->v
.quick
->no_file_data
= 1;
3698 sect_offset line_offset
{};
3700 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3701 if (attr
!= nullptr)
3703 struct quick_file_names find_entry
;
3705 line_offset
= (sect_offset
) DW_UNSND (attr
);
3707 /* We may have already read in this line header (TU line header sharing).
3708 If we have we're done. */
3709 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3710 find_entry
.hash
.line_sect_off
= line_offset
;
3711 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3712 &find_entry
, INSERT
);
3715 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3719 lh
= dwarf_decode_line_header (line_offset
, cu
);
3723 lh_cu
->v
.quick
->no_file_data
= 1;
3727 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3728 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3729 qfn
->hash
.line_sect_off
= line_offset
;
3730 gdb_assert (slot
!= NULL
);
3733 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3736 if (strcmp (fnd
.name
, "<unknown>") != 0)
3739 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3741 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3743 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3744 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3745 qfn
->file_names
[i
+ offset
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3746 qfn
->real_names
= NULL
;
3748 lh_cu
->v
.quick
->file_names
= qfn
;
3751 /* A helper for the "quick" functions which attempts to read the line
3752 table for THIS_CU. */
3754 static struct quick_file_names
*
3755 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3757 /* This should never be called for TUs. */
3758 gdb_assert (! this_cu
->is_debug_types
);
3759 /* Nor type unit groups. */
3760 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3762 if (this_cu
->v
.quick
->file_names
!= NULL
)
3763 return this_cu
->v
.quick
->file_names
;
3764 /* If we know there is no line data, no point in looking again. */
3765 if (this_cu
->v
.quick
->no_file_data
)
3768 cutu_reader
reader (this_cu
);
3769 if (!reader
.dummy_p
)
3770 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
3771 reader
.has_children
);
3773 if (this_cu
->v
.quick
->no_file_data
)
3775 return this_cu
->v
.quick
->file_names
;
3778 /* A helper for the "quick" functions which computes and caches the
3779 real path for a given file name from the line table. */
3782 dw2_get_real_path (struct objfile
*objfile
,
3783 struct quick_file_names
*qfn
, int index
)
3785 if (qfn
->real_names
== NULL
)
3786 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3787 qfn
->num_file_names
, const char *);
3789 if (qfn
->real_names
[index
] == NULL
)
3790 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3792 return qfn
->real_names
[index
];
3795 static struct symtab
*
3796 dw2_find_last_source_symtab (struct objfile
*objfile
)
3798 struct dwarf2_per_objfile
*dwarf2_per_objfile
3799 = get_dwarf2_per_objfile (objfile
);
3800 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3801 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3806 return compunit_primary_filetab (cust
);
3809 /* Traversal function for dw2_forget_cached_source_info. */
3812 dw2_free_cached_file_names (void **slot
, void *info
)
3814 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3816 if (file_data
->real_names
)
3820 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3822 xfree ((void*) file_data
->real_names
[i
]);
3823 file_data
->real_names
[i
] = NULL
;
3831 dw2_forget_cached_source_info (struct objfile
*objfile
)
3833 struct dwarf2_per_objfile
*dwarf2_per_objfile
3834 = get_dwarf2_per_objfile (objfile
);
3836 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3837 dw2_free_cached_file_names
, NULL
);
3840 /* Helper function for dw2_map_symtabs_matching_filename that expands
3841 the symtabs and calls the iterator. */
3844 dw2_map_expand_apply (struct objfile
*objfile
,
3845 struct dwarf2_per_cu_data
*per_cu
,
3846 const char *name
, const char *real_path
,
3847 gdb::function_view
<bool (symtab
*)> callback
)
3849 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3851 /* Don't visit already-expanded CUs. */
3852 if (per_cu
->v
.quick
->compunit_symtab
)
3855 /* This may expand more than one symtab, and we want to iterate over
3857 dw2_instantiate_symtab (per_cu
, false);
3859 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3860 last_made
, callback
);
3863 /* Implementation of the map_symtabs_matching_filename method. */
3866 dw2_map_symtabs_matching_filename
3867 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3868 gdb::function_view
<bool (symtab
*)> callback
)
3870 const char *name_basename
= lbasename (name
);
3871 struct dwarf2_per_objfile
*dwarf2_per_objfile
3872 = get_dwarf2_per_objfile (objfile
);
3874 /* The rule is CUs specify all the files, including those used by
3875 any TU, so there's no need to scan TUs here. */
3877 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3879 /* We only need to look at symtabs not already expanded. */
3880 if (per_cu
->v
.quick
->compunit_symtab
)
3883 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3884 if (file_data
== NULL
)
3887 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3889 const char *this_name
= file_data
->file_names
[j
];
3890 const char *this_real_name
;
3892 if (compare_filenames_for_search (this_name
, name
))
3894 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3900 /* Before we invoke realpath, which can get expensive when many
3901 files are involved, do a quick comparison of the basenames. */
3902 if (! basenames_may_differ
3903 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3906 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3907 if (compare_filenames_for_search (this_real_name
, name
))
3909 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3915 if (real_path
!= NULL
)
3917 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3918 gdb_assert (IS_ABSOLUTE_PATH (name
));
3919 if (this_real_name
!= NULL
3920 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3922 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3934 /* Struct used to manage iterating over all CUs looking for a symbol. */
3936 struct dw2_symtab_iterator
3938 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3939 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3940 /* If set, only look for symbols that match that block. Valid values are
3941 GLOBAL_BLOCK and STATIC_BLOCK. */
3942 gdb::optional
<block_enum
> block_index
;
3943 /* The kind of symbol we're looking for. */
3945 /* The list of CUs from the index entry of the symbol,
3946 or NULL if not found. */
3948 /* The next element in VEC to look at. */
3950 /* The number of elements in VEC, or zero if there is no match. */
3952 /* Have we seen a global version of the symbol?
3953 If so we can ignore all further global instances.
3954 This is to work around gold/15646, inefficient gold-generated
3959 /* Initialize the index symtab iterator ITER. */
3962 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3963 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3964 gdb::optional
<block_enum
> block_index
,
3968 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3969 iter
->block_index
= block_index
;
3970 iter
->domain
= domain
;
3972 iter
->global_seen
= 0;
3974 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3976 /* index is NULL if OBJF_READNOW. */
3977 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3978 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3986 /* Return the next matching CU or NULL if there are no more. */
3988 static struct dwarf2_per_cu_data
*
3989 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3991 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3993 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3995 offset_type cu_index_and_attrs
=
3996 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3997 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3998 gdb_index_symbol_kind symbol_kind
=
3999 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4000 /* Only check the symbol attributes if they're present.
4001 Indices prior to version 7 don't record them,
4002 and indices >= 7 may elide them for certain symbols
4003 (gold does this). */
4005 (dwarf2_per_objfile
->index_table
->version
>= 7
4006 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4008 /* Don't crash on bad data. */
4009 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4010 + dwarf2_per_objfile
->all_type_units
.size ()))
4012 complaint (_(".gdb_index entry has bad CU index"
4014 objfile_name (dwarf2_per_objfile
->objfile
));
4018 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4020 /* Skip if already read in. */
4021 if (per_cu
->v
.quick
->compunit_symtab
)
4024 /* Check static vs global. */
4027 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4029 if (iter
->block_index
.has_value ())
4031 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
4033 if (is_static
!= want_static
)
4037 /* Work around gold/15646. */
4038 if (!is_static
&& iter
->global_seen
)
4041 iter
->global_seen
= 1;
4044 /* Only check the symbol's kind if it has one. */
4047 switch (iter
->domain
)
4050 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4051 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4052 /* Some types are also in VAR_DOMAIN. */
4053 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4057 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4061 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4065 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4080 static struct compunit_symtab
*
4081 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
4082 const char *name
, domain_enum domain
)
4084 struct compunit_symtab
*stab_best
= NULL
;
4085 struct dwarf2_per_objfile
*dwarf2_per_objfile
4086 = get_dwarf2_per_objfile (objfile
);
4088 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4090 struct dw2_symtab_iterator iter
;
4091 struct dwarf2_per_cu_data
*per_cu
;
4093 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
4095 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4097 struct symbol
*sym
, *with_opaque
= NULL
;
4098 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4099 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4100 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4102 sym
= block_find_symbol (block
, name
, domain
,
4103 block_find_non_opaque_type_preferred
,
4106 /* Some caution must be observed with overloaded functions
4107 and methods, since the index will not contain any overload
4108 information (but NAME might contain it). */
4111 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4113 if (with_opaque
!= NULL
4114 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4117 /* Keep looking through other CUs. */
4124 dw2_print_stats (struct objfile
*objfile
)
4126 struct dwarf2_per_objfile
*dwarf2_per_objfile
4127 = get_dwarf2_per_objfile (objfile
);
4128 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4129 + dwarf2_per_objfile
->all_type_units
.size ());
4132 for (int i
= 0; i
< total
; ++i
)
4134 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4136 if (!per_cu
->v
.quick
->compunit_symtab
)
4139 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4140 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4143 /* This dumps minimal information about the index.
4144 It is called via "mt print objfiles".
4145 One use is to verify .gdb_index has been loaded by the
4146 gdb.dwarf2/gdb-index.exp testcase. */
4149 dw2_dump (struct objfile
*objfile
)
4151 struct dwarf2_per_objfile
*dwarf2_per_objfile
4152 = get_dwarf2_per_objfile (objfile
);
4154 gdb_assert (dwarf2_per_objfile
->using_index
);
4155 printf_filtered (".gdb_index:");
4156 if (dwarf2_per_objfile
->index_table
!= NULL
)
4158 printf_filtered (" version %d\n",
4159 dwarf2_per_objfile
->index_table
->version
);
4162 printf_filtered (" faked for \"readnow\"\n");
4163 printf_filtered ("\n");
4167 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4168 const char *func_name
)
4170 struct dwarf2_per_objfile
*dwarf2_per_objfile
4171 = get_dwarf2_per_objfile (objfile
);
4173 struct dw2_symtab_iterator iter
;
4174 struct dwarf2_per_cu_data
*per_cu
;
4176 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
4178 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4179 dw2_instantiate_symtab (per_cu
, false);
4184 dw2_expand_all_symtabs (struct objfile
*objfile
)
4186 struct dwarf2_per_objfile
*dwarf2_per_objfile
4187 = get_dwarf2_per_objfile (objfile
);
4188 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4189 + dwarf2_per_objfile
->all_type_units
.size ());
4191 for (int i
= 0; i
< total_units
; ++i
)
4193 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4195 /* We don't want to directly expand a partial CU, because if we
4196 read it with the wrong language, then assertion failures can
4197 be triggered later on. See PR symtab/23010. So, tell
4198 dw2_instantiate_symtab to skip partial CUs -- any important
4199 partial CU will be read via DW_TAG_imported_unit anyway. */
4200 dw2_instantiate_symtab (per_cu
, true);
4205 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4206 const char *fullname
)
4208 struct dwarf2_per_objfile
*dwarf2_per_objfile
4209 = get_dwarf2_per_objfile (objfile
);
4211 /* We don't need to consider type units here.
4212 This is only called for examining code, e.g. expand_line_sal.
4213 There can be an order of magnitude (or more) more type units
4214 than comp units, and we avoid them if we can. */
4216 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4218 /* We only need to look at symtabs not already expanded. */
4219 if (per_cu
->v
.quick
->compunit_symtab
)
4222 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4223 if (file_data
== NULL
)
4226 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4228 const char *this_fullname
= file_data
->file_names
[j
];
4230 if (filename_cmp (this_fullname
, fullname
) == 0)
4232 dw2_instantiate_symtab (per_cu
, false);
4240 dw2_map_matching_symbols
4241 (struct objfile
*objfile
,
4242 const lookup_name_info
&name
, domain_enum domain
,
4244 gdb::function_view
<symbol_found_callback_ftype
> callback
,
4245 symbol_compare_ftype
*ordered_compare
)
4247 /* Currently unimplemented; used for Ada. The function can be called if the
4248 current language is Ada for a non-Ada objfile using GNU index. As Ada
4249 does not look for non-Ada symbols this function should just return. */
4252 /* Starting from a search name, return the string that finds the upper
4253 bound of all strings that start with SEARCH_NAME in a sorted name
4254 list. Returns the empty string to indicate that the upper bound is
4255 the end of the list. */
4258 make_sort_after_prefix_name (const char *search_name
)
4260 /* When looking to complete "func", we find the upper bound of all
4261 symbols that start with "func" by looking for where we'd insert
4262 the closest string that would follow "func" in lexicographical
4263 order. Usually, that's "func"-with-last-character-incremented,
4264 i.e. "fund". Mind non-ASCII characters, though. Usually those
4265 will be UTF-8 multi-byte sequences, but we can't be certain.
4266 Especially mind the 0xff character, which is a valid character in
4267 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4268 rule out compilers allowing it in identifiers. Note that
4269 conveniently, strcmp/strcasecmp are specified to compare
4270 characters interpreted as unsigned char. So what we do is treat
4271 the whole string as a base 256 number composed of a sequence of
4272 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4273 to 0, and carries 1 to the following more-significant position.
4274 If the very first character in SEARCH_NAME ends up incremented
4275 and carries/overflows, then the upper bound is the end of the
4276 list. The string after the empty string is also the empty
4279 Some examples of this operation:
4281 SEARCH_NAME => "+1" RESULT
4285 "\xff" "a" "\xff" => "\xff" "b"
4290 Then, with these symbols for example:
4296 completing "func" looks for symbols between "func" and
4297 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4298 which finds "func" and "func1", but not "fund".
4302 funcÿ (Latin1 'ÿ' [0xff])
4306 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4307 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4311 ÿÿ (Latin1 'ÿ' [0xff])
4314 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4315 the end of the list.
4317 std::string after
= search_name
;
4318 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4320 if (!after
.empty ())
4321 after
.back () = (unsigned char) after
.back () + 1;
4325 /* See declaration. */
4327 std::pair
<std::vector
<name_component
>::const_iterator
,
4328 std::vector
<name_component
>::const_iterator
>
4329 mapped_index_base::find_name_components_bounds
4330 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
4333 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4335 const char *lang_name
4336 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4338 /* Comparison function object for lower_bound that matches against a
4339 given symbol name. */
4340 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4343 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4344 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4345 return name_cmp (elem_name
, name
) < 0;
4348 /* Comparison function object for upper_bound that matches against a
4349 given symbol name. */
4350 auto lookup_compare_upper
= [&] (const char *name
,
4351 const name_component
&elem
)
4353 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4354 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4355 return name_cmp (name
, elem_name
) < 0;
4358 auto begin
= this->name_components
.begin ();
4359 auto end
= this->name_components
.end ();
4361 /* Find the lower bound. */
4364 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4367 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4370 /* Find the upper bound. */
4373 if (lookup_name_without_params
.completion_mode ())
4375 /* In completion mode, we want UPPER to point past all
4376 symbols names that have the same prefix. I.e., with
4377 these symbols, and completing "func":
4379 function << lower bound
4381 other_function << upper bound
4383 We find the upper bound by looking for the insertion
4384 point of "func"-with-last-character-incremented,
4386 std::string after
= make_sort_after_prefix_name (lang_name
);
4389 return std::lower_bound (lower
, end
, after
.c_str (),
4390 lookup_compare_lower
);
4393 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4396 return {lower
, upper
};
4399 /* See declaration. */
4402 mapped_index_base::build_name_components ()
4404 if (!this->name_components
.empty ())
4407 this->name_components_casing
= case_sensitivity
;
4409 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4411 /* The code below only knows how to break apart components of C++
4412 symbol names (and other languages that use '::' as
4413 namespace/module separator) and Ada symbol names. */
4414 auto count
= this->symbol_name_count ();
4415 for (offset_type idx
= 0; idx
< count
; idx
++)
4417 if (this->symbol_name_slot_invalid (idx
))
4420 const char *name
= this->symbol_name_at (idx
);
4422 /* Add each name component to the name component table. */
4423 unsigned int previous_len
= 0;
4425 if (strstr (name
, "::") != nullptr)
4427 for (unsigned int current_len
= cp_find_first_component (name
);
4428 name
[current_len
] != '\0';
4429 current_len
+= cp_find_first_component (name
+ current_len
))
4431 gdb_assert (name
[current_len
] == ':');
4432 this->name_components
.push_back ({previous_len
, idx
});
4433 /* Skip the '::'. */
4435 previous_len
= current_len
;
4440 /* Handle the Ada encoded (aka mangled) form here. */
4441 for (const char *iter
= strstr (name
, "__");
4443 iter
= strstr (iter
, "__"))
4445 this->name_components
.push_back ({previous_len
, idx
});
4447 previous_len
= iter
- name
;
4451 this->name_components
.push_back ({previous_len
, idx
});
4454 /* Sort name_components elements by name. */
4455 auto name_comp_compare
= [&] (const name_component
&left
,
4456 const name_component
&right
)
4458 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4459 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4461 const char *left_name
= left_qualified
+ left
.name_offset
;
4462 const char *right_name
= right_qualified
+ right
.name_offset
;
4464 return name_cmp (left_name
, right_name
) < 0;
4467 std::sort (this->name_components
.begin (),
4468 this->name_components
.end (),
4472 /* Helper for dw2_expand_symtabs_matching that works with a
4473 mapped_index_base instead of the containing objfile. This is split
4474 to a separate function in order to be able to unit test the
4475 name_components matching using a mock mapped_index_base. For each
4476 symbol name that matches, calls MATCH_CALLBACK, passing it the
4477 symbol's index in the mapped_index_base symbol table. */
4480 dw2_expand_symtabs_matching_symbol
4481 (mapped_index_base
&index
,
4482 const lookup_name_info
&lookup_name_in
,
4483 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4484 enum search_domain kind
,
4485 gdb::function_view
<bool (offset_type
)> match_callback
)
4487 lookup_name_info lookup_name_without_params
4488 = lookup_name_in
.make_ignore_params ();
4490 /* Build the symbol name component sorted vector, if we haven't
4492 index
.build_name_components ();
4494 /* The same symbol may appear more than once in the range though.
4495 E.g., if we're looking for symbols that complete "w", and we have
4496 a symbol named "w1::w2", we'll find the two name components for
4497 that same symbol in the range. To be sure we only call the
4498 callback once per symbol, we first collect the symbol name
4499 indexes that matched in a temporary vector and ignore
4501 std::vector
<offset_type
> matches
;
4503 struct name_and_matcher
4505 symbol_name_matcher_ftype
*matcher
;
4506 const std::string
&name
;
4508 bool operator== (const name_and_matcher
&other
) const
4510 return matcher
== other
.matcher
&& name
== other
.name
;
4514 /* A vector holding all the different symbol name matchers, for all
4516 std::vector
<name_and_matcher
> matchers
;
4518 for (int i
= 0; i
< nr_languages
; i
++)
4520 enum language lang_e
= (enum language
) i
;
4522 const language_defn
*lang
= language_def (lang_e
);
4523 symbol_name_matcher_ftype
*name_matcher
4524 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4526 name_and_matcher key
{
4528 lookup_name_without_params
.language_lookup_name (lang_e
)
4531 /* Don't insert the same comparison routine more than once.
4532 Note that we do this linear walk. This is not a problem in
4533 practice because the number of supported languages is
4535 if (std::find (matchers
.begin (), matchers
.end (), key
)
4538 matchers
.push_back (std::move (key
));
4541 = index
.find_name_components_bounds (lookup_name_without_params
,
4544 /* Now for each symbol name in range, check to see if we have a name
4545 match, and if so, call the MATCH_CALLBACK callback. */
4547 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4549 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4551 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4552 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4555 matches
.push_back (bounds
.first
->idx
);
4559 std::sort (matches
.begin (), matches
.end ());
4561 /* Finally call the callback, once per match. */
4563 for (offset_type idx
: matches
)
4567 if (!match_callback (idx
))
4573 /* Above we use a type wider than idx's for 'prev', since 0 and
4574 (offset_type)-1 are both possible values. */
4575 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4580 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4582 /* A mock .gdb_index/.debug_names-like name index table, enough to
4583 exercise dw2_expand_symtabs_matching_symbol, which works with the
4584 mapped_index_base interface. Builds an index from the symbol list
4585 passed as parameter to the constructor. */
4586 class mock_mapped_index
: public mapped_index_base
4589 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4590 : m_symbol_table (symbols
)
4593 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4595 /* Return the number of names in the symbol table. */
4596 size_t symbol_name_count () const override
4598 return m_symbol_table
.size ();
4601 /* Get the name of the symbol at IDX in the symbol table. */
4602 const char *symbol_name_at (offset_type idx
) const override
4604 return m_symbol_table
[idx
];
4608 gdb::array_view
<const char *> m_symbol_table
;
4611 /* Convenience function that converts a NULL pointer to a "<null>"
4612 string, to pass to print routines. */
4615 string_or_null (const char *str
)
4617 return str
!= NULL
? str
: "<null>";
4620 /* Check if a lookup_name_info built from
4621 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4622 index. EXPECTED_LIST is the list of expected matches, in expected
4623 matching order. If no match expected, then an empty list is
4624 specified. Returns true on success. On failure prints a warning
4625 indicating the file:line that failed, and returns false. */
4628 check_match (const char *file
, int line
,
4629 mock_mapped_index
&mock_index
,
4630 const char *name
, symbol_name_match_type match_type
,
4631 bool completion_mode
,
4632 std::initializer_list
<const char *> expected_list
)
4634 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4636 bool matched
= true;
4638 auto mismatch
= [&] (const char *expected_str
,
4641 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4642 "expected=\"%s\", got=\"%s\"\n"),
4644 (match_type
== symbol_name_match_type::FULL
4646 name
, string_or_null (expected_str
), string_or_null (got
));
4650 auto expected_it
= expected_list
.begin ();
4651 auto expected_end
= expected_list
.end ();
4653 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4655 [&] (offset_type idx
)
4657 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4658 const char *expected_str
4659 = expected_it
== expected_end
? NULL
: *expected_it
++;
4661 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4662 mismatch (expected_str
, matched_name
);
4666 const char *expected_str
4667 = expected_it
== expected_end
? NULL
: *expected_it
++;
4668 if (expected_str
!= NULL
)
4669 mismatch (expected_str
, NULL
);
4674 /* The symbols added to the mock mapped_index for testing (in
4676 static const char *test_symbols
[] = {
4685 "ns2::tmpl<int>::foo2",
4686 "(anonymous namespace)::A::B::C",
4688 /* These are used to check that the increment-last-char in the
4689 matching algorithm for completion doesn't match "t1_fund" when
4690 completing "t1_func". */
4696 /* A UTF-8 name with multi-byte sequences to make sure that
4697 cp-name-parser understands this as a single identifier ("função"
4698 is "function" in PT). */
4701 /* \377 (0xff) is Latin1 'ÿ'. */
4704 /* \377 (0xff) is Latin1 'ÿ'. */
4708 /* A name with all sorts of complications. Starts with "z" to make
4709 it easier for the completion tests below. */
4710 #define Z_SYM_NAME \
4711 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4712 "::tuple<(anonymous namespace)::ui*, " \
4713 "std::default_delete<(anonymous namespace)::ui>, void>"
4718 /* Returns true if the mapped_index_base::find_name_component_bounds
4719 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4720 in completion mode. */
4723 check_find_bounds_finds (mapped_index_base
&index
,
4724 const char *search_name
,
4725 gdb::array_view
<const char *> expected_syms
)
4727 lookup_name_info
lookup_name (search_name
,
4728 symbol_name_match_type::FULL
, true);
4730 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4733 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4734 if (distance
!= expected_syms
.size ())
4737 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4739 auto nc_elem
= bounds
.first
+ exp_elem
;
4740 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4741 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4748 /* Test the lower-level mapped_index::find_name_component_bounds
4752 test_mapped_index_find_name_component_bounds ()
4754 mock_mapped_index
mock_index (test_symbols
);
4756 mock_index
.build_name_components ();
4758 /* Test the lower-level mapped_index::find_name_component_bounds
4759 method in completion mode. */
4761 static const char *expected_syms
[] = {
4766 SELF_CHECK (check_find_bounds_finds (mock_index
,
4767 "t1_func", expected_syms
));
4770 /* Check that the increment-last-char in the name matching algorithm
4771 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4773 static const char *expected_syms1
[] = {
4777 SELF_CHECK (check_find_bounds_finds (mock_index
,
4778 "\377", expected_syms1
));
4780 static const char *expected_syms2
[] = {
4783 SELF_CHECK (check_find_bounds_finds (mock_index
,
4784 "\377\377", expected_syms2
));
4788 /* Test dw2_expand_symtabs_matching_symbol. */
4791 test_dw2_expand_symtabs_matching_symbol ()
4793 mock_mapped_index
mock_index (test_symbols
);
4795 /* We let all tests run until the end even if some fails, for debug
4797 bool any_mismatch
= false;
4799 /* Create the expected symbols list (an initializer_list). Needed
4800 because lists have commas, and we need to pass them to CHECK,
4801 which is a macro. */
4802 #define EXPECT(...) { __VA_ARGS__ }
4804 /* Wrapper for check_match that passes down the current
4805 __FILE__/__LINE__. */
4806 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4807 any_mismatch |= !check_match (__FILE__, __LINE__, \
4809 NAME, MATCH_TYPE, COMPLETION_MODE, \
4812 /* Identity checks. */
4813 for (const char *sym
: test_symbols
)
4815 /* Should be able to match all existing symbols. */
4816 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4819 /* Should be able to match all existing symbols with
4821 std::string with_params
= std::string (sym
) + "(int)";
4822 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4825 /* Should be able to match all existing symbols with
4826 parameters and qualifiers. */
4827 with_params
= std::string (sym
) + " ( int ) const";
4828 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4831 /* This should really find sym, but cp-name-parser.y doesn't
4832 know about lvalue/rvalue qualifiers yet. */
4833 with_params
= std::string (sym
) + " ( int ) &&";
4834 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4838 /* Check that the name matching algorithm for completion doesn't get
4839 confused with Latin1 'ÿ' / 0xff. */
4841 static const char str
[] = "\377";
4842 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4843 EXPECT ("\377", "\377\377123"));
4846 /* Check that the increment-last-char in the matching algorithm for
4847 completion doesn't match "t1_fund" when completing "t1_func". */
4849 static const char str
[] = "t1_func";
4850 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4851 EXPECT ("t1_func", "t1_func1"));
4854 /* Check that completion mode works at each prefix of the expected
4857 static const char str
[] = "function(int)";
4858 size_t len
= strlen (str
);
4861 for (size_t i
= 1; i
< len
; i
++)
4863 lookup
.assign (str
, i
);
4864 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4865 EXPECT ("function"));
4869 /* While "w" is a prefix of both components, the match function
4870 should still only be called once. */
4872 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4874 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4878 /* Same, with a "complicated" symbol. */
4880 static const char str
[] = Z_SYM_NAME
;
4881 size_t len
= strlen (str
);
4884 for (size_t i
= 1; i
< len
; i
++)
4886 lookup
.assign (str
, i
);
4887 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4888 EXPECT (Z_SYM_NAME
));
4892 /* In FULL mode, an incomplete symbol doesn't match. */
4894 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4898 /* A complete symbol with parameters matches any overload, since the
4899 index has no overload info. */
4901 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4902 EXPECT ("std::zfunction", "std::zfunction2"));
4903 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4904 EXPECT ("std::zfunction", "std::zfunction2"));
4905 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4906 EXPECT ("std::zfunction", "std::zfunction2"));
4909 /* Check that whitespace is ignored appropriately. A symbol with a
4910 template argument list. */
4912 static const char expected
[] = "ns::foo<int>";
4913 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4915 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4919 /* Check that whitespace is ignored appropriately. A symbol with a
4920 template argument list that includes a pointer. */
4922 static const char expected
[] = "ns::foo<char*>";
4923 /* Try both completion and non-completion modes. */
4924 static const bool completion_mode
[2] = {false, true};
4925 for (size_t i
= 0; i
< 2; i
++)
4927 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4928 completion_mode
[i
], EXPECT (expected
));
4929 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4930 completion_mode
[i
], EXPECT (expected
));
4932 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4933 completion_mode
[i
], EXPECT (expected
));
4934 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4935 completion_mode
[i
], EXPECT (expected
));
4940 /* Check method qualifiers are ignored. */
4941 static const char expected
[] = "ns::foo<char*>";
4942 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4943 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4944 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4945 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4946 CHECK_MATCH ("foo < char * > ( int ) const",
4947 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4948 CHECK_MATCH ("foo < char * > ( int ) &&",
4949 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4952 /* Test lookup names that don't match anything. */
4954 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4957 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4961 /* Some wild matching tests, exercising "(anonymous namespace)",
4962 which should not be confused with a parameter list. */
4964 static const char *syms
[] = {
4968 "A :: B :: C ( int )",
4973 for (const char *s
: syms
)
4975 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4976 EXPECT ("(anonymous namespace)::A::B::C"));
4981 static const char expected
[] = "ns2::tmpl<int>::foo2";
4982 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4984 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4988 SELF_CHECK (!any_mismatch
);
4997 test_mapped_index_find_name_component_bounds ();
4998 test_dw2_expand_symtabs_matching_symbol ();
5001 }} // namespace selftests::dw2_expand_symtabs_matching
5003 #endif /* GDB_SELF_TEST */
5005 /* If FILE_MATCHER is NULL or if PER_CU has
5006 dwarf2_per_cu_quick_data::MARK set (see
5007 dw_expand_symtabs_matching_file_matcher), expand the CU and call
5008 EXPANSION_NOTIFY on it. */
5011 dw2_expand_symtabs_matching_one
5012 (struct dwarf2_per_cu_data
*per_cu
,
5013 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5014 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5016 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5018 bool symtab_was_null
5019 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5021 dw2_instantiate_symtab (per_cu
, false);
5023 if (expansion_notify
!= NULL
5025 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5026 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5030 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5031 matched, to expand corresponding CUs that were marked. IDX is the
5032 index of the symbol name that matched. */
5035 dw2_expand_marked_cus
5036 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5037 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5038 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5041 offset_type
*vec
, vec_len
, vec_idx
;
5042 bool global_seen
= false;
5043 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5045 vec
= (offset_type
*) (index
.constant_pool
5046 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5047 vec_len
= MAYBE_SWAP (vec
[0]);
5048 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5050 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5051 /* This value is only valid for index versions >= 7. */
5052 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5053 gdb_index_symbol_kind symbol_kind
=
5054 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5055 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5056 /* Only check the symbol attributes if they're present.
5057 Indices prior to version 7 don't record them,
5058 and indices >= 7 may elide them for certain symbols
5059 (gold does this). */
5062 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5064 /* Work around gold/15646. */
5067 if (!is_static
&& global_seen
)
5073 /* Only check the symbol's kind if it has one. */
5078 case VARIABLES_DOMAIN
:
5079 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5082 case FUNCTIONS_DOMAIN
:
5083 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5087 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5090 case MODULES_DOMAIN
:
5091 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
5099 /* Don't crash on bad data. */
5100 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5101 + dwarf2_per_objfile
->all_type_units
.size ()))
5103 complaint (_(".gdb_index entry has bad CU index"
5105 objfile_name (dwarf2_per_objfile
->objfile
));
5109 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5110 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5115 /* If FILE_MATCHER is non-NULL, set all the
5116 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5117 that match FILE_MATCHER. */
5120 dw_expand_symtabs_matching_file_matcher
5121 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5122 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5124 if (file_matcher
== NULL
)
5127 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5129 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5131 NULL
, xcalloc
, xfree
));
5132 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5134 NULL
, xcalloc
, xfree
));
5136 /* The rule is CUs specify all the files, including those used by
5137 any TU, so there's no need to scan TUs here. */
5139 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5143 per_cu
->v
.quick
->mark
= 0;
5145 /* We only need to look at symtabs not already expanded. */
5146 if (per_cu
->v
.quick
->compunit_symtab
)
5149 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5150 if (file_data
== NULL
)
5153 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5155 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5157 per_cu
->v
.quick
->mark
= 1;
5161 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5163 const char *this_real_name
;
5165 if (file_matcher (file_data
->file_names
[j
], false))
5167 per_cu
->v
.quick
->mark
= 1;
5171 /* Before we invoke realpath, which can get expensive when many
5172 files are involved, do a quick comparison of the basenames. */
5173 if (!basenames_may_differ
5174 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5178 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5179 if (file_matcher (this_real_name
, false))
5181 per_cu
->v
.quick
->mark
= 1;
5186 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5187 ? visited_found
.get ()
5188 : visited_not_found
.get (),
5195 dw2_expand_symtabs_matching
5196 (struct objfile
*objfile
,
5197 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5198 const lookup_name_info
&lookup_name
,
5199 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5200 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5201 enum search_domain kind
)
5203 struct dwarf2_per_objfile
*dwarf2_per_objfile
5204 = get_dwarf2_per_objfile (objfile
);
5206 /* index_table is NULL if OBJF_READNOW. */
5207 if (!dwarf2_per_objfile
->index_table
)
5210 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5212 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5214 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5216 kind
, [&] (offset_type idx
)
5218 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5219 expansion_notify
, kind
);
5224 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5227 static struct compunit_symtab
*
5228 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5233 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5234 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5237 if (cust
->includes
== NULL
)
5240 for (i
= 0; cust
->includes
[i
]; ++i
)
5242 struct compunit_symtab
*s
= cust
->includes
[i
];
5244 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5252 static struct compunit_symtab
*
5253 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5254 struct bound_minimal_symbol msymbol
,
5256 struct obj_section
*section
,
5259 struct dwarf2_per_cu_data
*data
;
5260 struct compunit_symtab
*result
;
5262 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5265 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
5266 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5267 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5271 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5272 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5273 paddress (get_objfile_arch (objfile
), pc
));
5276 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5279 gdb_assert (result
!= NULL
);
5284 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5285 void *data
, int need_fullname
)
5287 struct dwarf2_per_objfile
*dwarf2_per_objfile
5288 = get_dwarf2_per_objfile (objfile
);
5290 if (!dwarf2_per_objfile
->filenames_cache
)
5292 dwarf2_per_objfile
->filenames_cache
.emplace ();
5294 htab_up
visited (htab_create_alloc (10,
5295 htab_hash_pointer
, htab_eq_pointer
,
5296 NULL
, xcalloc
, xfree
));
5298 /* The rule is CUs specify all the files, including those used
5299 by any TU, so there's no need to scan TUs here. We can
5300 ignore file names coming from already-expanded CUs. */
5302 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5304 if (per_cu
->v
.quick
->compunit_symtab
)
5306 void **slot
= htab_find_slot (visited
.get (),
5307 per_cu
->v
.quick
->file_names
,
5310 *slot
= per_cu
->v
.quick
->file_names
;
5314 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5316 /* We only need to look at symtabs not already expanded. */
5317 if (per_cu
->v
.quick
->compunit_symtab
)
5320 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5321 if (file_data
== NULL
)
5324 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5327 /* Already visited. */
5332 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5334 const char *filename
= file_data
->file_names
[j
];
5335 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5340 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5342 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5345 this_real_name
= gdb_realpath (filename
);
5346 (*fun
) (filename
, this_real_name
.get (), data
);
5351 dw2_has_symbols (struct objfile
*objfile
)
5356 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5359 dw2_find_last_source_symtab
,
5360 dw2_forget_cached_source_info
,
5361 dw2_map_symtabs_matching_filename
,
5365 dw2_expand_symtabs_for_function
,
5366 dw2_expand_all_symtabs
,
5367 dw2_expand_symtabs_with_fullname
,
5368 dw2_map_matching_symbols
,
5369 dw2_expand_symtabs_matching
,
5370 dw2_find_pc_sect_compunit_symtab
,
5372 dw2_map_symbol_filenames
5375 /* DWARF-5 debug_names reader. */
5377 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5378 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5380 /* A helper function that reads the .debug_names section in SECTION
5381 and fills in MAP. FILENAME is the name of the file containing the
5382 section; it is used for error reporting.
5384 Returns true if all went well, false otherwise. */
5387 read_debug_names_from_section (struct objfile
*objfile
,
5388 const char *filename
,
5389 struct dwarf2_section_info
*section
,
5390 mapped_debug_names
&map
)
5392 if (dwarf2_section_empty_p (section
))
5395 /* Older elfutils strip versions could keep the section in the main
5396 executable while splitting it for the separate debug info file. */
5397 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5400 dwarf2_read_section (objfile
, section
);
5402 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5404 const gdb_byte
*addr
= section
->buffer
;
5406 bfd
*const abfd
= get_section_bfd_owner (section
);
5408 unsigned int bytes_read
;
5409 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5412 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5413 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5414 if (bytes_read
+ length
!= section
->size
)
5416 /* There may be multiple per-CU indices. */
5417 warning (_("Section .debug_names in %s length %s does not match "
5418 "section length %s, ignoring .debug_names."),
5419 filename
, plongest (bytes_read
+ length
),
5420 pulongest (section
->size
));
5424 /* The version number. */
5425 uint16_t version
= read_2_bytes (abfd
, addr
);
5429 warning (_("Section .debug_names in %s has unsupported version %d, "
5430 "ignoring .debug_names."),
5436 uint16_t padding
= read_2_bytes (abfd
, addr
);
5440 warning (_("Section .debug_names in %s has unsupported padding %d, "
5441 "ignoring .debug_names."),
5446 /* comp_unit_count - The number of CUs in the CU list. */
5447 map
.cu_count
= read_4_bytes (abfd
, addr
);
5450 /* local_type_unit_count - The number of TUs in the local TU
5452 map
.tu_count
= read_4_bytes (abfd
, addr
);
5455 /* foreign_type_unit_count - The number of TUs in the foreign TU
5457 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5459 if (foreign_tu_count
!= 0)
5461 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5462 "ignoring .debug_names."),
5463 filename
, static_cast<unsigned long> (foreign_tu_count
));
5467 /* bucket_count - The number of hash buckets in the hash lookup
5469 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5472 /* name_count - The number of unique names in the index. */
5473 map
.name_count
= read_4_bytes (abfd
, addr
);
5476 /* abbrev_table_size - The size in bytes of the abbreviations
5478 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5481 /* augmentation_string_size - The size in bytes of the augmentation
5482 string. This value is rounded up to a multiple of 4. */
5483 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5485 map
.augmentation_is_gdb
= ((augmentation_string_size
5486 == sizeof (dwarf5_augmentation
))
5487 && memcmp (addr
, dwarf5_augmentation
,
5488 sizeof (dwarf5_augmentation
)) == 0);
5489 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5490 addr
+= augmentation_string_size
;
5493 map
.cu_table_reordered
= addr
;
5494 addr
+= map
.cu_count
* map
.offset_size
;
5496 /* List of Local TUs */
5497 map
.tu_table_reordered
= addr
;
5498 addr
+= map
.tu_count
* map
.offset_size
;
5500 /* Hash Lookup Table */
5501 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5502 addr
+= map
.bucket_count
* 4;
5503 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5504 addr
+= map
.name_count
* 4;
5507 map
.name_table_string_offs_reordered
= addr
;
5508 addr
+= map
.name_count
* map
.offset_size
;
5509 map
.name_table_entry_offs_reordered
= addr
;
5510 addr
+= map
.name_count
* map
.offset_size
;
5512 const gdb_byte
*abbrev_table_start
= addr
;
5515 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5520 const auto insertpair
5521 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5522 if (!insertpair
.second
)
5524 warning (_("Section .debug_names in %s has duplicate index %s, "
5525 "ignoring .debug_names."),
5526 filename
, pulongest (index_num
));
5529 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5530 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5535 mapped_debug_names::index_val::attr attr
;
5536 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5538 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5540 if (attr
.form
== DW_FORM_implicit_const
)
5542 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5546 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5548 indexval
.attr_vec
.push_back (std::move (attr
));
5551 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5553 warning (_("Section .debug_names in %s has abbreviation_table "
5554 "of size %s vs. written as %u, ignoring .debug_names."),
5555 filename
, plongest (addr
- abbrev_table_start
),
5559 map
.entry_pool
= addr
;
5564 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5568 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5569 const mapped_debug_names
&map
,
5570 dwarf2_section_info
§ion
,
5573 sect_offset sect_off_prev
;
5574 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5576 sect_offset sect_off_next
;
5577 if (i
< map
.cu_count
)
5580 = (sect_offset
) (extract_unsigned_integer
5581 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5583 map
.dwarf5_byte_order
));
5586 sect_off_next
= (sect_offset
) section
.size
;
5589 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5590 dwarf2_per_cu_data
*per_cu
5591 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5592 sect_off_prev
, length
);
5593 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5595 sect_off_prev
= sect_off_next
;
5599 /* Read the CU list from the mapped index, and use it to create all
5600 the CU objects for this dwarf2_per_objfile. */
5603 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5604 const mapped_debug_names
&map
,
5605 const mapped_debug_names
&dwz_map
)
5607 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5608 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5610 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5611 dwarf2_per_objfile
->info
,
5612 false /* is_dwz */);
5614 if (dwz_map
.cu_count
== 0)
5617 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5618 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5622 /* Read .debug_names. If everything went ok, initialize the "quick"
5623 elements of all the CUs and return true. Otherwise, return false. */
5626 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5628 std::unique_ptr
<mapped_debug_names
> map
5629 (new mapped_debug_names (dwarf2_per_objfile
));
5630 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5631 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5633 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5634 &dwarf2_per_objfile
->debug_names
,
5638 /* Don't use the index if it's empty. */
5639 if (map
->name_count
== 0)
5642 /* If there is a .dwz file, read it so we can get its CU list as
5644 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5647 if (!read_debug_names_from_section (objfile
,
5648 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5649 &dwz
->debug_names
, dwz_map
))
5651 warning (_("could not read '.debug_names' section from %s; skipping"),
5652 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5657 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5659 if (map
->tu_count
!= 0)
5661 /* We can only handle a single .debug_types when we have an
5663 if (dwarf2_per_objfile
->types
.size () != 1)
5666 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5668 create_signatured_type_table_from_debug_names
5669 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5672 create_addrmap_from_aranges (dwarf2_per_objfile
,
5673 &dwarf2_per_objfile
->debug_aranges
);
5675 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5676 dwarf2_per_objfile
->using_index
= 1;
5677 dwarf2_per_objfile
->quick_file_names_table
=
5678 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5683 /* Type used to manage iterating over all CUs looking for a symbol for
5686 class dw2_debug_names_iterator
5689 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5690 gdb::optional
<block_enum
> block_index
,
5693 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5694 m_addr (find_vec_in_debug_names (map
, name
))
5697 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5698 search_domain search
, uint32_t namei
)
5701 m_addr (find_vec_in_debug_names (map
, namei
))
5704 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5705 block_enum block_index
, domain_enum domain
,
5707 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5708 m_addr (find_vec_in_debug_names (map
, namei
))
5711 /* Return the next matching CU or NULL if there are no more. */
5712 dwarf2_per_cu_data
*next ();
5715 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5717 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5720 /* The internalized form of .debug_names. */
5721 const mapped_debug_names
&m_map
;
5723 /* If set, only look for symbols that match that block. Valid values are
5724 GLOBAL_BLOCK and STATIC_BLOCK. */
5725 const gdb::optional
<block_enum
> m_block_index
;
5727 /* The kind of symbol we're looking for. */
5728 const domain_enum m_domain
= UNDEF_DOMAIN
;
5729 const search_domain m_search
= ALL_DOMAIN
;
5731 /* The list of CUs from the index entry of the symbol, or NULL if
5733 const gdb_byte
*m_addr
;
5737 mapped_debug_names::namei_to_name (uint32_t namei
) const
5739 const ULONGEST namei_string_offs
5740 = extract_unsigned_integer ((name_table_string_offs_reordered
5741 + namei
* offset_size
),
5744 return read_indirect_string_at_offset
5745 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5748 /* Find a slot in .debug_names for the object named NAME. If NAME is
5749 found, return pointer to its pool data. If NAME cannot be found,
5753 dw2_debug_names_iterator::find_vec_in_debug_names
5754 (const mapped_debug_names
&map
, const char *name
)
5756 int (*cmp
) (const char *, const char *);
5758 gdb::unique_xmalloc_ptr
<char> without_params
;
5759 if (current_language
->la_language
== language_cplus
5760 || current_language
->la_language
== language_fortran
5761 || current_language
->la_language
== language_d
)
5763 /* NAME is already canonical. Drop any qualifiers as
5764 .debug_names does not contain any. */
5766 if (strchr (name
, '(') != NULL
)
5768 without_params
= cp_remove_params (name
);
5769 if (without_params
!= NULL
)
5770 name
= without_params
.get ();
5774 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5776 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5778 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5779 (map
.bucket_table_reordered
5780 + (full_hash
% map
.bucket_count
)), 4,
5781 map
.dwarf5_byte_order
);
5785 if (namei
>= map
.name_count
)
5787 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5789 namei
, map
.name_count
,
5790 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5796 const uint32_t namei_full_hash
5797 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5798 (map
.hash_table_reordered
+ namei
), 4,
5799 map
.dwarf5_byte_order
);
5800 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5803 if (full_hash
== namei_full_hash
)
5805 const char *const namei_string
= map
.namei_to_name (namei
);
5807 #if 0 /* An expensive sanity check. */
5808 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5810 complaint (_("Wrong .debug_names hash for string at index %u "
5812 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5817 if (cmp (namei_string
, name
) == 0)
5819 const ULONGEST namei_entry_offs
5820 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5821 + namei
* map
.offset_size
),
5822 map
.offset_size
, map
.dwarf5_byte_order
);
5823 return map
.entry_pool
+ namei_entry_offs
;
5828 if (namei
>= map
.name_count
)
5834 dw2_debug_names_iterator::find_vec_in_debug_names
5835 (const mapped_debug_names
&map
, uint32_t namei
)
5837 if (namei
>= map
.name_count
)
5839 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5841 namei
, map
.name_count
,
5842 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5846 const ULONGEST namei_entry_offs
5847 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5848 + namei
* map
.offset_size
),
5849 map
.offset_size
, map
.dwarf5_byte_order
);
5850 return map
.entry_pool
+ namei_entry_offs
;
5853 /* See dw2_debug_names_iterator. */
5855 dwarf2_per_cu_data
*
5856 dw2_debug_names_iterator::next ()
5861 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5862 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5863 bfd
*const abfd
= objfile
->obfd
;
5867 unsigned int bytes_read
;
5868 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5869 m_addr
+= bytes_read
;
5873 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5874 if (indexval_it
== m_map
.abbrev_map
.cend ())
5876 complaint (_("Wrong .debug_names undefined abbrev code %s "
5878 pulongest (abbrev
), objfile_name (objfile
));
5881 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5882 enum class symbol_linkage
{
5886 } symbol_linkage_
= symbol_linkage::unknown
;
5887 dwarf2_per_cu_data
*per_cu
= NULL
;
5888 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5893 case DW_FORM_implicit_const
:
5894 ull
= attr
.implicit_const
;
5896 case DW_FORM_flag_present
:
5900 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5901 m_addr
+= bytes_read
;
5904 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5905 dwarf_form_name (attr
.form
),
5906 objfile_name (objfile
));
5909 switch (attr
.dw_idx
)
5911 case DW_IDX_compile_unit
:
5912 /* Don't crash on bad data. */
5913 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5915 complaint (_(".debug_names entry has bad CU index %s"
5918 objfile_name (dwarf2_per_objfile
->objfile
));
5921 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5923 case DW_IDX_type_unit
:
5924 /* Don't crash on bad data. */
5925 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5927 complaint (_(".debug_names entry has bad TU index %s"
5930 objfile_name (dwarf2_per_objfile
->objfile
));
5933 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5935 case DW_IDX_GNU_internal
:
5936 if (!m_map
.augmentation_is_gdb
)
5938 symbol_linkage_
= symbol_linkage::static_
;
5940 case DW_IDX_GNU_external
:
5941 if (!m_map
.augmentation_is_gdb
)
5943 symbol_linkage_
= symbol_linkage::extern_
;
5948 /* Skip if already read in. */
5949 if (per_cu
->v
.quick
->compunit_symtab
)
5952 /* Check static vs global. */
5953 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5955 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5956 const bool symbol_is_static
=
5957 symbol_linkage_
== symbol_linkage::static_
;
5958 if (want_static
!= symbol_is_static
)
5962 /* Match dw2_symtab_iter_next, symbol_kind
5963 and debug_names::psymbol_tag. */
5967 switch (indexval
.dwarf_tag
)
5969 case DW_TAG_variable
:
5970 case DW_TAG_subprogram
:
5971 /* Some types are also in VAR_DOMAIN. */
5972 case DW_TAG_typedef
:
5973 case DW_TAG_structure_type
:
5980 switch (indexval
.dwarf_tag
)
5982 case DW_TAG_typedef
:
5983 case DW_TAG_structure_type
:
5990 switch (indexval
.dwarf_tag
)
5993 case DW_TAG_variable
:
6000 switch (indexval
.dwarf_tag
)
6012 /* Match dw2_expand_symtabs_matching, symbol_kind and
6013 debug_names::psymbol_tag. */
6016 case VARIABLES_DOMAIN
:
6017 switch (indexval
.dwarf_tag
)
6019 case DW_TAG_variable
:
6025 case FUNCTIONS_DOMAIN
:
6026 switch (indexval
.dwarf_tag
)
6028 case DW_TAG_subprogram
:
6035 switch (indexval
.dwarf_tag
)
6037 case DW_TAG_typedef
:
6038 case DW_TAG_structure_type
:
6044 case MODULES_DOMAIN
:
6045 switch (indexval
.dwarf_tag
)
6059 static struct compunit_symtab
*
6060 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
6061 const char *name
, domain_enum domain
)
6063 struct dwarf2_per_objfile
*dwarf2_per_objfile
6064 = get_dwarf2_per_objfile (objfile
);
6066 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6069 /* index is NULL if OBJF_READNOW. */
6072 const auto &map
= *mapp
;
6074 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
6076 struct compunit_symtab
*stab_best
= NULL
;
6077 struct dwarf2_per_cu_data
*per_cu
;
6078 while ((per_cu
= iter
.next ()) != NULL
)
6080 struct symbol
*sym
, *with_opaque
= NULL
;
6081 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6082 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6083 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6085 sym
= block_find_symbol (block
, name
, domain
,
6086 block_find_non_opaque_type_preferred
,
6089 /* Some caution must be observed with overloaded functions and
6090 methods, since the index will not contain any overload
6091 information (but NAME might contain it). */
6094 && strcmp_iw (sym
->search_name (), name
) == 0)
6096 if (with_opaque
!= NULL
6097 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
6100 /* Keep looking through other CUs. */
6106 /* This dumps minimal information about .debug_names. It is called
6107 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6108 uses this to verify that .debug_names has been loaded. */
6111 dw2_debug_names_dump (struct objfile
*objfile
)
6113 struct dwarf2_per_objfile
*dwarf2_per_objfile
6114 = get_dwarf2_per_objfile (objfile
);
6116 gdb_assert (dwarf2_per_objfile
->using_index
);
6117 printf_filtered (".debug_names:");
6118 if (dwarf2_per_objfile
->debug_names_table
)
6119 printf_filtered (" exists\n");
6121 printf_filtered (" faked for \"readnow\"\n");
6122 printf_filtered ("\n");
6126 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6127 const char *func_name
)
6129 struct dwarf2_per_objfile
*dwarf2_per_objfile
6130 = get_dwarf2_per_objfile (objfile
);
6132 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6133 if (dwarf2_per_objfile
->debug_names_table
)
6135 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6137 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
6139 struct dwarf2_per_cu_data
*per_cu
;
6140 while ((per_cu
= iter
.next ()) != NULL
)
6141 dw2_instantiate_symtab (per_cu
, false);
6146 dw2_debug_names_map_matching_symbols
6147 (struct objfile
*objfile
,
6148 const lookup_name_info
&name
, domain_enum domain
,
6150 gdb::function_view
<symbol_found_callback_ftype
> callback
,
6151 symbol_compare_ftype
*ordered_compare
)
6153 struct dwarf2_per_objfile
*dwarf2_per_objfile
6154 = get_dwarf2_per_objfile (objfile
);
6156 /* debug_names_table is NULL if OBJF_READNOW. */
6157 if (!dwarf2_per_objfile
->debug_names_table
)
6160 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6161 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
6163 const char *match_name
= name
.ada ().lookup_name ().c_str ();
6164 auto matcher
= [&] (const char *symname
)
6166 if (ordered_compare
== nullptr)
6168 return ordered_compare (symname
, match_name
) == 0;
6171 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
6172 [&] (offset_type namei
)
6174 /* The name was matched, now expand corresponding CUs that were
6176 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
6178 struct dwarf2_per_cu_data
*per_cu
;
6179 while ((per_cu
= iter
.next ()) != NULL
)
6180 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
6184 /* It's a shame we couldn't do this inside the
6185 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
6186 that have already been expanded. Instead, this loop matches what
6187 the psymtab code does. */
6188 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
6190 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
6191 if (cust
!= nullptr)
6193 const struct block
*block
6194 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
6195 if (!iterate_over_symbols_terminated (block
, name
,
6203 dw2_debug_names_expand_symtabs_matching
6204 (struct objfile
*objfile
,
6205 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6206 const lookup_name_info
&lookup_name
,
6207 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6208 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6209 enum search_domain kind
)
6211 struct dwarf2_per_objfile
*dwarf2_per_objfile
6212 = get_dwarf2_per_objfile (objfile
);
6214 /* debug_names_table is NULL if OBJF_READNOW. */
6215 if (!dwarf2_per_objfile
->debug_names_table
)
6218 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6220 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6222 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6224 kind
, [&] (offset_type namei
)
6226 /* The name was matched, now expand corresponding CUs that were
6228 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6230 struct dwarf2_per_cu_data
*per_cu
;
6231 while ((per_cu
= iter
.next ()) != NULL
)
6232 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6238 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6241 dw2_find_last_source_symtab
,
6242 dw2_forget_cached_source_info
,
6243 dw2_map_symtabs_matching_filename
,
6244 dw2_debug_names_lookup_symbol
,
6246 dw2_debug_names_dump
,
6247 dw2_debug_names_expand_symtabs_for_function
,
6248 dw2_expand_all_symtabs
,
6249 dw2_expand_symtabs_with_fullname
,
6250 dw2_debug_names_map_matching_symbols
,
6251 dw2_debug_names_expand_symtabs_matching
,
6252 dw2_find_pc_sect_compunit_symtab
,
6254 dw2_map_symbol_filenames
6257 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6258 to either a dwarf2_per_objfile or dwz_file object. */
6260 template <typename T
>
6261 static gdb::array_view
<const gdb_byte
>
6262 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6264 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6266 if (dwarf2_section_empty_p (section
))
6269 /* Older elfutils strip versions could keep the section in the main
6270 executable while splitting it for the separate debug info file. */
6271 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
6274 dwarf2_read_section (obj
, section
);
6276 /* dwarf2_section_info::size is a bfd_size_type, while
6277 gdb::array_view works with size_t. On 32-bit hosts, with
6278 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6279 is 32-bit. So we need an explicit narrowing conversion here.
6280 This is fine, because it's impossible to allocate or mmap an
6281 array/buffer larger than what size_t can represent. */
6282 return gdb::make_array_view (section
->buffer
, section
->size
);
6285 /* Lookup the index cache for the contents of the index associated to
6288 static gdb::array_view
<const gdb_byte
>
6289 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6291 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6292 if (build_id
== nullptr)
6295 return global_index_cache
.lookup_gdb_index (build_id
,
6296 &dwarf2_obj
->index_cache_res
);
6299 /* Same as the above, but for DWZ. */
6301 static gdb::array_view
<const gdb_byte
>
6302 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6304 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6305 if (build_id
== nullptr)
6308 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6311 /* See symfile.h. */
6314 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6316 struct dwarf2_per_objfile
*dwarf2_per_objfile
6317 = get_dwarf2_per_objfile (objfile
);
6319 /* If we're about to read full symbols, don't bother with the
6320 indices. In this case we also don't care if some other debug
6321 format is making psymtabs, because they are all about to be
6323 if ((objfile
->flags
& OBJF_READNOW
))
6325 dwarf2_per_objfile
->using_index
= 1;
6326 create_all_comp_units (dwarf2_per_objfile
);
6327 create_all_type_units (dwarf2_per_objfile
);
6328 dwarf2_per_objfile
->quick_file_names_table
6329 = create_quick_file_names_table
6330 (dwarf2_per_objfile
->all_comp_units
.size ());
6332 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6333 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6335 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6337 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6338 struct dwarf2_per_cu_quick_data
);
6341 /* Return 1 so that gdb sees the "quick" functions. However,
6342 these functions will be no-ops because we will have expanded
6344 *index_kind
= dw_index_kind::GDB_INDEX
;
6348 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6350 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6354 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6355 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6356 get_gdb_index_contents_from_section
<dwz_file
>))
6358 *index_kind
= dw_index_kind::GDB_INDEX
;
6362 /* ... otherwise, try to find the index in the index cache. */
6363 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6364 get_gdb_index_contents_from_cache
,
6365 get_gdb_index_contents_from_cache_dwz
))
6367 global_index_cache
.hit ();
6368 *index_kind
= dw_index_kind::GDB_INDEX
;
6372 global_index_cache
.miss ();
6378 /* Build a partial symbol table. */
6381 dwarf2_build_psymtabs (struct objfile
*objfile
)
6383 struct dwarf2_per_objfile
*dwarf2_per_objfile
6384 = get_dwarf2_per_objfile (objfile
);
6386 init_psymbol_list (objfile
, 1024);
6390 /* This isn't really ideal: all the data we allocate on the
6391 objfile's obstack is still uselessly kept around. However,
6392 freeing it seems unsafe. */
6393 psymtab_discarder
psymtabs (objfile
);
6394 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6397 /* (maybe) store an index in the cache. */
6398 global_index_cache
.store (dwarf2_per_objfile
);
6400 catch (const gdb_exception_error
&except
)
6402 exception_print (gdb_stderr
, except
);
6406 /* Return the total length of the CU described by HEADER. */
6409 get_cu_length (const struct comp_unit_head
*header
)
6411 return header
->initial_length_size
+ header
->length
;
6414 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6417 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6419 sect_offset bottom
= cu_header
->sect_off
;
6420 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6422 return sect_off
>= bottom
&& sect_off
< top
;
6425 /* Find the base address of the compilation unit for range lists and
6426 location lists. It will normally be specified by DW_AT_low_pc.
6427 In DWARF-3 draft 4, the base address could be overridden by
6428 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6429 compilation units with discontinuous ranges. */
6432 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6434 struct attribute
*attr
;
6437 cu
->base_address
= 0;
6439 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6440 if (attr
!= nullptr)
6442 cu
->base_address
= attr_value_as_address (attr
);
6447 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6448 if (attr
!= nullptr)
6450 cu
->base_address
= attr_value_as_address (attr
);
6456 /* Read in the comp unit header information from the debug_info at info_ptr.
6457 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6458 NOTE: This leaves members offset, first_die_offset to be filled in
6461 static const gdb_byte
*
6462 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6463 const gdb_byte
*info_ptr
,
6464 struct dwarf2_section_info
*section
,
6465 rcuh_kind section_kind
)
6468 unsigned int bytes_read
;
6469 const char *filename
= get_section_file_name (section
);
6470 bfd
*abfd
= get_section_bfd_owner (section
);
6472 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6473 cu_header
->initial_length_size
= bytes_read
;
6474 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6475 info_ptr
+= bytes_read
;
6476 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6477 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6478 error (_("Dwarf Error: wrong version in compilation unit header "
6479 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6480 cu_header
->version
, filename
);
6482 if (cu_header
->version
< 5)
6483 switch (section_kind
)
6485 case rcuh_kind::COMPILE
:
6486 cu_header
->unit_type
= DW_UT_compile
;
6488 case rcuh_kind::TYPE
:
6489 cu_header
->unit_type
= DW_UT_type
;
6492 internal_error (__FILE__
, __LINE__
,
6493 _("read_comp_unit_head: invalid section_kind"));
6497 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6498 (read_1_byte (abfd
, info_ptr
));
6500 switch (cu_header
->unit_type
)
6504 case DW_UT_skeleton
:
6505 case DW_UT_split_compile
:
6506 if (section_kind
!= rcuh_kind::COMPILE
)
6507 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6508 "(is %s, should be %s) [in module %s]"),
6509 dwarf_unit_type_name (cu_header
->unit_type
),
6510 dwarf_unit_type_name (DW_UT_type
), filename
);
6513 case DW_UT_split_type
:
6514 section_kind
= rcuh_kind::TYPE
;
6517 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6518 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6519 "[in module %s]"), cu_header
->unit_type
,
6520 dwarf_unit_type_name (DW_UT_compile
),
6521 dwarf_unit_type_name (DW_UT_skeleton
),
6522 dwarf_unit_type_name (DW_UT_split_compile
),
6523 dwarf_unit_type_name (DW_UT_type
),
6524 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6527 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6530 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6533 info_ptr
+= bytes_read
;
6534 if (cu_header
->version
< 5)
6536 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6539 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6540 if (signed_addr
< 0)
6541 internal_error (__FILE__
, __LINE__
,
6542 _("read_comp_unit_head: dwarf from non elf file"));
6543 cu_header
->signed_addr_p
= signed_addr
;
6545 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6546 || cu_header
->unit_type
== DW_UT_skeleton
6547 || cu_header
->unit_type
== DW_UT_split_compile
;
6549 if (header_has_signature
)
6551 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6555 if (section_kind
== rcuh_kind::TYPE
)
6557 LONGEST type_offset
;
6558 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6559 info_ptr
+= bytes_read
;
6560 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6561 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6562 error (_("Dwarf Error: Too big type_offset in compilation unit "
6563 "header (is %s) [in module %s]"), plongest (type_offset
),
6570 /* Helper function that returns the proper abbrev section for
6573 static struct dwarf2_section_info
*
6574 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6576 struct dwarf2_section_info
*abbrev
;
6577 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6579 if (this_cu
->is_dwz
)
6580 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6582 abbrev
= &dwarf2_per_objfile
->abbrev
;
6587 /* Subroutine of read_and_check_comp_unit_head and
6588 read_and_check_type_unit_head to simplify them.
6589 Perform various error checking on the header. */
6592 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6593 struct comp_unit_head
*header
,
6594 struct dwarf2_section_info
*section
,
6595 struct dwarf2_section_info
*abbrev_section
)
6597 const char *filename
= get_section_file_name (section
);
6599 if (to_underlying (header
->abbrev_sect_off
)
6600 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6601 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6602 "(offset %s + 6) [in module %s]"),
6603 sect_offset_str (header
->abbrev_sect_off
),
6604 sect_offset_str (header
->sect_off
),
6607 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6608 avoid potential 32-bit overflow. */
6609 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6611 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6612 "(offset %s + 0) [in module %s]"),
6613 header
->length
, sect_offset_str (header
->sect_off
),
6617 /* Read in a CU/TU header and perform some basic error checking.
6618 The contents of the header are stored in HEADER.
6619 The result is a pointer to the start of the first DIE. */
6621 static const gdb_byte
*
6622 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6623 struct comp_unit_head
*header
,
6624 struct dwarf2_section_info
*section
,
6625 struct dwarf2_section_info
*abbrev_section
,
6626 const gdb_byte
*info_ptr
,
6627 rcuh_kind section_kind
)
6629 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6631 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6633 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6635 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6637 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6643 /* Fetch the abbreviation table offset from a comp or type unit header. */
6646 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6647 struct dwarf2_section_info
*section
,
6648 sect_offset sect_off
)
6650 bfd
*abfd
= get_section_bfd_owner (section
);
6651 const gdb_byte
*info_ptr
;
6652 unsigned int initial_length_size
, offset_size
;
6655 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6656 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6657 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6658 offset_size
= initial_length_size
== 4 ? 4 : 8;
6659 info_ptr
+= initial_length_size
;
6661 version
= read_2_bytes (abfd
, info_ptr
);
6665 /* Skip unit type and address size. */
6669 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6672 /* Allocate a new partial symtab for file named NAME and mark this new
6673 partial symtab as being an include of PST. */
6676 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6677 struct objfile
*objfile
)
6679 dwarf2_psymtab
*subpst
= new dwarf2_psymtab (name
, objfile
);
6681 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6683 /* It shares objfile->objfile_obstack. */
6684 subpst
->dirname
= pst
->dirname
;
6687 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6688 subpst
->dependencies
[0] = pst
;
6689 subpst
->number_of_dependencies
= 1;
6691 /* No private part is necessary for include psymtabs. This property
6692 can be used to differentiate between such include psymtabs and
6693 the regular ones. */
6694 subpst
->per_cu_data
= nullptr;
6697 /* Read the Line Number Program data and extract the list of files
6698 included by the source file represented by PST. Build an include
6699 partial symtab for each of these included files. */
6702 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6703 struct die_info
*die
,
6704 dwarf2_psymtab
*pst
)
6707 struct attribute
*attr
;
6709 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6710 if (attr
!= nullptr)
6711 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6713 return; /* No linetable, so no includes. */
6715 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6716 that we pass in the raw text_low here; that is ok because we're
6717 only decoding the line table to make include partial symtabs, and
6718 so the addresses aren't really used. */
6719 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6720 pst
->raw_text_low (), 1);
6724 hash_signatured_type (const void *item
)
6726 const struct signatured_type
*sig_type
6727 = (const struct signatured_type
*) item
;
6729 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6730 return sig_type
->signature
;
6734 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6736 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6737 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6739 return lhs
->signature
== rhs
->signature
;
6742 /* Allocate a hash table for signatured types. */
6745 allocate_signatured_type_table (struct objfile
*objfile
)
6747 return htab_create_alloc_ex (41,
6748 hash_signatured_type
,
6751 &objfile
->objfile_obstack
,
6752 hashtab_obstack_allocate
,
6753 dummy_obstack_deallocate
);
6756 /* A helper function to add a signatured type CU to a table. */
6759 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6761 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6762 std::vector
<signatured_type
*> *all_type_units
6763 = (std::vector
<signatured_type
*> *) datum
;
6765 all_type_units
->push_back (sigt
);
6770 /* A helper for create_debug_types_hash_table. Read types from SECTION
6771 and fill them into TYPES_HTAB. It will process only type units,
6772 therefore DW_UT_type. */
6775 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6776 struct dwo_file
*dwo_file
,
6777 dwarf2_section_info
*section
, htab_t
&types_htab
,
6778 rcuh_kind section_kind
)
6780 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6781 struct dwarf2_section_info
*abbrev_section
;
6783 const gdb_byte
*info_ptr
, *end_ptr
;
6785 abbrev_section
= (dwo_file
!= NULL
6786 ? &dwo_file
->sections
.abbrev
6787 : &dwarf2_per_objfile
->abbrev
);
6789 if (dwarf_read_debug
)
6790 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6791 get_section_name (section
),
6792 get_section_file_name (abbrev_section
));
6794 dwarf2_read_section (objfile
, section
);
6795 info_ptr
= section
->buffer
;
6797 if (info_ptr
== NULL
)
6800 /* We can't set abfd until now because the section may be empty or
6801 not present, in which case the bfd is unknown. */
6802 abfd
= get_section_bfd_owner (section
);
6804 /* We don't use cutu_reader here because we don't need to read
6805 any dies: the signature is in the header. */
6807 end_ptr
= info_ptr
+ section
->size
;
6808 while (info_ptr
< end_ptr
)
6810 struct signatured_type
*sig_type
;
6811 struct dwo_unit
*dwo_tu
;
6813 const gdb_byte
*ptr
= info_ptr
;
6814 struct comp_unit_head header
;
6815 unsigned int length
;
6817 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6819 /* Initialize it due to a false compiler warning. */
6820 header
.signature
= -1;
6821 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6823 /* We need to read the type's signature in order to build the hash
6824 table, but we don't need anything else just yet. */
6826 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6827 abbrev_section
, ptr
, section_kind
);
6829 length
= get_cu_length (&header
);
6831 /* Skip dummy type units. */
6832 if (ptr
>= info_ptr
+ length
6833 || peek_abbrev_code (abfd
, ptr
) == 0
6834 || header
.unit_type
!= DW_UT_type
)
6840 if (types_htab
== NULL
)
6843 types_htab
= allocate_dwo_unit_table (objfile
);
6845 types_htab
= allocate_signatured_type_table (objfile
);
6851 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6853 dwo_tu
->dwo_file
= dwo_file
;
6854 dwo_tu
->signature
= header
.signature
;
6855 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6856 dwo_tu
->section
= section
;
6857 dwo_tu
->sect_off
= sect_off
;
6858 dwo_tu
->length
= length
;
6862 /* N.B.: type_offset is not usable if this type uses a DWO file.
6863 The real type_offset is in the DWO file. */
6865 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6866 struct signatured_type
);
6867 sig_type
->signature
= header
.signature
;
6868 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6869 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6870 sig_type
->per_cu
.is_debug_types
= 1;
6871 sig_type
->per_cu
.section
= section
;
6872 sig_type
->per_cu
.sect_off
= sect_off
;
6873 sig_type
->per_cu
.length
= length
;
6876 slot
= htab_find_slot (types_htab
,
6877 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6879 gdb_assert (slot
!= NULL
);
6882 sect_offset dup_sect_off
;
6886 const struct dwo_unit
*dup_tu
6887 = (const struct dwo_unit
*) *slot
;
6889 dup_sect_off
= dup_tu
->sect_off
;
6893 const struct signatured_type
*dup_tu
6894 = (const struct signatured_type
*) *slot
;
6896 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6899 complaint (_("debug type entry at offset %s is duplicate to"
6900 " the entry at offset %s, signature %s"),
6901 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6902 hex_string (header
.signature
));
6904 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6906 if (dwarf_read_debug
> 1)
6907 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6908 sect_offset_str (sect_off
),
6909 hex_string (header
.signature
));
6915 /* Create the hash table of all entries in the .debug_types
6916 (or .debug_types.dwo) section(s).
6917 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6918 otherwise it is NULL.
6920 The result is a pointer to the hash table or NULL if there are no types.
6922 Note: This function processes DWO files only, not DWP files. */
6925 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6926 struct dwo_file
*dwo_file
,
6927 gdb::array_view
<dwarf2_section_info
> type_sections
,
6930 for (dwarf2_section_info
§ion
: type_sections
)
6931 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6932 types_htab
, rcuh_kind::TYPE
);
6935 /* Create the hash table of all entries in the .debug_types section,
6936 and initialize all_type_units.
6937 The result is zero if there is an error (e.g. missing .debug_types section),
6938 otherwise non-zero. */
6941 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6943 htab_t types_htab
= NULL
;
6945 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6946 &dwarf2_per_objfile
->info
, types_htab
,
6947 rcuh_kind::COMPILE
);
6948 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6949 dwarf2_per_objfile
->types
, types_htab
);
6950 if (types_htab
== NULL
)
6952 dwarf2_per_objfile
->signatured_types
= NULL
;
6956 dwarf2_per_objfile
->signatured_types
= types_htab
;
6958 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6959 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6961 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6962 &dwarf2_per_objfile
->all_type_units
);
6967 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6968 If SLOT is non-NULL, it is the entry to use in the hash table.
6969 Otherwise we find one. */
6971 static struct signatured_type
*
6972 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6975 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6977 if (dwarf2_per_objfile
->all_type_units
.size ()
6978 == dwarf2_per_objfile
->all_type_units
.capacity ())
6979 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6981 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6982 struct signatured_type
);
6984 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6985 sig_type
->signature
= sig
;
6986 sig_type
->per_cu
.is_debug_types
= 1;
6987 if (dwarf2_per_objfile
->using_index
)
6989 sig_type
->per_cu
.v
.quick
=
6990 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6991 struct dwarf2_per_cu_quick_data
);
6996 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6999 gdb_assert (*slot
== NULL
);
7001 /* The rest of sig_type must be filled in by the caller. */
7005 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
7006 Fill in SIG_ENTRY with DWO_ENTRY. */
7009 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7010 struct signatured_type
*sig_entry
,
7011 struct dwo_unit
*dwo_entry
)
7013 /* Make sure we're not clobbering something we don't expect to. */
7014 gdb_assert (! sig_entry
->per_cu
.queued
);
7015 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
7016 if (dwarf2_per_objfile
->using_index
)
7018 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
7019 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
7022 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7023 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7024 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7025 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7026 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7028 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7029 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7030 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7031 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7032 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7033 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7034 sig_entry
->dwo_unit
= dwo_entry
;
7037 /* Subroutine of lookup_signatured_type.
7038 If we haven't read the TU yet, create the signatured_type data structure
7039 for a TU to be read in directly from a DWO file, bypassing the stub.
7040 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7041 using .gdb_index, then when reading a CU we want to stay in the DWO file
7042 containing that CU. Otherwise we could end up reading several other DWO
7043 files (due to comdat folding) to process the transitive closure of all the
7044 mentioned TUs, and that can be slow. The current DWO file will have every
7045 type signature that it needs.
7046 We only do this for .gdb_index because in the psymtab case we already have
7047 to read all the DWOs to build the type unit groups. */
7049 static struct signatured_type
*
7050 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7052 struct dwarf2_per_objfile
*dwarf2_per_objfile
7053 = cu
->per_cu
->dwarf2_per_objfile
;
7054 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7055 struct dwo_file
*dwo_file
;
7056 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7057 struct signatured_type find_sig_entry
, *sig_entry
;
7060 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7062 /* If TU skeletons have been removed then we may not have read in any
7064 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7066 dwarf2_per_objfile
->signatured_types
7067 = allocate_signatured_type_table (objfile
);
7070 /* We only ever need to read in one copy of a signatured type.
7071 Use the global signatured_types array to do our own comdat-folding
7072 of types. If this is the first time we're reading this TU, and
7073 the TU has an entry in .gdb_index, replace the recorded data from
7074 .gdb_index with this TU. */
7076 find_sig_entry
.signature
= sig
;
7077 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7078 &find_sig_entry
, INSERT
);
7079 sig_entry
= (struct signatured_type
*) *slot
;
7081 /* We can get here with the TU already read, *or* in the process of being
7082 read. Don't reassign the global entry to point to this DWO if that's
7083 the case. Also note that if the TU is already being read, it may not
7084 have come from a DWO, the program may be a mix of Fission-compiled
7085 code and non-Fission-compiled code. */
7087 /* Have we already tried to read this TU?
7088 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7089 needn't exist in the global table yet). */
7090 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7093 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7094 dwo_unit of the TU itself. */
7095 dwo_file
= cu
->dwo_unit
->dwo_file
;
7097 /* Ok, this is the first time we're reading this TU. */
7098 if (dwo_file
->tus
== NULL
)
7100 find_dwo_entry
.signature
= sig
;
7101 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7102 if (dwo_entry
== NULL
)
7105 /* If the global table doesn't have an entry for this TU, add one. */
7106 if (sig_entry
== NULL
)
7107 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7109 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7110 sig_entry
->per_cu
.tu_read
= 1;
7114 /* Subroutine of lookup_signatured_type.
7115 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7116 then try the DWP file. If the TU stub (skeleton) has been removed then
7117 it won't be in .gdb_index. */
7119 static struct signatured_type
*
7120 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7122 struct dwarf2_per_objfile
*dwarf2_per_objfile
7123 = cu
->per_cu
->dwarf2_per_objfile
;
7124 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7125 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7126 struct dwo_unit
*dwo_entry
;
7127 struct signatured_type find_sig_entry
, *sig_entry
;
7130 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7131 gdb_assert (dwp_file
!= NULL
);
7133 /* If TU skeletons have been removed then we may not have read in any
7135 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7137 dwarf2_per_objfile
->signatured_types
7138 = allocate_signatured_type_table (objfile
);
7141 find_sig_entry
.signature
= sig
;
7142 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7143 &find_sig_entry
, INSERT
);
7144 sig_entry
= (struct signatured_type
*) *slot
;
7146 /* Have we already tried to read this TU?
7147 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7148 needn't exist in the global table yet). */
7149 if (sig_entry
!= NULL
)
7152 if (dwp_file
->tus
== NULL
)
7154 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7155 sig
, 1 /* is_debug_types */);
7156 if (dwo_entry
== NULL
)
7159 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7160 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7165 /* Lookup a signature based type for DW_FORM_ref_sig8.
7166 Returns NULL if signature SIG is not present in the table.
7167 It is up to the caller to complain about this. */
7169 static struct signatured_type
*
7170 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7172 struct dwarf2_per_objfile
*dwarf2_per_objfile
7173 = cu
->per_cu
->dwarf2_per_objfile
;
7176 && dwarf2_per_objfile
->using_index
)
7178 /* We're in a DWO/DWP file, and we're using .gdb_index.
7179 These cases require special processing. */
7180 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7181 return lookup_dwo_signatured_type (cu
, sig
);
7183 return lookup_dwp_signatured_type (cu
, sig
);
7187 struct signatured_type find_entry
, *entry
;
7189 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7191 find_entry
.signature
= sig
;
7192 entry
= ((struct signatured_type
*)
7193 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7198 /* Return the address base of the compile unit, which, if exists, is stored
7199 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
7200 static gdb::optional
<ULONGEST
>
7201 lookup_addr_base (struct die_info
*comp_unit_die
)
7203 struct attribute
*attr
;
7204 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
7205 if (attr
== nullptr)
7206 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
7207 if (attr
== nullptr)
7208 return gdb::optional
<ULONGEST
> ();
7209 return DW_UNSND (attr
);
7212 /* Return range lists base of the compile unit, which, if exists, is stored
7213 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
7215 lookup_ranges_base (struct die_info
*comp_unit_die
)
7217 struct attribute
*attr
;
7218 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
7219 if (attr
== nullptr)
7220 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
7221 if (attr
== nullptr)
7223 return DW_UNSND (attr
);
7226 /* Low level DIE reading support. */
7228 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7231 init_cu_die_reader (struct die_reader_specs
*reader
,
7232 struct dwarf2_cu
*cu
,
7233 struct dwarf2_section_info
*section
,
7234 struct dwo_file
*dwo_file
,
7235 struct abbrev_table
*abbrev_table
)
7237 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7238 reader
->abfd
= get_section_bfd_owner (section
);
7240 reader
->dwo_file
= dwo_file
;
7241 reader
->die_section
= section
;
7242 reader
->buffer
= section
->buffer
;
7243 reader
->buffer_end
= section
->buffer
+ section
->size
;
7244 reader
->comp_dir
= NULL
;
7245 reader
->abbrev_table
= abbrev_table
;
7248 /* Subroutine of cutu_reader to simplify it.
7249 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7250 There's just a lot of work to do, and cutu_reader is big enough
7253 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7254 from it to the DIE in the DWO. If NULL we are skipping the stub.
7255 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7256 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7257 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7258 STUB_COMP_DIR may be non-NULL.
7259 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7260 are filled in with the info of the DIE from the DWO file.
7261 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7262 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7263 kept around for at least as long as *RESULT_READER.
7265 The result is non-zero if a valid (non-dummy) DIE was found. */
7268 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7269 struct dwo_unit
*dwo_unit
,
7270 struct die_info
*stub_comp_unit_die
,
7271 const char *stub_comp_dir
,
7272 struct die_reader_specs
*result_reader
,
7273 const gdb_byte
**result_info_ptr
,
7274 struct die_info
**result_comp_unit_die
,
7275 int *result_has_children
,
7276 abbrev_table_up
*result_dwo_abbrev_table
)
7278 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7279 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7280 struct dwarf2_cu
*cu
= this_cu
->cu
;
7282 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7283 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7284 int i
,num_extra_attrs
;
7285 struct dwarf2_section_info
*dwo_abbrev_section
;
7286 struct die_info
*comp_unit_die
;
7288 /* At most one of these may be provided. */
7289 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7291 /* These attributes aren't processed until later:
7292 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7293 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7294 referenced later. However, these attributes are found in the stub
7295 which we won't have later. In order to not impose this complication
7296 on the rest of the code, we read them here and copy them to the
7305 if (stub_comp_unit_die
!= NULL
)
7307 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7309 if (! this_cu
->is_debug_types
)
7310 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7311 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7312 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7313 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7314 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7316 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
7318 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
7319 here (if needed). We need the value before we can process
7321 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
7323 else if (stub_comp_dir
!= NULL
)
7325 /* Reconstruct the comp_dir attribute to simplify the code below. */
7326 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7327 comp_dir
->name
= DW_AT_comp_dir
;
7328 comp_dir
->form
= DW_FORM_string
;
7329 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7330 DW_STRING (comp_dir
) = stub_comp_dir
;
7333 /* Set up for reading the DWO CU/TU. */
7334 cu
->dwo_unit
= dwo_unit
;
7335 dwarf2_section_info
*section
= dwo_unit
->section
;
7336 dwarf2_read_section (objfile
, section
);
7337 abfd
= get_section_bfd_owner (section
);
7338 begin_info_ptr
= info_ptr
= (section
->buffer
7339 + to_underlying (dwo_unit
->sect_off
));
7340 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7342 if (this_cu
->is_debug_types
)
7344 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7346 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7347 &cu
->header
, section
,
7349 info_ptr
, rcuh_kind::TYPE
);
7350 /* This is not an assert because it can be caused by bad debug info. */
7351 if (sig_type
->signature
!= cu
->header
.signature
)
7353 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7354 " TU at offset %s [in module %s]"),
7355 hex_string (sig_type
->signature
),
7356 hex_string (cu
->header
.signature
),
7357 sect_offset_str (dwo_unit
->sect_off
),
7358 bfd_get_filename (abfd
));
7360 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7361 /* For DWOs coming from DWP files, we don't know the CU length
7362 nor the type's offset in the TU until now. */
7363 dwo_unit
->length
= get_cu_length (&cu
->header
);
7364 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7366 /* Establish the type offset that can be used to lookup the type.
7367 For DWO files, we don't know it until now. */
7368 sig_type
->type_offset_in_section
7369 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7373 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7374 &cu
->header
, section
,
7376 info_ptr
, rcuh_kind::COMPILE
);
7377 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7378 /* For DWOs coming from DWP files, we don't know the CU length
7380 dwo_unit
->length
= get_cu_length (&cu
->header
);
7383 *result_dwo_abbrev_table
7384 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7385 cu
->header
.abbrev_sect_off
);
7386 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7387 result_dwo_abbrev_table
->get ());
7389 /* Read in the die, but leave space to copy over the attributes
7390 from the stub. This has the benefit of simplifying the rest of
7391 the code - all the work to maintain the illusion of a single
7392 DW_TAG_{compile,type}_unit DIE is done here. */
7393 num_extra_attrs
= ((stmt_list
!= NULL
)
7397 + (comp_dir
!= NULL
));
7398 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7399 result_has_children
, num_extra_attrs
);
7401 /* Copy over the attributes from the stub to the DIE we just read in. */
7402 comp_unit_die
= *result_comp_unit_die
;
7403 i
= comp_unit_die
->num_attrs
;
7404 if (stmt_list
!= NULL
)
7405 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7407 comp_unit_die
->attrs
[i
++] = *low_pc
;
7408 if (high_pc
!= NULL
)
7409 comp_unit_die
->attrs
[i
++] = *high_pc
;
7411 comp_unit_die
->attrs
[i
++] = *ranges
;
7412 if (comp_dir
!= NULL
)
7413 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7414 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7416 if (dwarf_die_debug
)
7418 fprintf_unfiltered (gdb_stdlog
,
7419 "Read die from %s@0x%x of %s:\n",
7420 get_section_name (section
),
7421 (unsigned) (begin_info_ptr
- section
->buffer
),
7422 bfd_get_filename (abfd
));
7423 dump_die (comp_unit_die
, dwarf_die_debug
);
7426 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7427 TUs by skipping the stub and going directly to the entry in the DWO file.
7428 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7429 to get it via circuitous means. Blech. */
7430 if (comp_dir
!= NULL
)
7431 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7433 /* Skip dummy compilation units. */
7434 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7435 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7438 *result_info_ptr
= info_ptr
;
7442 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7443 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7444 signature is part of the header. */
7445 static gdb::optional
<ULONGEST
>
7446 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7448 if (cu
->header
.version
>= 5)
7449 return cu
->header
.signature
;
7450 struct attribute
*attr
;
7451 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7452 if (attr
== nullptr)
7453 return gdb::optional
<ULONGEST
> ();
7454 return DW_UNSND (attr
);
7457 /* Subroutine of cutu_reader to simplify it.
7458 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7459 Returns NULL if the specified DWO unit cannot be found. */
7461 static struct dwo_unit
*
7462 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7463 struct die_info
*comp_unit_die
,
7464 const char *dwo_name
)
7466 struct dwarf2_cu
*cu
= this_cu
->cu
;
7467 struct dwo_unit
*dwo_unit
;
7468 const char *comp_dir
;
7470 gdb_assert (cu
!= NULL
);
7472 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7473 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7474 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7476 if (this_cu
->is_debug_types
)
7478 struct signatured_type
*sig_type
;
7480 /* Since this_cu is the first member of struct signatured_type,
7481 we can go from a pointer to one to a pointer to the other. */
7482 sig_type
= (struct signatured_type
*) this_cu
;
7483 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7487 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7488 if (!signature
.has_value ())
7489 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7491 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7492 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7499 /* Subroutine of cutu_reader to simplify it.
7500 See it for a description of the parameters.
7501 Read a TU directly from a DWO file, bypassing the stub. */
7504 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7505 int use_existing_cu
, int keep
)
7507 struct signatured_type
*sig_type
;
7508 struct die_reader_specs reader
;
7510 /* Verify we can do the following downcast, and that we have the
7512 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7513 sig_type
= (struct signatured_type
*) this_cu
;
7514 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7516 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7518 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7519 /* There's no need to do the rereading_dwo_cu handling that
7520 cutu_reader does since we don't read the stub. */
7524 /* If !use_existing_cu, this_cu->cu must be NULL. */
7525 gdb_assert (this_cu
->cu
== NULL
);
7526 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7529 /* A future optimization, if needed, would be to use an existing
7530 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7531 could share abbrev tables. */
7533 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7534 NULL
/* stub_comp_unit_die */,
7535 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7537 &comp_unit_die
, &has_children
,
7538 &m_dwo_abbrev_table
) == 0)
7545 /* Initialize a CU (or TU) and read its DIEs.
7546 If the CU defers to a DWO file, read the DWO file as well.
7548 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7549 Otherwise the table specified in the comp unit header is read in and used.
7550 This is an optimization for when we already have the abbrev table.
7552 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7553 Otherwise, a new CU is allocated with xmalloc.
7555 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7556 read_in_chain. Otherwise the dwarf2_cu data is freed at the
7559 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7560 struct abbrev_table
*abbrev_table
,
7561 int use_existing_cu
, int keep
,
7563 : die_reader_specs
{},
7564 m_this_cu (this_cu
),
7567 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7568 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7569 struct dwarf2_section_info
*section
= this_cu
->section
;
7570 bfd
*abfd
= get_section_bfd_owner (section
);
7571 struct dwarf2_cu
*cu
;
7572 const gdb_byte
*begin_info_ptr
;
7573 struct signatured_type
*sig_type
= NULL
;
7574 struct dwarf2_section_info
*abbrev_section
;
7575 /* Non-zero if CU currently points to a DWO file and we need to
7576 reread it. When this happens we need to reread the skeleton die
7577 before we can reread the DWO file (this only applies to CUs, not TUs). */
7578 int rereading_dwo_cu
= 0;
7580 if (dwarf_die_debug
)
7581 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7582 this_cu
->is_debug_types
? "type" : "comp",
7583 sect_offset_str (this_cu
->sect_off
));
7585 if (use_existing_cu
)
7588 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7589 file (instead of going through the stub), short-circuit all of this. */
7590 if (this_cu
->reading_dwo_directly
)
7592 /* Narrow down the scope of possibilities to have to understand. */
7593 gdb_assert (this_cu
->is_debug_types
);
7594 gdb_assert (abbrev_table
== NULL
);
7595 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
);
7599 /* This is cheap if the section is already read in. */
7600 dwarf2_read_section (objfile
, section
);
7602 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7604 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7606 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7609 /* If this CU is from a DWO file we need to start over, we need to
7610 refetch the attributes from the skeleton CU.
7611 This could be optimized by retrieving those attributes from when we
7612 were here the first time: the previous comp_unit_die was stored in
7613 comp_unit_obstack. But there's no data yet that we need this
7615 if (cu
->dwo_unit
!= NULL
)
7616 rereading_dwo_cu
= 1;
7620 /* If !use_existing_cu, this_cu->cu must be NULL. */
7621 gdb_assert (this_cu
->cu
== NULL
);
7622 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7623 cu
= m_new_cu
.get ();
7626 /* Get the header. */
7627 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7629 /* We already have the header, there's no need to read it in again. */
7630 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7634 if (this_cu
->is_debug_types
)
7636 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7637 &cu
->header
, section
,
7638 abbrev_section
, info_ptr
,
7641 /* Since per_cu is the first member of struct signatured_type,
7642 we can go from a pointer to one to a pointer to the other. */
7643 sig_type
= (struct signatured_type
*) this_cu
;
7644 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7645 gdb_assert (sig_type
->type_offset_in_tu
7646 == cu
->header
.type_cu_offset_in_tu
);
7647 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7649 /* LENGTH has not been set yet for type units if we're
7650 using .gdb_index. */
7651 this_cu
->length
= get_cu_length (&cu
->header
);
7653 /* Establish the type offset that can be used to lookup the type. */
7654 sig_type
->type_offset_in_section
=
7655 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7657 this_cu
->dwarf_version
= cu
->header
.version
;
7661 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7662 &cu
->header
, section
,
7665 rcuh_kind::COMPILE
);
7667 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7668 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7669 this_cu
->dwarf_version
= cu
->header
.version
;
7673 /* Skip dummy compilation units. */
7674 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7675 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7681 /* If we don't have them yet, read the abbrevs for this compilation unit.
7682 And if we need to read them now, make sure they're freed when we're
7684 if (abbrev_table
!= NULL
)
7685 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7688 m_abbrev_table_holder
7689 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7690 cu
->header
.abbrev_sect_off
);
7691 abbrev_table
= m_abbrev_table_holder
.get ();
7694 /* Read the top level CU/TU die. */
7695 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7696 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
, &has_children
);
7698 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7704 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7705 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7706 table from the DWO file and pass the ownership over to us. It will be
7707 referenced from READER, so we must make sure to free it after we're done
7710 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7711 DWO CU, that this test will fail (the attribute will not be present). */
7712 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7713 if (dwo_name
!= nullptr)
7715 struct dwo_unit
*dwo_unit
;
7716 struct die_info
*dwo_comp_unit_die
;
7720 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7721 " has children (offset %s) [in module %s]"),
7722 sect_offset_str (this_cu
->sect_off
),
7723 bfd_get_filename (abfd
));
7725 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
7726 if (dwo_unit
!= NULL
)
7728 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7729 comp_unit_die
, NULL
,
7731 &dwo_comp_unit_die
, &has_children
,
7732 &m_dwo_abbrev_table
) == 0)
7738 comp_unit_die
= dwo_comp_unit_die
;
7742 /* Yikes, we couldn't find the rest of the DIE, we only have
7743 the stub. A complaint has already been logged. There's
7744 not much more we can do except pass on the stub DIE to
7745 die_reader_func. We don't want to throw an error on bad
7751 cutu_reader::~cutu_reader ()
7753 /* Done, clean up. */
7754 if (m_new_cu
!= NULL
&& m_keep
&& !dummy_p
)
7756 struct dwarf2_per_objfile
*dwarf2_per_objfile
7757 = m_this_cu
->dwarf2_per_objfile
;
7758 /* Link this CU into read_in_chain. */
7759 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7760 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
7761 /* The chain owns it now. */
7762 m_new_cu
.release ();
7766 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7767 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7768 assumed to have already done the lookup to find the DWO file).
7770 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7771 THIS_CU->is_debug_types, but nothing else.
7773 We fill in THIS_CU->length.
7775 THIS_CU->cu is always freed when done.
7776 This is done in order to not leave THIS_CU->cu in a state where we have
7777 to care whether it refers to the "main" CU or the DWO CU.
7779 When parent_cu is passed, it is used to provide a default value for
7780 str_offsets_base and addr_base from the parent. */
7782 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7783 struct dwarf2_cu
*parent_cu
,
7784 struct dwo_file
*dwo_file
)
7785 : die_reader_specs
{},
7788 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7789 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7790 struct dwarf2_section_info
*section
= this_cu
->section
;
7791 bfd
*abfd
= get_section_bfd_owner (section
);
7792 struct dwarf2_section_info
*abbrev_section
;
7793 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7796 if (dwarf_die_debug
)
7797 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7798 this_cu
->is_debug_types
? "type" : "comp",
7799 sect_offset_str (this_cu
->sect_off
));
7801 gdb_assert (this_cu
->cu
== NULL
);
7803 abbrev_section
= (dwo_file
!= NULL
7804 ? &dwo_file
->sections
.abbrev
7805 : get_abbrev_section_for_cu (this_cu
));
7807 /* This is cheap if the section is already read in. */
7808 dwarf2_read_section (objfile
, section
);
7810 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7812 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7813 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7814 &m_new_cu
->header
, section
,
7815 abbrev_section
, info_ptr
,
7816 (this_cu
->is_debug_types
7818 : rcuh_kind::COMPILE
));
7820 if (parent_cu
!= nullptr)
7822 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7823 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7825 this_cu
->length
= get_cu_length (&m_new_cu
->header
);
7827 /* Skip dummy compilation units. */
7828 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7829 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7835 m_abbrev_table_holder
7836 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7837 m_new_cu
->header
.abbrev_sect_off
);
7839 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7840 m_abbrev_table_holder
.get ());
7841 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
, &has_children
);
7845 /* Type Unit Groups.
7847 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7848 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7849 so that all types coming from the same compilation (.o file) are grouped
7850 together. A future step could be to put the types in the same symtab as
7851 the CU the types ultimately came from. */
7854 hash_type_unit_group (const void *item
)
7856 const struct type_unit_group
*tu_group
7857 = (const struct type_unit_group
*) item
;
7859 return hash_stmt_list_entry (&tu_group
->hash
);
7863 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7865 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7866 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7868 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7871 /* Allocate a hash table for type unit groups. */
7874 allocate_type_unit_groups_table (struct objfile
*objfile
)
7876 return htab_create_alloc_ex (3,
7877 hash_type_unit_group
,
7880 &objfile
->objfile_obstack
,
7881 hashtab_obstack_allocate
,
7882 dummy_obstack_deallocate
);
7885 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7886 partial symtabs. We combine several TUs per psymtab to not let the size
7887 of any one psymtab grow too big. */
7888 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7889 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7891 /* Helper routine for get_type_unit_group.
7892 Create the type_unit_group object used to hold one or more TUs. */
7894 static struct type_unit_group
*
7895 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7897 struct dwarf2_per_objfile
*dwarf2_per_objfile
7898 = cu
->per_cu
->dwarf2_per_objfile
;
7899 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7900 struct dwarf2_per_cu_data
*per_cu
;
7901 struct type_unit_group
*tu_group
;
7903 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7904 struct type_unit_group
);
7905 per_cu
= &tu_group
->per_cu
;
7906 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7908 if (dwarf2_per_objfile
->using_index
)
7910 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7911 struct dwarf2_per_cu_quick_data
);
7915 unsigned int line_offset
= to_underlying (line_offset_struct
);
7916 dwarf2_psymtab
*pst
;
7919 /* Give the symtab a useful name for debug purposes. */
7920 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7921 name
= string_printf ("<type_units_%d>",
7922 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7924 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7926 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7927 pst
->anonymous
= true;
7930 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7931 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7936 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7937 STMT_LIST is a DW_AT_stmt_list attribute. */
7939 static struct type_unit_group
*
7940 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7942 struct dwarf2_per_objfile
*dwarf2_per_objfile
7943 = cu
->per_cu
->dwarf2_per_objfile
;
7944 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7945 struct type_unit_group
*tu_group
;
7947 unsigned int line_offset
;
7948 struct type_unit_group type_unit_group_for_lookup
;
7950 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7952 dwarf2_per_objfile
->type_unit_groups
=
7953 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7956 /* Do we need to create a new group, or can we use an existing one? */
7960 line_offset
= DW_UNSND (stmt_list
);
7961 ++tu_stats
->nr_symtab_sharers
;
7965 /* Ugh, no stmt_list. Rare, but we have to handle it.
7966 We can do various things here like create one group per TU or
7967 spread them over multiple groups to split up the expansion work.
7968 To avoid worst case scenarios (too many groups or too large groups)
7969 we, umm, group them in bunches. */
7970 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7971 | (tu_stats
->nr_stmt_less_type_units
7972 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7973 ++tu_stats
->nr_stmt_less_type_units
;
7976 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7977 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7978 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7979 &type_unit_group_for_lookup
, INSERT
);
7982 tu_group
= (struct type_unit_group
*) *slot
;
7983 gdb_assert (tu_group
!= NULL
);
7987 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7988 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7990 ++tu_stats
->nr_symtabs
;
7996 /* Partial symbol tables. */
7998 /* Create a psymtab named NAME and assign it to PER_CU.
8000 The caller must fill in the following details:
8001 dirname, textlow, texthigh. */
8003 static dwarf2_psymtab
*
8004 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8006 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
8007 dwarf2_psymtab
*pst
;
8009 pst
= new dwarf2_psymtab (name
, objfile
, 0);
8011 pst
->psymtabs_addrmap_supported
= true;
8013 /* This is the glue that links PST into GDB's symbol API. */
8014 pst
->per_cu_data
= per_cu
;
8015 per_cu
->v
.psymtab
= pst
;
8020 /* DIE reader function for process_psymtab_comp_unit. */
8023 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8024 const gdb_byte
*info_ptr
,
8025 struct die_info
*comp_unit_die
,
8027 int want_partial_unit
,
8028 enum language pretend_language
)
8030 struct dwarf2_cu
*cu
= reader
->cu
;
8031 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8032 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8033 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8035 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8036 dwarf2_psymtab
*pst
;
8037 enum pc_bounds_kind cu_bounds_kind
;
8038 const char *filename
;
8040 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !want_partial_unit
)
8043 gdb_assert (! per_cu
->is_debug_types
);
8045 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
8047 /* Allocate a new partial symbol table structure. */
8048 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8049 if (filename
== NULL
)
8052 pst
= create_partial_symtab (per_cu
, filename
);
8054 /* This must be done before calling dwarf2_build_include_psymtabs. */
8055 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8057 baseaddr
= objfile
->text_section_offset ();
8059 dwarf2_find_base_address (comp_unit_die
, cu
);
8061 /* Possibly set the default values of LOWPC and HIGHPC from
8063 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8064 &best_highpc
, cu
, pst
);
8065 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8068 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
8071 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
8073 /* Store the contiguous range if it is not empty; it can be
8074 empty for CUs with no code. */
8075 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8079 /* Check if comp unit has_children.
8080 If so, read the rest of the partial symbols from this comp unit.
8081 If not, there's no more debug_info for this comp unit. */
8084 struct partial_die_info
*first_die
;
8085 CORE_ADDR lowpc
, highpc
;
8087 lowpc
= ((CORE_ADDR
) -1);
8088 highpc
= ((CORE_ADDR
) 0);
8090 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8092 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8093 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8095 /* If we didn't find a lowpc, set it to highpc to avoid
8096 complaints from `maint check'. */
8097 if (lowpc
== ((CORE_ADDR
) -1))
8100 /* If the compilation unit didn't have an explicit address range,
8101 then use the information extracted from its child dies. */
8102 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8105 best_highpc
= highpc
;
8108 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
8109 best_lowpc
+ baseaddr
)
8111 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
8112 best_highpc
+ baseaddr
)
8115 end_psymtab_common (objfile
, pst
);
8117 if (!cu
->per_cu
->imported_symtabs_empty ())
8120 int len
= cu
->per_cu
->imported_symtabs_size ();
8122 /* Fill in 'dependencies' here; we fill in 'users' in a
8124 pst
->number_of_dependencies
= len
;
8126 = objfile
->partial_symtabs
->allocate_dependencies (len
);
8127 for (i
= 0; i
< len
; ++i
)
8129 pst
->dependencies
[i
]
8130 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
8133 cu
->per_cu
->imported_symtabs_free ();
8136 /* Get the list of files included in the current compilation unit,
8137 and build a psymtab for each of them. */
8138 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8140 if (dwarf_read_debug
)
8141 fprintf_unfiltered (gdb_stdlog
,
8142 "Psymtab for %s unit @%s: %s - %s"
8143 ", %d global, %d static syms\n",
8144 per_cu
->is_debug_types
? "type" : "comp",
8145 sect_offset_str (per_cu
->sect_off
),
8146 paddress (gdbarch
, pst
->text_low (objfile
)),
8147 paddress (gdbarch
, pst
->text_high (objfile
)),
8148 pst
->n_global_syms
, pst
->n_static_syms
);
8151 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8152 Process compilation unit THIS_CU for a psymtab. */
8155 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8156 int want_partial_unit
,
8157 enum language pretend_language
)
8159 /* If this compilation unit was already read in, free the
8160 cached copy in order to read it in again. This is
8161 necessary because we skipped some symbols when we first
8162 read in the compilation unit (see load_partial_dies).
8163 This problem could be avoided, but the benefit is unclear. */
8164 if (this_cu
->cu
!= NULL
)
8165 free_one_cached_comp_unit (this_cu
);
8167 cutu_reader
reader (this_cu
, NULL
, 0, 0, false);
8173 else if (this_cu
->is_debug_types
)
8174 build_type_psymtabs_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
8175 reader
.has_children
);
8177 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
8178 reader
.comp_unit_die
,
8179 reader
.has_children
,
8183 /* Age out any secondary CUs. */
8184 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8187 /* Reader function for build_type_psymtabs. */
8190 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8191 const gdb_byte
*info_ptr
,
8192 struct die_info
*type_unit_die
,
8195 struct dwarf2_per_objfile
*dwarf2_per_objfile
8196 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8197 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8198 struct dwarf2_cu
*cu
= reader
->cu
;
8199 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8200 struct signatured_type
*sig_type
;
8201 struct type_unit_group
*tu_group
;
8202 struct attribute
*attr
;
8203 struct partial_die_info
*first_die
;
8204 CORE_ADDR lowpc
, highpc
;
8205 dwarf2_psymtab
*pst
;
8207 gdb_assert (per_cu
->is_debug_types
);
8208 sig_type
= (struct signatured_type
*) per_cu
;
8213 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8214 tu_group
= get_type_unit_group (cu
, attr
);
8216 if (tu_group
->tus
== nullptr)
8217 tu_group
->tus
= new std::vector
<signatured_type
*>;
8218 tu_group
->tus
->push_back (sig_type
);
8220 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8221 pst
= create_partial_symtab (per_cu
, "");
8222 pst
->anonymous
= true;
8224 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8226 lowpc
= (CORE_ADDR
) -1;
8227 highpc
= (CORE_ADDR
) 0;
8228 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8230 end_psymtab_common (objfile
, pst
);
8233 /* Struct used to sort TUs by their abbreviation table offset. */
8235 struct tu_abbrev_offset
8237 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8238 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8241 signatured_type
*sig_type
;
8242 sect_offset abbrev_offset
;
8245 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8248 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8249 const struct tu_abbrev_offset
&b
)
8251 return a
.abbrev_offset
< b
.abbrev_offset
;
8254 /* Efficiently read all the type units.
8255 This does the bulk of the work for build_type_psymtabs.
8257 The efficiency is because we sort TUs by the abbrev table they use and
8258 only read each abbrev table once. In one program there are 200K TUs
8259 sharing 8K abbrev tables.
8261 The main purpose of this function is to support building the
8262 dwarf2_per_objfile->type_unit_groups table.
8263 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8264 can collapse the search space by grouping them by stmt_list.
8265 The savings can be significant, in the same program from above the 200K TUs
8266 share 8K stmt_list tables.
8268 FUNC is expected to call get_type_unit_group, which will create the
8269 struct type_unit_group if necessary and add it to
8270 dwarf2_per_objfile->type_unit_groups. */
8273 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8275 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8276 abbrev_table_up abbrev_table
;
8277 sect_offset abbrev_offset
;
8279 /* It's up to the caller to not call us multiple times. */
8280 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8282 if (dwarf2_per_objfile
->all_type_units
.empty ())
8285 /* TUs typically share abbrev tables, and there can be way more TUs than
8286 abbrev tables. Sort by abbrev table to reduce the number of times we
8287 read each abbrev table in.
8288 Alternatives are to punt or to maintain a cache of abbrev tables.
8289 This is simpler and efficient enough for now.
8291 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8292 symtab to use). Typically TUs with the same abbrev offset have the same
8293 stmt_list value too so in practice this should work well.
8295 The basic algorithm here is:
8297 sort TUs by abbrev table
8298 for each TU with same abbrev table:
8299 read abbrev table if first user
8300 read TU top level DIE
8301 [IWBN if DWO skeletons had DW_AT_stmt_list]
8304 if (dwarf_read_debug
)
8305 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8307 /* Sort in a separate table to maintain the order of all_type_units
8308 for .gdb_index: TU indices directly index all_type_units. */
8309 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8310 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8312 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8313 sorted_by_abbrev
.emplace_back
8314 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8315 sig_type
->per_cu
.section
,
8316 sig_type
->per_cu
.sect_off
));
8318 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8319 sort_tu_by_abbrev_offset
);
8321 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8323 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8325 /* Switch to the next abbrev table if necessary. */
8326 if (abbrev_table
== NULL
8327 || tu
.abbrev_offset
!= abbrev_offset
)
8329 abbrev_offset
= tu
.abbrev_offset
;
8331 abbrev_table_read_table (dwarf2_per_objfile
,
8332 &dwarf2_per_objfile
->abbrev
,
8334 ++tu_stats
->nr_uniq_abbrev_tables
;
8337 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8339 if (!reader
.dummy_p
)
8340 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8341 reader
.comp_unit_die
,
8342 reader
.has_children
);
8346 /* Print collected type unit statistics. */
8349 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8351 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8353 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8354 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8355 dwarf2_per_objfile
->all_type_units
.size ());
8356 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8357 tu_stats
->nr_uniq_abbrev_tables
);
8358 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8359 tu_stats
->nr_symtabs
);
8360 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8361 tu_stats
->nr_symtab_sharers
);
8362 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8363 tu_stats
->nr_stmt_less_type_units
);
8364 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8365 tu_stats
->nr_all_type_units_reallocs
);
8368 /* Traversal function for build_type_psymtabs. */
8371 build_type_psymtab_dependencies (void **slot
, void *info
)
8373 struct dwarf2_per_objfile
*dwarf2_per_objfile
8374 = (struct dwarf2_per_objfile
*) info
;
8375 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8376 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8377 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8378 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8379 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8382 gdb_assert (len
> 0);
8383 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8385 pst
->number_of_dependencies
= len
;
8386 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8387 for (i
= 0; i
< len
; ++i
)
8389 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8390 gdb_assert (iter
->per_cu
.is_debug_types
);
8391 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8392 iter
->type_unit_group
= tu_group
;
8395 delete tu_group
->tus
;
8396 tu_group
->tus
= nullptr;
8401 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8402 Build partial symbol tables for the .debug_types comp-units. */
8405 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8407 if (! create_all_type_units (dwarf2_per_objfile
))
8410 build_type_psymtabs_1 (dwarf2_per_objfile
);
8413 /* Traversal function for process_skeletonless_type_unit.
8414 Read a TU in a DWO file and build partial symbols for it. */
8417 process_skeletonless_type_unit (void **slot
, void *info
)
8419 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8420 struct dwarf2_per_objfile
*dwarf2_per_objfile
8421 = (struct dwarf2_per_objfile
*) info
;
8422 struct signatured_type find_entry
, *entry
;
8424 /* If this TU doesn't exist in the global table, add it and read it in. */
8426 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8428 dwarf2_per_objfile
->signatured_types
8429 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8432 find_entry
.signature
= dwo_unit
->signature
;
8433 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8435 /* If we've already seen this type there's nothing to do. What's happening
8436 is we're doing our own version of comdat-folding here. */
8440 /* This does the job that create_all_type_units would have done for
8442 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8443 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8446 /* This does the job that build_type_psymtabs_1 would have done. */
8447 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, 0, false);
8448 if (!reader
.dummy_p
)
8449 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8450 reader
.comp_unit_die
, reader
.has_children
);
8455 /* Traversal function for process_skeletonless_type_units. */
8458 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8460 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8462 if (dwo_file
->tus
!= NULL
)
8464 htab_traverse_noresize (dwo_file
->tus
,
8465 process_skeletonless_type_unit
, info
);
8471 /* Scan all TUs of DWO files, verifying we've processed them.
8472 This is needed in case a TU was emitted without its skeleton.
8473 Note: This can't be done until we know what all the DWO files are. */
8476 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8478 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8479 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8480 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8482 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8483 process_dwo_file_for_skeletonless_type_units
,
8484 dwarf2_per_objfile
);
8488 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8491 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8493 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8495 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8500 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8502 /* Set the 'user' field only if it is not already set. */
8503 if (pst
->dependencies
[j
]->user
== NULL
)
8504 pst
->dependencies
[j
]->user
= pst
;
8509 /* Build the partial symbol table by doing a quick pass through the
8510 .debug_info and .debug_abbrev sections. */
8513 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8515 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8517 if (dwarf_read_debug
)
8519 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8520 objfile_name (objfile
));
8523 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8525 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8527 /* Any cached compilation units will be linked by the per-objfile
8528 read_in_chain. Make sure to free them when we're done. */
8529 free_cached_comp_units
freer (dwarf2_per_objfile
);
8531 build_type_psymtabs (dwarf2_per_objfile
);
8533 create_all_comp_units (dwarf2_per_objfile
);
8535 /* Create a temporary address map on a temporary obstack. We later
8536 copy this to the final obstack. */
8537 auto_obstack temp_obstack
;
8539 scoped_restore save_psymtabs_addrmap
8540 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8541 addrmap_create_mutable (&temp_obstack
));
8543 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8544 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8546 /* This has to wait until we read the CUs, we need the list of DWOs. */
8547 process_skeletonless_type_units (dwarf2_per_objfile
);
8549 /* Now that all TUs have been processed we can fill in the dependencies. */
8550 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8552 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8553 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8556 if (dwarf_read_debug
)
8557 print_tu_stats (dwarf2_per_objfile
);
8559 set_partial_user (dwarf2_per_objfile
);
8561 objfile
->partial_symtabs
->psymtabs_addrmap
8562 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8563 objfile
->partial_symtabs
->obstack ());
8564 /* At this point we want to keep the address map. */
8565 save_psymtabs_addrmap
.release ();
8567 if (dwarf_read_debug
)
8568 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8569 objfile_name (objfile
));
8572 /* Load the partial DIEs for a secondary CU into memory.
8573 This is also used when rereading a primary CU with load_all_dies. */
8576 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8578 cutu_reader
reader (this_cu
, NULL
, 1, 1, false);
8580 if (!reader
.dummy_p
)
8582 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8585 /* Check if comp unit has_children.
8586 If so, read the rest of the partial symbols from this comp unit.
8587 If not, there's no more debug_info for this comp unit. */
8588 if (reader
.has_children
)
8589 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8594 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8595 struct dwarf2_section_info
*section
,
8596 struct dwarf2_section_info
*abbrev_section
,
8597 unsigned int is_dwz
)
8599 const gdb_byte
*info_ptr
;
8600 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8602 if (dwarf_read_debug
)
8603 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8604 get_section_name (section
),
8605 get_section_file_name (section
));
8607 dwarf2_read_section (objfile
, section
);
8609 info_ptr
= section
->buffer
;
8611 while (info_ptr
< section
->buffer
+ section
->size
)
8613 struct dwarf2_per_cu_data
*this_cu
;
8615 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8617 comp_unit_head cu_header
;
8618 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8619 abbrev_section
, info_ptr
,
8620 rcuh_kind::COMPILE
);
8622 /* Save the compilation unit for later lookup. */
8623 if (cu_header
.unit_type
!= DW_UT_type
)
8625 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8626 struct dwarf2_per_cu_data
);
8627 memset (this_cu
, 0, sizeof (*this_cu
));
8631 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8632 struct signatured_type
);
8633 memset (sig_type
, 0, sizeof (*sig_type
));
8634 sig_type
->signature
= cu_header
.signature
;
8635 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8636 this_cu
= &sig_type
->per_cu
;
8638 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8639 this_cu
->sect_off
= sect_off
;
8640 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8641 this_cu
->is_dwz
= is_dwz
;
8642 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8643 this_cu
->section
= section
;
8645 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8647 info_ptr
= info_ptr
+ this_cu
->length
;
8651 /* Create a list of all compilation units in OBJFILE.
8652 This is only done for -readnow and building partial symtabs. */
8655 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8657 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8658 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8659 &dwarf2_per_objfile
->abbrev
, 0);
8661 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8663 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8667 /* Process all loaded DIEs for compilation unit CU, starting at
8668 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8669 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8670 DW_AT_ranges). See the comments of add_partial_subprogram on how
8671 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8674 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8675 CORE_ADDR
*highpc
, int set_addrmap
,
8676 struct dwarf2_cu
*cu
)
8678 struct partial_die_info
*pdi
;
8680 /* Now, march along the PDI's, descending into ones which have
8681 interesting children but skipping the children of the other ones,
8682 until we reach the end of the compilation unit. */
8690 /* Anonymous namespaces or modules have no name but have interesting
8691 children, so we need to look at them. Ditto for anonymous
8694 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8695 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8696 || pdi
->tag
== DW_TAG_imported_unit
8697 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8701 case DW_TAG_subprogram
:
8702 case DW_TAG_inlined_subroutine
:
8703 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8705 case DW_TAG_constant
:
8706 case DW_TAG_variable
:
8707 case DW_TAG_typedef
:
8708 case DW_TAG_union_type
:
8709 if (!pdi
->is_declaration
)
8711 add_partial_symbol (pdi
, cu
);
8714 case DW_TAG_class_type
:
8715 case DW_TAG_interface_type
:
8716 case DW_TAG_structure_type
:
8717 if (!pdi
->is_declaration
)
8719 add_partial_symbol (pdi
, cu
);
8721 if ((cu
->language
== language_rust
8722 || cu
->language
== language_cplus
) && pdi
->has_children
)
8723 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8726 case DW_TAG_enumeration_type
:
8727 if (!pdi
->is_declaration
)
8728 add_partial_enumeration (pdi
, cu
);
8730 case DW_TAG_base_type
:
8731 case DW_TAG_subrange_type
:
8732 /* File scope base type definitions are added to the partial
8734 add_partial_symbol (pdi
, cu
);
8736 case DW_TAG_namespace
:
8737 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8740 if (!pdi
->is_declaration
)
8741 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8743 case DW_TAG_imported_unit
:
8745 struct dwarf2_per_cu_data
*per_cu
;
8747 /* For now we don't handle imported units in type units. */
8748 if (cu
->per_cu
->is_debug_types
)
8750 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8751 " supported in type units [in module %s]"),
8752 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8755 per_cu
= dwarf2_find_containing_comp_unit
8756 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8757 cu
->per_cu
->dwarf2_per_objfile
);
8759 /* Go read the partial unit, if needed. */
8760 if (per_cu
->v
.psymtab
== NULL
)
8761 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8763 cu
->per_cu
->imported_symtabs_push (per_cu
);
8766 case DW_TAG_imported_declaration
:
8767 add_partial_symbol (pdi
, cu
);
8774 /* If the die has a sibling, skip to the sibling. */
8776 pdi
= pdi
->die_sibling
;
8780 /* Functions used to compute the fully scoped name of a partial DIE.
8782 Normally, this is simple. For C++, the parent DIE's fully scoped
8783 name is concatenated with "::" and the partial DIE's name.
8784 Enumerators are an exception; they use the scope of their parent
8785 enumeration type, i.e. the name of the enumeration type is not
8786 prepended to the enumerator.
8788 There are two complexities. One is DW_AT_specification; in this
8789 case "parent" means the parent of the target of the specification,
8790 instead of the direct parent of the DIE. The other is compilers
8791 which do not emit DW_TAG_namespace; in this case we try to guess
8792 the fully qualified name of structure types from their members'
8793 linkage names. This must be done using the DIE's children rather
8794 than the children of any DW_AT_specification target. We only need
8795 to do this for structures at the top level, i.e. if the target of
8796 any DW_AT_specification (if any; otherwise the DIE itself) does not
8799 /* Compute the scope prefix associated with PDI's parent, in
8800 compilation unit CU. The result will be allocated on CU's
8801 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8802 field. NULL is returned if no prefix is necessary. */
8804 partial_die_parent_scope (struct partial_die_info
*pdi
,
8805 struct dwarf2_cu
*cu
)
8807 const char *grandparent_scope
;
8808 struct partial_die_info
*parent
, *real_pdi
;
8810 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8811 then this means the parent of the specification DIE. */
8814 while (real_pdi
->has_specification
)
8816 auto res
= find_partial_die (real_pdi
->spec_offset
,
8817 real_pdi
->spec_is_dwz
, cu
);
8822 parent
= real_pdi
->die_parent
;
8826 if (parent
->scope_set
)
8827 return parent
->scope
;
8831 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8833 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8834 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8835 Work around this problem here. */
8836 if (cu
->language
== language_cplus
8837 && parent
->tag
== DW_TAG_namespace
8838 && strcmp (parent
->name
, "::") == 0
8839 && grandparent_scope
== NULL
)
8841 parent
->scope
= NULL
;
8842 parent
->scope_set
= 1;
8846 /* Nested subroutines in Fortran get a prefix. */
8847 if (pdi
->tag
== DW_TAG_enumerator
)
8848 /* Enumerators should not get the name of the enumeration as a prefix. */
8849 parent
->scope
= grandparent_scope
;
8850 else if (parent
->tag
== DW_TAG_namespace
8851 || parent
->tag
== DW_TAG_module
8852 || parent
->tag
== DW_TAG_structure_type
8853 || parent
->tag
== DW_TAG_class_type
8854 || parent
->tag
== DW_TAG_interface_type
8855 || parent
->tag
== DW_TAG_union_type
8856 || parent
->tag
== DW_TAG_enumeration_type
8857 || (cu
->language
== language_fortran
8858 && parent
->tag
== DW_TAG_subprogram
8859 && pdi
->tag
== DW_TAG_subprogram
))
8861 if (grandparent_scope
== NULL
)
8862 parent
->scope
= parent
->name
;
8864 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8866 parent
->name
, 0, cu
);
8870 /* FIXME drow/2004-04-01: What should we be doing with
8871 function-local names? For partial symbols, we should probably be
8873 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8874 dwarf_tag_name (parent
->tag
),
8875 sect_offset_str (pdi
->sect_off
));
8876 parent
->scope
= grandparent_scope
;
8879 parent
->scope_set
= 1;
8880 return parent
->scope
;
8883 /* Return the fully scoped name associated with PDI, from compilation unit
8884 CU. The result will be allocated with malloc. */
8886 static gdb::unique_xmalloc_ptr
<char>
8887 partial_die_full_name (struct partial_die_info
*pdi
,
8888 struct dwarf2_cu
*cu
)
8890 const char *parent_scope
;
8892 /* If this is a template instantiation, we can not work out the
8893 template arguments from partial DIEs. So, unfortunately, we have
8894 to go through the full DIEs. At least any work we do building
8895 types here will be reused if full symbols are loaded later. */
8896 if (pdi
->has_template_arguments
)
8900 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8902 struct die_info
*die
;
8903 struct attribute attr
;
8904 struct dwarf2_cu
*ref_cu
= cu
;
8906 /* DW_FORM_ref_addr is using section offset. */
8907 attr
.name
= (enum dwarf_attribute
) 0;
8908 attr
.form
= DW_FORM_ref_addr
;
8909 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8910 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8912 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8916 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8917 if (parent_scope
== NULL
)
8920 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8925 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8927 struct dwarf2_per_objfile
*dwarf2_per_objfile
8928 = cu
->per_cu
->dwarf2_per_objfile
;
8929 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8930 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8932 const char *actual_name
= NULL
;
8935 baseaddr
= objfile
->text_section_offset ();
8937 gdb::unique_xmalloc_ptr
<char> built_actual_name
8938 = partial_die_full_name (pdi
, cu
);
8939 if (built_actual_name
!= NULL
)
8940 actual_name
= built_actual_name
.get ();
8942 if (actual_name
== NULL
)
8943 actual_name
= pdi
->name
;
8947 case DW_TAG_inlined_subroutine
:
8948 case DW_TAG_subprogram
:
8949 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8951 if (pdi
->is_external
8952 || cu
->language
== language_ada
8953 || (cu
->language
== language_fortran
8954 && pdi
->die_parent
!= NULL
8955 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8957 /* Normally, only "external" DIEs are part of the global scope.
8958 But in Ada and Fortran, we want to be able to access nested
8959 procedures globally. So all Ada and Fortran subprograms are
8960 stored in the global scope. */
8961 add_psymbol_to_list (actual_name
,
8962 built_actual_name
!= NULL
,
8963 VAR_DOMAIN
, LOC_BLOCK
,
8964 SECT_OFF_TEXT (objfile
),
8965 psymbol_placement::GLOBAL
,
8967 cu
->language
, objfile
);
8971 add_psymbol_to_list (actual_name
,
8972 built_actual_name
!= NULL
,
8973 VAR_DOMAIN
, LOC_BLOCK
,
8974 SECT_OFF_TEXT (objfile
),
8975 psymbol_placement::STATIC
,
8976 addr
, cu
->language
, objfile
);
8979 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8980 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8982 case DW_TAG_constant
:
8983 add_psymbol_to_list (actual_name
,
8984 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8985 -1, (pdi
->is_external
8986 ? psymbol_placement::GLOBAL
8987 : psymbol_placement::STATIC
),
8988 0, cu
->language
, objfile
);
8990 case DW_TAG_variable
:
8992 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8996 && !dwarf2_per_objfile
->has_section_at_zero
)
8998 /* A global or static variable may also have been stripped
8999 out by the linker if unused, in which case its address
9000 will be nullified; do not add such variables into partial
9001 symbol table then. */
9003 else if (pdi
->is_external
)
9006 Don't enter into the minimal symbol tables as there is
9007 a minimal symbol table entry from the ELF symbols already.
9008 Enter into partial symbol table if it has a location
9009 descriptor or a type.
9010 If the location descriptor is missing, new_symbol will create
9011 a LOC_UNRESOLVED symbol, the address of the variable will then
9012 be determined from the minimal symbol table whenever the variable
9014 The address for the partial symbol table entry is not
9015 used by GDB, but it comes in handy for debugging partial symbol
9018 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9019 add_psymbol_to_list (actual_name
,
9020 built_actual_name
!= NULL
,
9021 VAR_DOMAIN
, LOC_STATIC
,
9022 SECT_OFF_TEXT (objfile
),
9023 psymbol_placement::GLOBAL
,
9024 addr
, cu
->language
, objfile
);
9028 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9030 /* Static Variable. Skip symbols whose value we cannot know (those
9031 without location descriptors or constant values). */
9032 if (!has_loc
&& !pdi
->has_const_value
)
9035 add_psymbol_to_list (actual_name
,
9036 built_actual_name
!= NULL
,
9037 VAR_DOMAIN
, LOC_STATIC
,
9038 SECT_OFF_TEXT (objfile
),
9039 psymbol_placement::STATIC
,
9041 cu
->language
, objfile
);
9044 case DW_TAG_typedef
:
9045 case DW_TAG_base_type
:
9046 case DW_TAG_subrange_type
:
9047 add_psymbol_to_list (actual_name
,
9048 built_actual_name
!= NULL
,
9049 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9050 psymbol_placement::STATIC
,
9051 0, cu
->language
, objfile
);
9053 case DW_TAG_imported_declaration
:
9054 case DW_TAG_namespace
:
9055 add_psymbol_to_list (actual_name
,
9056 built_actual_name
!= NULL
,
9057 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9058 psymbol_placement::GLOBAL
,
9059 0, cu
->language
, objfile
);
9062 /* With Fortran 77 there might be a "BLOCK DATA" module
9063 available without any name. If so, we skip the module as it
9064 doesn't bring any value. */
9065 if (actual_name
!= nullptr)
9066 add_psymbol_to_list (actual_name
,
9067 built_actual_name
!= NULL
,
9068 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
9069 psymbol_placement::GLOBAL
,
9070 0, cu
->language
, objfile
);
9072 case DW_TAG_class_type
:
9073 case DW_TAG_interface_type
:
9074 case DW_TAG_structure_type
:
9075 case DW_TAG_union_type
:
9076 case DW_TAG_enumeration_type
:
9077 /* Skip external references. The DWARF standard says in the section
9078 about "Structure, Union, and Class Type Entries": "An incomplete
9079 structure, union or class type is represented by a structure,
9080 union or class entry that does not have a byte size attribute
9081 and that has a DW_AT_declaration attribute." */
9082 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9085 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9086 static vs. global. */
9087 add_psymbol_to_list (actual_name
,
9088 built_actual_name
!= NULL
,
9089 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
9090 cu
->language
== language_cplus
9091 ? psymbol_placement::GLOBAL
9092 : psymbol_placement::STATIC
,
9093 0, cu
->language
, objfile
);
9096 case DW_TAG_enumerator
:
9097 add_psymbol_to_list (actual_name
,
9098 built_actual_name
!= NULL
,
9099 VAR_DOMAIN
, LOC_CONST
, -1,
9100 cu
->language
== language_cplus
9101 ? psymbol_placement::GLOBAL
9102 : psymbol_placement::STATIC
,
9103 0, cu
->language
, objfile
);
9110 /* Read a partial die corresponding to a namespace; also, add a symbol
9111 corresponding to that namespace to the symbol table. NAMESPACE is
9112 the name of the enclosing namespace. */
9115 add_partial_namespace (struct partial_die_info
*pdi
,
9116 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9117 int set_addrmap
, struct dwarf2_cu
*cu
)
9119 /* Add a symbol for the namespace. */
9121 add_partial_symbol (pdi
, cu
);
9123 /* Now scan partial symbols in that namespace. */
9125 if (pdi
->has_children
)
9126 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9129 /* Read a partial die corresponding to a Fortran module. */
9132 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9133 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9135 /* Add a symbol for the namespace. */
9137 add_partial_symbol (pdi
, cu
);
9139 /* Now scan partial symbols in that module. */
9141 if (pdi
->has_children
)
9142 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9145 /* Read a partial die corresponding to a subprogram or an inlined
9146 subprogram and create a partial symbol for that subprogram.
9147 When the CU language allows it, this routine also defines a partial
9148 symbol for each nested subprogram that this subprogram contains.
9149 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9150 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9152 PDI may also be a lexical block, in which case we simply search
9153 recursively for subprograms defined inside that lexical block.
9154 Again, this is only performed when the CU language allows this
9155 type of definitions. */
9158 add_partial_subprogram (struct partial_die_info
*pdi
,
9159 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9160 int set_addrmap
, struct dwarf2_cu
*cu
)
9162 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9164 if (pdi
->has_pc_info
)
9166 if (pdi
->lowpc
< *lowpc
)
9167 *lowpc
= pdi
->lowpc
;
9168 if (pdi
->highpc
> *highpc
)
9169 *highpc
= pdi
->highpc
;
9172 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9173 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9175 CORE_ADDR this_highpc
;
9176 CORE_ADDR this_lowpc
;
9178 baseaddr
= objfile
->text_section_offset ();
9180 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9181 pdi
->lowpc
+ baseaddr
)
9184 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9185 pdi
->highpc
+ baseaddr
)
9187 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
9188 this_lowpc
, this_highpc
- 1,
9189 cu
->per_cu
->v
.psymtab
);
9193 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9195 if (!pdi
->is_declaration
)
9196 /* Ignore subprogram DIEs that do not have a name, they are
9197 illegal. Do not emit a complaint at this point, we will
9198 do so when we convert this psymtab into a symtab. */
9200 add_partial_symbol (pdi
, cu
);
9204 if (! pdi
->has_children
)
9207 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
9209 pdi
= pdi
->die_child
;
9213 if (pdi
->tag
== DW_TAG_subprogram
9214 || pdi
->tag
== DW_TAG_inlined_subroutine
9215 || pdi
->tag
== DW_TAG_lexical_block
)
9216 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9217 pdi
= pdi
->die_sibling
;
9222 /* Read a partial die corresponding to an enumeration type. */
9225 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9226 struct dwarf2_cu
*cu
)
9228 struct partial_die_info
*pdi
;
9230 if (enum_pdi
->name
!= NULL
)
9231 add_partial_symbol (enum_pdi
, cu
);
9233 pdi
= enum_pdi
->die_child
;
9236 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9237 complaint (_("malformed enumerator DIE ignored"));
9239 add_partial_symbol (pdi
, cu
);
9240 pdi
= pdi
->die_sibling
;
9244 /* Return the initial uleb128 in the die at INFO_PTR. */
9247 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9249 unsigned int bytes_read
;
9251 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9254 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9255 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9257 Return the corresponding abbrev, or NULL if the number is zero (indicating
9258 an empty DIE). In either case *BYTES_READ will be set to the length of
9259 the initial number. */
9261 static struct abbrev_info
*
9262 peek_die_abbrev (const die_reader_specs
&reader
,
9263 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9265 dwarf2_cu
*cu
= reader
.cu
;
9266 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9267 unsigned int abbrev_number
9268 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9270 if (abbrev_number
== 0)
9273 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9276 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9277 " at offset %s [in module %s]"),
9278 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9279 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9285 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9286 Returns a pointer to the end of a series of DIEs, terminated by an empty
9287 DIE. Any children of the skipped DIEs will also be skipped. */
9289 static const gdb_byte
*
9290 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9294 unsigned int bytes_read
;
9295 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9298 return info_ptr
+ bytes_read
;
9300 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9304 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9305 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9306 abbrev corresponding to that skipped uleb128 should be passed in
9307 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9310 static const gdb_byte
*
9311 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9312 struct abbrev_info
*abbrev
)
9314 unsigned int bytes_read
;
9315 struct attribute attr
;
9316 bfd
*abfd
= reader
->abfd
;
9317 struct dwarf2_cu
*cu
= reader
->cu
;
9318 const gdb_byte
*buffer
= reader
->buffer
;
9319 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9320 unsigned int form
, i
;
9322 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9324 /* The only abbrev we care about is DW_AT_sibling. */
9325 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9328 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
9330 if (attr
.form
== DW_FORM_ref_addr
)
9331 complaint (_("ignoring absolute DW_AT_sibling"));
9334 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9335 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9337 if (sibling_ptr
< info_ptr
)
9338 complaint (_("DW_AT_sibling points backwards"));
9339 else if (sibling_ptr
> reader
->buffer_end
)
9340 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9346 /* If it isn't DW_AT_sibling, skip this attribute. */
9347 form
= abbrev
->attrs
[i
].form
;
9351 case DW_FORM_ref_addr
:
9352 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9353 and later it is offset sized. */
9354 if (cu
->header
.version
== 2)
9355 info_ptr
+= cu
->header
.addr_size
;
9357 info_ptr
+= cu
->header
.offset_size
;
9359 case DW_FORM_GNU_ref_alt
:
9360 info_ptr
+= cu
->header
.offset_size
;
9363 info_ptr
+= cu
->header
.addr_size
;
9371 case DW_FORM_flag_present
:
9372 case DW_FORM_implicit_const
:
9389 case DW_FORM_ref_sig8
:
9392 case DW_FORM_data16
:
9395 case DW_FORM_string
:
9396 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9397 info_ptr
+= bytes_read
;
9399 case DW_FORM_sec_offset
:
9401 case DW_FORM_GNU_strp_alt
:
9402 info_ptr
+= cu
->header
.offset_size
;
9404 case DW_FORM_exprloc
:
9406 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9407 info_ptr
+= bytes_read
;
9409 case DW_FORM_block1
:
9410 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9412 case DW_FORM_block2
:
9413 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9415 case DW_FORM_block4
:
9416 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9422 case DW_FORM_ref_udata
:
9423 case DW_FORM_GNU_addr_index
:
9424 case DW_FORM_GNU_str_index
:
9425 case DW_FORM_rnglistx
:
9426 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9428 case DW_FORM_indirect
:
9429 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9430 info_ptr
+= bytes_read
;
9431 /* We need to continue parsing from here, so just go back to
9433 goto skip_attribute
;
9436 error (_("Dwarf Error: Cannot handle %s "
9437 "in DWARF reader [in module %s]"),
9438 dwarf_form_name (form
),
9439 bfd_get_filename (abfd
));
9443 if (abbrev
->has_children
)
9444 return skip_children (reader
, info_ptr
);
9449 /* Locate ORIG_PDI's sibling.
9450 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9452 static const gdb_byte
*
9453 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9454 struct partial_die_info
*orig_pdi
,
9455 const gdb_byte
*info_ptr
)
9457 /* Do we know the sibling already? */
9459 if (orig_pdi
->sibling
)
9460 return orig_pdi
->sibling
;
9462 /* Are there any children to deal with? */
9464 if (!orig_pdi
->has_children
)
9467 /* Skip the children the long way. */
9469 return skip_children (reader
, info_ptr
);
9472 /* Expand this partial symbol table into a full symbol table. SELF is
9476 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
9478 struct dwarf2_per_objfile
*dwarf2_per_objfile
9479 = get_dwarf2_per_objfile (objfile
);
9481 gdb_assert (!readin
);
9482 /* If this psymtab is constructed from a debug-only objfile, the
9483 has_section_at_zero flag will not necessarily be correct. We
9484 can get the correct value for this flag by looking at the data
9485 associated with the (presumably stripped) associated objfile. */
9486 if (objfile
->separate_debug_objfile_backlink
)
9488 struct dwarf2_per_objfile
*dpo_backlink
9489 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9491 dwarf2_per_objfile
->has_section_at_zero
9492 = dpo_backlink
->has_section_at_zero
;
9495 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9497 expand_psymtab (objfile
);
9499 process_cu_includes (dwarf2_per_objfile
);
9502 /* Reading in full CUs. */
9504 /* Add PER_CU to the queue. */
9507 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9508 enum language pretend_language
)
9510 struct dwarf2_queue_item
*item
;
9513 item
= XNEW (struct dwarf2_queue_item
);
9514 item
->per_cu
= per_cu
;
9515 item
->pretend_language
= pretend_language
;
9518 if (dwarf2_queue
== NULL
)
9519 dwarf2_queue
= item
;
9521 dwarf2_queue_tail
->next
= item
;
9523 dwarf2_queue_tail
= item
;
9526 /* If PER_CU is not yet queued, add it to the queue.
9527 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9529 The result is non-zero if PER_CU was queued, otherwise the result is zero
9530 meaning either PER_CU is already queued or it is already loaded.
9532 N.B. There is an invariant here that if a CU is queued then it is loaded.
9533 The caller is required to load PER_CU if we return non-zero. */
9536 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9537 struct dwarf2_per_cu_data
*per_cu
,
9538 enum language pretend_language
)
9540 /* We may arrive here during partial symbol reading, if we need full
9541 DIEs to process an unusual case (e.g. template arguments). Do
9542 not queue PER_CU, just tell our caller to load its DIEs. */
9543 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9545 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9550 /* Mark the dependence relation so that we don't flush PER_CU
9552 if (dependent_cu
!= NULL
)
9553 dwarf2_add_dependence (dependent_cu
, per_cu
);
9555 /* If it's already on the queue, we have nothing to do. */
9559 /* If the compilation unit is already loaded, just mark it as
9561 if (per_cu
->cu
!= NULL
)
9563 per_cu
->cu
->last_used
= 0;
9567 /* Add it to the queue. */
9568 queue_comp_unit (per_cu
, pretend_language
);
9573 /* Process the queue. */
9576 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9578 struct dwarf2_queue_item
*item
, *next_item
;
9580 if (dwarf_read_debug
)
9582 fprintf_unfiltered (gdb_stdlog
,
9583 "Expanding one or more symtabs of objfile %s ...\n",
9584 objfile_name (dwarf2_per_objfile
->objfile
));
9587 /* The queue starts out with one item, but following a DIE reference
9588 may load a new CU, adding it to the end of the queue. */
9589 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9591 if ((dwarf2_per_objfile
->using_index
9592 ? !item
->per_cu
->v
.quick
->compunit_symtab
9593 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9594 /* Skip dummy CUs. */
9595 && item
->per_cu
->cu
!= NULL
)
9597 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9598 unsigned int debug_print_threshold
;
9601 if (per_cu
->is_debug_types
)
9603 struct signatured_type
*sig_type
=
9604 (struct signatured_type
*) per_cu
;
9606 sprintf (buf
, "TU %s at offset %s",
9607 hex_string (sig_type
->signature
),
9608 sect_offset_str (per_cu
->sect_off
));
9609 /* There can be 100s of TUs.
9610 Only print them in verbose mode. */
9611 debug_print_threshold
= 2;
9615 sprintf (buf
, "CU at offset %s",
9616 sect_offset_str (per_cu
->sect_off
));
9617 debug_print_threshold
= 1;
9620 if (dwarf_read_debug
>= debug_print_threshold
)
9621 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9623 if (per_cu
->is_debug_types
)
9624 process_full_type_unit (per_cu
, item
->pretend_language
);
9626 process_full_comp_unit (per_cu
, item
->pretend_language
);
9628 if (dwarf_read_debug
>= debug_print_threshold
)
9629 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9632 item
->per_cu
->queued
= 0;
9633 next_item
= item
->next
;
9637 dwarf2_queue_tail
= NULL
;
9639 if (dwarf_read_debug
)
9641 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9642 objfile_name (dwarf2_per_objfile
->objfile
));
9646 /* Read in full symbols for PST, and anything it depends on. */
9649 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9651 struct dwarf2_per_cu_data
*per_cu
;
9656 read_dependencies (objfile
);
9658 per_cu
= per_cu_data
;
9662 /* It's an include file, no symbols to read for it.
9663 Everything is in the parent symtab. */
9668 dw2_do_instantiate_symtab (per_cu
, false);
9671 /* Trivial hash function for die_info: the hash value of a DIE
9672 is its offset in .debug_info for this objfile. */
9675 die_hash (const void *item
)
9677 const struct die_info
*die
= (const struct die_info
*) item
;
9679 return to_underlying (die
->sect_off
);
9682 /* Trivial comparison function for die_info structures: two DIEs
9683 are equal if they have the same offset. */
9686 die_eq (const void *item_lhs
, const void *item_rhs
)
9688 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9689 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9691 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9694 /* Load the DIEs associated with PER_CU into memory. */
9697 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9699 enum language pretend_language
)
9701 gdb_assert (! this_cu
->is_debug_types
);
9703 cutu_reader
reader (this_cu
, NULL
, 1, 1, skip_partial
);
9707 struct dwarf2_cu
*cu
= reader
.cu
;
9708 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9710 gdb_assert (cu
->die_hash
== NULL
);
9712 htab_create_alloc_ex (cu
->header
.length
/ 12,
9716 &cu
->comp_unit_obstack
,
9717 hashtab_obstack_allocate
,
9718 dummy_obstack_deallocate
);
9720 if (reader
.has_children
)
9721 reader
.comp_unit_die
->child
9722 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9723 &info_ptr
, reader
.comp_unit_die
);
9724 cu
->dies
= reader
.comp_unit_die
;
9725 /* comp_unit_die is not stored in die_hash, no need. */
9727 /* We try not to read any attributes in this function, because not
9728 all CUs needed for references have been loaded yet, and symbol
9729 table processing isn't initialized. But we have to set the CU language,
9730 or we won't be able to build types correctly.
9731 Similarly, if we do not read the producer, we can not apply
9732 producer-specific interpretation. */
9733 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9736 /* Add a DIE to the delayed physname list. */
9739 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9740 const char *name
, struct die_info
*die
,
9741 struct dwarf2_cu
*cu
)
9743 struct delayed_method_info mi
;
9745 mi
.fnfield_index
= fnfield_index
;
9749 cu
->method_list
.push_back (mi
);
9752 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9753 "const" / "volatile". If so, decrements LEN by the length of the
9754 modifier and return true. Otherwise return false. */
9758 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9760 size_t mod_len
= sizeof (mod
) - 1;
9761 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9769 /* Compute the physnames of any methods on the CU's method list.
9771 The computation of method physnames is delayed in order to avoid the
9772 (bad) condition that one of the method's formal parameters is of an as yet
9776 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9778 /* Only C++ delays computing physnames. */
9779 if (cu
->method_list
.empty ())
9781 gdb_assert (cu
->language
== language_cplus
);
9783 for (const delayed_method_info
&mi
: cu
->method_list
)
9785 const char *physname
;
9786 struct fn_fieldlist
*fn_flp
9787 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9788 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9789 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9790 = physname
? physname
: "";
9792 /* Since there's no tag to indicate whether a method is a
9793 const/volatile overload, extract that information out of the
9795 if (physname
!= NULL
)
9797 size_t len
= strlen (physname
);
9801 if (physname
[len
] == ')') /* shortcut */
9803 else if (check_modifier (physname
, len
, " const"))
9804 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9805 else if (check_modifier (physname
, len
, " volatile"))
9806 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9813 /* The list is no longer needed. */
9814 cu
->method_list
.clear ();
9817 /* Go objects should be embedded in a DW_TAG_module DIE,
9818 and it's not clear if/how imported objects will appear.
9819 To keep Go support simple until that's worked out,
9820 go back through what we've read and create something usable.
9821 We could do this while processing each DIE, and feels kinda cleaner,
9822 but that way is more invasive.
9823 This is to, for example, allow the user to type "p var" or "b main"
9824 without having to specify the package name, and allow lookups
9825 of module.object to work in contexts that use the expression
9829 fixup_go_packaging (struct dwarf2_cu
*cu
)
9831 gdb::unique_xmalloc_ptr
<char> package_name
;
9832 struct pending
*list
;
9835 for (list
= *cu
->get_builder ()->get_global_symbols ();
9839 for (i
= 0; i
< list
->nsyms
; ++i
)
9841 struct symbol
*sym
= list
->symbol
[i
];
9843 if (sym
->language () == language_go
9844 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9846 gdb::unique_xmalloc_ptr
<char> this_package_name
9847 (go_symbol_package_name (sym
));
9849 if (this_package_name
== NULL
)
9851 if (package_name
== NULL
)
9852 package_name
= std::move (this_package_name
);
9855 struct objfile
*objfile
9856 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9857 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9858 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9859 (symbol_symtab (sym
) != NULL
9860 ? symtab_to_filename_for_display
9861 (symbol_symtab (sym
))
9862 : objfile_name (objfile
)),
9863 this_package_name
.get (), package_name
.get ());
9869 if (package_name
!= NULL
)
9871 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9872 const char *saved_package_name
9873 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9874 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9875 saved_package_name
);
9878 sym
= allocate_symbol (objfile
);
9879 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9880 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9881 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9882 e.g., "main" finds the "main" module and not C's main(). */
9883 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9884 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9885 SYMBOL_TYPE (sym
) = type
;
9887 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9891 /* Allocate a fully-qualified name consisting of the two parts on the
9895 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9897 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9900 /* A helper that allocates a struct discriminant_info to attach to a
9903 static struct discriminant_info
*
9904 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9907 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9908 gdb_assert (discriminant_index
== -1
9909 || (discriminant_index
>= 0
9910 && discriminant_index
< TYPE_NFIELDS (type
)));
9911 gdb_assert (default_index
== -1
9912 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9914 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9916 struct discriminant_info
*disc
9917 = ((struct discriminant_info
*)
9919 offsetof (struct discriminant_info
, discriminants
)
9920 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9921 disc
->default_index
= default_index
;
9922 disc
->discriminant_index
= discriminant_index
;
9924 struct dynamic_prop prop
;
9925 prop
.kind
= PROP_UNDEFINED
;
9926 prop
.data
.baton
= disc
;
9928 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9933 /* Some versions of rustc emitted enums in an unusual way.
9935 Ordinary enums were emitted as unions. The first element of each
9936 structure in the union was named "RUST$ENUM$DISR". This element
9937 held the discriminant.
9939 These versions of Rust also implemented the "non-zero"
9940 optimization. When the enum had two values, and one is empty and
9941 the other holds a pointer that cannot be zero, the pointer is used
9942 as the discriminant, with a zero value meaning the empty variant.
9943 Here, the union's first member is of the form
9944 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9945 where the fieldnos are the indices of the fields that should be
9946 traversed in order to find the field (which may be several fields deep)
9947 and the variantname is the name of the variant of the case when the
9950 This function recognizes whether TYPE is of one of these forms,
9951 and, if so, smashes it to be a variant type. */
9954 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9956 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9958 /* We don't need to deal with empty enums. */
9959 if (TYPE_NFIELDS (type
) == 0)
9962 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9963 if (TYPE_NFIELDS (type
) == 1
9964 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9966 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9968 /* Decode the field name to find the offset of the
9970 ULONGEST bit_offset
= 0;
9971 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9972 while (name
[0] >= '0' && name
[0] <= '9')
9975 unsigned long index
= strtoul (name
, &tail
, 10);
9978 || index
>= TYPE_NFIELDS (field_type
)
9979 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9980 != FIELD_LOC_KIND_BITPOS
))
9982 complaint (_("Could not parse Rust enum encoding string \"%s\""
9984 TYPE_FIELD_NAME (type
, 0),
9985 objfile_name (objfile
));
9990 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9991 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9994 /* Make a union to hold the variants. */
9995 struct type
*union_type
= alloc_type (objfile
);
9996 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9997 TYPE_NFIELDS (union_type
) = 3;
9998 TYPE_FIELDS (union_type
)
9999 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10000 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10001 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10003 /* Put the discriminant must at index 0. */
10004 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10005 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10006 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10007 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10009 /* The order of fields doesn't really matter, so put the real
10010 field at index 1 and the data-less field at index 2. */
10011 struct discriminant_info
*disc
10012 = alloc_discriminant_info (union_type
, 0, 1);
10013 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10014 TYPE_FIELD_NAME (union_type
, 1)
10015 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10016 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10017 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10018 TYPE_FIELD_NAME (union_type
, 1));
10020 const char *dataless_name
10021 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10023 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10025 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10026 /* NAME points into the original discriminant name, which
10027 already has the correct lifetime. */
10028 TYPE_FIELD_NAME (union_type
, 2) = name
;
10029 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10030 disc
->discriminants
[2] = 0;
10032 /* Smash this type to be a structure type. We have to do this
10033 because the type has already been recorded. */
10034 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10035 TYPE_NFIELDS (type
) = 1;
10037 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10039 /* Install the variant part. */
10040 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10041 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10042 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10044 /* A union with a single anonymous field is probably an old-style
10045 univariant enum. */
10046 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
10048 /* Smash this type to be a structure type. We have to do this
10049 because the type has already been recorded. */
10050 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10052 /* Make a union to hold the variants. */
10053 struct type
*union_type
= alloc_type (objfile
);
10054 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10055 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10056 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10057 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10058 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10060 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10061 const char *variant_name
10062 = rust_last_path_segment (TYPE_NAME (field_type
));
10063 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10064 TYPE_NAME (field_type
)
10065 = rust_fully_qualify (&objfile
->objfile_obstack
,
10066 TYPE_NAME (type
), variant_name
);
10068 /* Install the union in the outer struct type. */
10069 TYPE_NFIELDS (type
) = 1;
10071 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10072 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10073 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10074 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10076 alloc_discriminant_info (union_type
, -1, 0);
10080 struct type
*disr_type
= nullptr;
10081 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10083 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10085 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10087 /* All fields of a true enum will be structs. */
10090 else if (TYPE_NFIELDS (disr_type
) == 0)
10092 /* Could be data-less variant, so keep going. */
10093 disr_type
= nullptr;
10095 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10096 "RUST$ENUM$DISR") != 0)
10098 /* Not a Rust enum. */
10108 /* If we got here without a discriminant, then it's probably
10110 if (disr_type
== nullptr)
10113 /* Smash this type to be a structure type. We have to do this
10114 because the type has already been recorded. */
10115 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10117 /* Make a union to hold the variants. */
10118 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10119 struct type
*union_type
= alloc_type (objfile
);
10120 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10121 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10122 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10123 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10124 TYPE_FIELDS (union_type
)
10125 = (struct field
*) TYPE_ZALLOC (union_type
,
10126 (TYPE_NFIELDS (union_type
)
10127 * sizeof (struct field
)));
10129 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10130 TYPE_NFIELDS (type
) * sizeof (struct field
));
10132 /* Install the discriminant at index 0 in the union. */
10133 TYPE_FIELD (union_type
, 0) = *disr_field
;
10134 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10135 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10137 /* Install the union in the outer struct type. */
10138 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10139 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10140 TYPE_NFIELDS (type
) = 1;
10142 /* Set the size and offset of the union type. */
10143 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10145 /* We need a way to find the correct discriminant given a
10146 variant name. For convenience we build a map here. */
10147 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10148 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10149 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10151 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10154 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10155 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10159 int n_fields
= TYPE_NFIELDS (union_type
);
10160 struct discriminant_info
*disc
10161 = alloc_discriminant_info (union_type
, 0, -1);
10162 /* Skip the discriminant here. */
10163 for (int i
= 1; i
< n_fields
; ++i
)
10165 /* Find the final word in the name of this variant's type.
10166 That name can be used to look up the correct
10168 const char *variant_name
10169 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10172 auto iter
= discriminant_map
.find (variant_name
);
10173 if (iter
!= discriminant_map
.end ())
10174 disc
->discriminants
[i
] = iter
->second
;
10176 /* Remove the discriminant field, if it exists. */
10177 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10178 if (TYPE_NFIELDS (sub_type
) > 0)
10180 --TYPE_NFIELDS (sub_type
);
10181 ++TYPE_FIELDS (sub_type
);
10183 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10184 TYPE_NAME (sub_type
)
10185 = rust_fully_qualify (&objfile
->objfile_obstack
,
10186 TYPE_NAME (type
), variant_name
);
10191 /* Rewrite some Rust unions to be structures with variants parts. */
10194 rust_union_quirks (struct dwarf2_cu
*cu
)
10196 gdb_assert (cu
->language
== language_rust
);
10197 for (type
*type_
: cu
->rust_unions
)
10198 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10199 /* We don't need this any more. */
10200 cu
->rust_unions
.clear ();
10203 /* Return the symtab for PER_CU. This works properly regardless of
10204 whether we're using the index or psymtabs. */
10206 static struct compunit_symtab
*
10207 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10209 return (per_cu
->dwarf2_per_objfile
->using_index
10210 ? per_cu
->v
.quick
->compunit_symtab
10211 : per_cu
->v
.psymtab
->compunit_symtab
);
10214 /* A helper function for computing the list of all symbol tables
10215 included by PER_CU. */
10218 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
10219 htab_t all_children
, htab_t all_type_symtabs
,
10220 struct dwarf2_per_cu_data
*per_cu
,
10221 struct compunit_symtab
*immediate_parent
)
10224 struct compunit_symtab
*cust
;
10226 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10229 /* This inclusion and its children have been processed. */
10234 /* Only add a CU if it has a symbol table. */
10235 cust
= get_compunit_symtab (per_cu
);
10238 /* If this is a type unit only add its symbol table if we haven't
10239 seen it yet (type unit per_cu's can share symtabs). */
10240 if (per_cu
->is_debug_types
)
10242 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10246 result
->push_back (cust
);
10247 if (cust
->user
== NULL
)
10248 cust
->user
= immediate_parent
;
10253 result
->push_back (cust
);
10254 if (cust
->user
== NULL
)
10255 cust
->user
= immediate_parent
;
10259 if (!per_cu
->imported_symtabs_empty ())
10260 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10262 recursively_compute_inclusions (result
, all_children
,
10263 all_type_symtabs
, ptr
, cust
);
10267 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10271 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10273 gdb_assert (! per_cu
->is_debug_types
);
10275 if (!per_cu
->imported_symtabs_empty ())
10278 std::vector
<compunit_symtab
*> result_symtabs
;
10279 htab_t all_children
, all_type_symtabs
;
10280 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10282 /* If we don't have a symtab, we can just skip this case. */
10286 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10287 NULL
, xcalloc
, xfree
);
10288 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10289 NULL
, xcalloc
, xfree
);
10291 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10293 recursively_compute_inclusions (&result_symtabs
, all_children
,
10294 all_type_symtabs
, ptr
, cust
);
10297 /* Now we have a transitive closure of all the included symtabs. */
10298 len
= result_symtabs
.size ();
10300 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10301 struct compunit_symtab
*, len
+ 1);
10302 memcpy (cust
->includes
, result_symtabs
.data (),
10303 len
* sizeof (compunit_symtab
*));
10304 cust
->includes
[len
] = NULL
;
10306 htab_delete (all_children
);
10307 htab_delete (all_type_symtabs
);
10311 /* Compute the 'includes' field for the symtabs of all the CUs we just
10315 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10317 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10319 if (! iter
->is_debug_types
)
10320 compute_compunit_symtab_includes (iter
);
10323 dwarf2_per_objfile
->just_read_cus
.clear ();
10326 /* Generate full symbol information for PER_CU, whose DIEs have
10327 already been loaded into memory. */
10330 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10331 enum language pretend_language
)
10333 struct dwarf2_cu
*cu
= per_cu
->cu
;
10334 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10335 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10336 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10337 CORE_ADDR lowpc
, highpc
;
10338 struct compunit_symtab
*cust
;
10339 CORE_ADDR baseaddr
;
10340 struct block
*static_block
;
10343 baseaddr
= objfile
->text_section_offset ();
10345 /* Clear the list here in case something was left over. */
10346 cu
->method_list
.clear ();
10348 cu
->language
= pretend_language
;
10349 cu
->language_defn
= language_def (cu
->language
);
10351 /* Do line number decoding in read_file_scope () */
10352 process_die (cu
->dies
, cu
);
10354 /* For now fudge the Go package. */
10355 if (cu
->language
== language_go
)
10356 fixup_go_packaging (cu
);
10358 /* Now that we have processed all the DIEs in the CU, all the types
10359 should be complete, and it should now be safe to compute all of the
10361 compute_delayed_physnames (cu
);
10363 if (cu
->language
== language_rust
)
10364 rust_union_quirks (cu
);
10366 /* Some compilers don't define a DW_AT_high_pc attribute for the
10367 compilation unit. If the DW_AT_high_pc is missing, synthesize
10368 it, by scanning the DIE's below the compilation unit. */
10369 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10371 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10372 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10374 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10375 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10376 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10377 addrmap to help ensure it has an accurate map of pc values belonging to
10379 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10381 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10382 SECT_OFF_TEXT (objfile
),
10387 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10389 /* Set symtab language to language from DW_AT_language. If the
10390 compilation is from a C file generated by language preprocessors, do
10391 not set the language if it was already deduced by start_subfile. */
10392 if (!(cu
->language
== language_c
10393 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10394 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10396 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10397 produce DW_AT_location with location lists but it can be possibly
10398 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10399 there were bugs in prologue debug info, fixed later in GCC-4.5
10400 by "unwind info for epilogues" patch (which is not directly related).
10402 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10403 needed, it would be wrong due to missing DW_AT_producer there.
10405 Still one can confuse GDB by using non-standard GCC compilation
10406 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10408 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10409 cust
->locations_valid
= 1;
10411 if (gcc_4_minor
>= 5)
10412 cust
->epilogue_unwind_valid
= 1;
10414 cust
->call_site_htab
= cu
->call_site_htab
;
10417 if (dwarf2_per_objfile
->using_index
)
10418 per_cu
->v
.quick
->compunit_symtab
= cust
;
10421 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
10422 pst
->compunit_symtab
= cust
;
10423 pst
->readin
= true;
10426 /* Push it for inclusion processing later. */
10427 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10429 /* Not needed any more. */
10430 cu
->reset_builder ();
10433 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10434 already been loaded into memory. */
10437 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10438 enum language pretend_language
)
10440 struct dwarf2_cu
*cu
= per_cu
->cu
;
10441 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10442 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10443 struct compunit_symtab
*cust
;
10444 struct signatured_type
*sig_type
;
10446 gdb_assert (per_cu
->is_debug_types
);
10447 sig_type
= (struct signatured_type
*) per_cu
;
10449 /* Clear the list here in case something was left over. */
10450 cu
->method_list
.clear ();
10452 cu
->language
= pretend_language
;
10453 cu
->language_defn
= language_def (cu
->language
);
10455 /* The symbol tables are set up in read_type_unit_scope. */
10456 process_die (cu
->dies
, cu
);
10458 /* For now fudge the Go package. */
10459 if (cu
->language
== language_go
)
10460 fixup_go_packaging (cu
);
10462 /* Now that we have processed all the DIEs in the CU, all the types
10463 should be complete, and it should now be safe to compute all of the
10465 compute_delayed_physnames (cu
);
10467 if (cu
->language
== language_rust
)
10468 rust_union_quirks (cu
);
10470 /* TUs share symbol tables.
10471 If this is the first TU to use this symtab, complete the construction
10472 of it with end_expandable_symtab. Otherwise, complete the addition of
10473 this TU's symbols to the existing symtab. */
10474 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10476 buildsym_compunit
*builder
= cu
->get_builder ();
10477 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10478 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10482 /* Set symtab language to language from DW_AT_language. If the
10483 compilation is from a C file generated by language preprocessors,
10484 do not set the language if it was already deduced by
10486 if (!(cu
->language
== language_c
10487 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10488 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10493 cu
->get_builder ()->augment_type_symtab ();
10494 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10497 if (dwarf2_per_objfile
->using_index
)
10498 per_cu
->v
.quick
->compunit_symtab
= cust
;
10501 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
10502 pst
->compunit_symtab
= cust
;
10503 pst
->readin
= true;
10506 /* Not needed any more. */
10507 cu
->reset_builder ();
10510 /* Process an imported unit DIE. */
10513 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10515 struct attribute
*attr
;
10517 /* For now we don't handle imported units in type units. */
10518 if (cu
->per_cu
->is_debug_types
)
10520 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10521 " supported in type units [in module %s]"),
10522 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10525 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10528 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10529 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10530 dwarf2_per_cu_data
*per_cu
10531 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10532 cu
->per_cu
->dwarf2_per_objfile
);
10534 /* If necessary, add it to the queue and load its DIEs. */
10535 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10536 load_full_comp_unit (per_cu
, false, cu
->language
);
10538 cu
->per_cu
->imported_symtabs_push (per_cu
);
10542 /* RAII object that represents a process_die scope: i.e.,
10543 starts/finishes processing a DIE. */
10544 class process_die_scope
10547 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10548 : m_die (die
), m_cu (cu
)
10550 /* We should only be processing DIEs not already in process. */
10551 gdb_assert (!m_die
->in_process
);
10552 m_die
->in_process
= true;
10555 ~process_die_scope ()
10557 m_die
->in_process
= false;
10559 /* If we're done processing the DIE for the CU that owns the line
10560 header, we don't need the line header anymore. */
10561 if (m_cu
->line_header_die_owner
== m_die
)
10563 delete m_cu
->line_header
;
10564 m_cu
->line_header
= NULL
;
10565 m_cu
->line_header_die_owner
= NULL
;
10574 /* Process a die and its children. */
10577 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10579 process_die_scope
scope (die
, cu
);
10583 case DW_TAG_padding
:
10585 case DW_TAG_compile_unit
:
10586 case DW_TAG_partial_unit
:
10587 read_file_scope (die
, cu
);
10589 case DW_TAG_type_unit
:
10590 read_type_unit_scope (die
, cu
);
10592 case DW_TAG_subprogram
:
10593 /* Nested subprograms in Fortran get a prefix. */
10594 if (cu
->language
== language_fortran
10595 && die
->parent
!= NULL
10596 && die
->parent
->tag
== DW_TAG_subprogram
)
10597 cu
->processing_has_namespace_info
= true;
10598 /* Fall through. */
10599 case DW_TAG_inlined_subroutine
:
10600 read_func_scope (die
, cu
);
10602 case DW_TAG_lexical_block
:
10603 case DW_TAG_try_block
:
10604 case DW_TAG_catch_block
:
10605 read_lexical_block_scope (die
, cu
);
10607 case DW_TAG_call_site
:
10608 case DW_TAG_GNU_call_site
:
10609 read_call_site_scope (die
, cu
);
10611 case DW_TAG_class_type
:
10612 case DW_TAG_interface_type
:
10613 case DW_TAG_structure_type
:
10614 case DW_TAG_union_type
:
10615 process_structure_scope (die
, cu
);
10617 case DW_TAG_enumeration_type
:
10618 process_enumeration_scope (die
, cu
);
10621 /* These dies have a type, but processing them does not create
10622 a symbol or recurse to process the children. Therefore we can
10623 read them on-demand through read_type_die. */
10624 case DW_TAG_subroutine_type
:
10625 case DW_TAG_set_type
:
10626 case DW_TAG_array_type
:
10627 case DW_TAG_pointer_type
:
10628 case DW_TAG_ptr_to_member_type
:
10629 case DW_TAG_reference_type
:
10630 case DW_TAG_rvalue_reference_type
:
10631 case DW_TAG_string_type
:
10634 case DW_TAG_base_type
:
10635 case DW_TAG_subrange_type
:
10636 case DW_TAG_typedef
:
10637 /* Add a typedef symbol for the type definition, if it has a
10639 new_symbol (die
, read_type_die (die
, cu
), cu
);
10641 case DW_TAG_common_block
:
10642 read_common_block (die
, cu
);
10644 case DW_TAG_common_inclusion
:
10646 case DW_TAG_namespace
:
10647 cu
->processing_has_namespace_info
= true;
10648 read_namespace (die
, cu
);
10650 case DW_TAG_module
:
10651 cu
->processing_has_namespace_info
= true;
10652 read_module (die
, cu
);
10654 case DW_TAG_imported_declaration
:
10655 cu
->processing_has_namespace_info
= true;
10656 if (read_namespace_alias (die
, cu
))
10658 /* The declaration is not a global namespace alias. */
10659 /* Fall through. */
10660 case DW_TAG_imported_module
:
10661 cu
->processing_has_namespace_info
= true;
10662 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10663 || cu
->language
!= language_fortran
))
10664 complaint (_("Tag '%s' has unexpected children"),
10665 dwarf_tag_name (die
->tag
));
10666 read_import_statement (die
, cu
);
10669 case DW_TAG_imported_unit
:
10670 process_imported_unit_die (die
, cu
);
10673 case DW_TAG_variable
:
10674 read_variable (die
, cu
);
10678 new_symbol (die
, NULL
, cu
);
10683 /* DWARF name computation. */
10685 /* A helper function for dwarf2_compute_name which determines whether DIE
10686 needs to have the name of the scope prepended to the name listed in the
10690 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10692 struct attribute
*attr
;
10696 case DW_TAG_namespace
:
10697 case DW_TAG_typedef
:
10698 case DW_TAG_class_type
:
10699 case DW_TAG_interface_type
:
10700 case DW_TAG_structure_type
:
10701 case DW_TAG_union_type
:
10702 case DW_TAG_enumeration_type
:
10703 case DW_TAG_enumerator
:
10704 case DW_TAG_subprogram
:
10705 case DW_TAG_inlined_subroutine
:
10706 case DW_TAG_member
:
10707 case DW_TAG_imported_declaration
:
10710 case DW_TAG_variable
:
10711 case DW_TAG_constant
:
10712 /* We only need to prefix "globally" visible variables. These include
10713 any variable marked with DW_AT_external or any variable that
10714 lives in a namespace. [Variables in anonymous namespaces
10715 require prefixing, but they are not DW_AT_external.] */
10717 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10719 struct dwarf2_cu
*spec_cu
= cu
;
10721 return die_needs_namespace (die_specification (die
, &spec_cu
),
10725 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10726 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10727 && die
->parent
->tag
!= DW_TAG_module
)
10729 /* A variable in a lexical block of some kind does not need a
10730 namespace, even though in C++ such variables may be external
10731 and have a mangled name. */
10732 if (die
->parent
->tag
== DW_TAG_lexical_block
10733 || die
->parent
->tag
== DW_TAG_try_block
10734 || die
->parent
->tag
== DW_TAG_catch_block
10735 || die
->parent
->tag
== DW_TAG_subprogram
)
10744 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10745 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10746 defined for the given DIE. */
10748 static struct attribute
*
10749 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10751 struct attribute
*attr
;
10753 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10755 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10760 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10761 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10762 defined for the given DIE. */
10764 static const char *
10765 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10767 const char *linkage_name
;
10769 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10770 if (linkage_name
== NULL
)
10771 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10773 return linkage_name
;
10776 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10777 compute the physname for the object, which include a method's:
10778 - formal parameters (C++),
10779 - receiver type (Go),
10781 The term "physname" is a bit confusing.
10782 For C++, for example, it is the demangled name.
10783 For Go, for example, it's the mangled name.
10785 For Ada, return the DIE's linkage name rather than the fully qualified
10786 name. PHYSNAME is ignored..
10788 The result is allocated on the objfile_obstack and canonicalized. */
10790 static const char *
10791 dwarf2_compute_name (const char *name
,
10792 struct die_info
*die
, struct dwarf2_cu
*cu
,
10795 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10798 name
= dwarf2_name (die
, cu
);
10800 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10801 but otherwise compute it by typename_concat inside GDB.
10802 FIXME: Actually this is not really true, or at least not always true.
10803 It's all very confusing. compute_and_set_names doesn't try to demangle
10804 Fortran names because there is no mangling standard. So new_symbol
10805 will set the demangled name to the result of dwarf2_full_name, and it is
10806 the demangled name that GDB uses if it exists. */
10807 if (cu
->language
== language_ada
10808 || (cu
->language
== language_fortran
&& physname
))
10810 /* For Ada unit, we prefer the linkage name over the name, as
10811 the former contains the exported name, which the user expects
10812 to be able to reference. Ideally, we want the user to be able
10813 to reference this entity using either natural or linkage name,
10814 but we haven't started looking at this enhancement yet. */
10815 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10817 if (linkage_name
!= NULL
)
10818 return linkage_name
;
10821 /* These are the only languages we know how to qualify names in. */
10823 && (cu
->language
== language_cplus
10824 || cu
->language
== language_fortran
|| cu
->language
== language_d
10825 || cu
->language
== language_rust
))
10827 if (die_needs_namespace (die
, cu
))
10829 const char *prefix
;
10830 const char *canonical_name
= NULL
;
10834 prefix
= determine_prefix (die
, cu
);
10835 if (*prefix
!= '\0')
10837 gdb::unique_xmalloc_ptr
<char> prefixed_name
10838 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10840 buf
.puts (prefixed_name
.get ());
10845 /* Template parameters may be specified in the DIE's DW_AT_name, or
10846 as children with DW_TAG_template_type_param or
10847 DW_TAG_value_type_param. If the latter, add them to the name
10848 here. If the name already has template parameters, then
10849 skip this step; some versions of GCC emit both, and
10850 it is more efficient to use the pre-computed name.
10852 Something to keep in mind about this process: it is very
10853 unlikely, or in some cases downright impossible, to produce
10854 something that will match the mangled name of a function.
10855 If the definition of the function has the same debug info,
10856 we should be able to match up with it anyway. But fallbacks
10857 using the minimal symbol, for instance to find a method
10858 implemented in a stripped copy of libstdc++, will not work.
10859 If we do not have debug info for the definition, we will have to
10860 match them up some other way.
10862 When we do name matching there is a related problem with function
10863 templates; two instantiated function templates are allowed to
10864 differ only by their return types, which we do not add here. */
10866 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10868 struct attribute
*attr
;
10869 struct die_info
*child
;
10872 die
->building_fullname
= 1;
10874 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10878 const gdb_byte
*bytes
;
10879 struct dwarf2_locexpr_baton
*baton
;
10882 if (child
->tag
!= DW_TAG_template_type_param
10883 && child
->tag
!= DW_TAG_template_value_param
)
10894 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10897 complaint (_("template parameter missing DW_AT_type"));
10898 buf
.puts ("UNKNOWN_TYPE");
10901 type
= die_type (child
, cu
);
10903 if (child
->tag
== DW_TAG_template_type_param
)
10905 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10906 &type_print_raw_options
);
10910 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10913 complaint (_("template parameter missing "
10914 "DW_AT_const_value"));
10915 buf
.puts ("UNKNOWN_VALUE");
10919 dwarf2_const_value_attr (attr
, type
, name
,
10920 &cu
->comp_unit_obstack
, cu
,
10921 &value
, &bytes
, &baton
);
10923 if (TYPE_NOSIGN (type
))
10924 /* GDB prints characters as NUMBER 'CHAR'. If that's
10925 changed, this can use value_print instead. */
10926 c_printchar (value
, type
, &buf
);
10929 struct value_print_options opts
;
10932 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10936 else if (bytes
!= NULL
)
10938 v
= allocate_value (type
);
10939 memcpy (value_contents_writeable (v
), bytes
,
10940 TYPE_LENGTH (type
));
10943 v
= value_from_longest (type
, value
);
10945 /* Specify decimal so that we do not depend on
10947 get_formatted_print_options (&opts
, 'd');
10949 value_print (v
, &buf
, &opts
);
10954 die
->building_fullname
= 0;
10958 /* Close the argument list, with a space if necessary
10959 (nested templates). */
10960 if (!buf
.empty () && buf
.string ().back () == '>')
10967 /* For C++ methods, append formal parameter type
10968 information, if PHYSNAME. */
10970 if (physname
&& die
->tag
== DW_TAG_subprogram
10971 && cu
->language
== language_cplus
)
10973 struct type
*type
= read_type_die (die
, cu
);
10975 c_type_print_args (type
, &buf
, 1, cu
->language
,
10976 &type_print_raw_options
);
10978 if (cu
->language
== language_cplus
)
10980 /* Assume that an artificial first parameter is
10981 "this", but do not crash if it is not. RealView
10982 marks unnamed (and thus unused) parameters as
10983 artificial; there is no way to differentiate
10985 if (TYPE_NFIELDS (type
) > 0
10986 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10987 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10988 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10990 buf
.puts (" const");
10994 const std::string
&intermediate_name
= buf
.string ();
10996 if (cu
->language
== language_cplus
)
10998 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10999 &objfile
->per_bfd
->storage_obstack
);
11001 /* If we only computed INTERMEDIATE_NAME, or if
11002 INTERMEDIATE_NAME is already canonical, then we need to
11003 copy it to the appropriate obstack. */
11004 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11005 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
11006 intermediate_name
);
11008 name
= canonical_name
;
11015 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11016 If scope qualifiers are appropriate they will be added. The result
11017 will be allocated on the storage_obstack, or NULL if the DIE does
11018 not have a name. NAME may either be from a previous call to
11019 dwarf2_name or NULL.
11021 The output string will be canonicalized (if C++). */
11023 static const char *
11024 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11026 return dwarf2_compute_name (name
, die
, cu
, 0);
11029 /* Construct a physname for the given DIE in CU. NAME may either be
11030 from a previous call to dwarf2_name or NULL. The result will be
11031 allocated on the objfile_objstack or NULL if the DIE does not have a
11034 The output string will be canonicalized (if C++). */
11036 static const char *
11037 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11039 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11040 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11043 /* In this case dwarf2_compute_name is just a shortcut not building anything
11045 if (!die_needs_namespace (die
, cu
))
11046 return dwarf2_compute_name (name
, die
, cu
, 1);
11048 mangled
= dw2_linkage_name (die
, cu
);
11050 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11051 See https://github.com/rust-lang/rust/issues/32925. */
11052 if (cu
->language
== language_rust
&& mangled
!= NULL
11053 && strchr (mangled
, '{') != NULL
)
11056 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11058 gdb::unique_xmalloc_ptr
<char> demangled
;
11059 if (mangled
!= NULL
)
11062 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11064 /* Do nothing (do not demangle the symbol name). */
11066 else if (cu
->language
== language_go
)
11068 /* This is a lie, but we already lie to the caller new_symbol.
11069 new_symbol assumes we return the mangled name.
11070 This just undoes that lie until things are cleaned up. */
11074 /* Use DMGL_RET_DROP for C++ template functions to suppress
11075 their return type. It is easier for GDB users to search
11076 for such functions as `name(params)' than `long name(params)'.
11077 In such case the minimal symbol names do not match the full
11078 symbol names but for template functions there is never a need
11079 to look up their definition from their declaration so
11080 the only disadvantage remains the minimal symbol variant
11081 `long name(params)' does not have the proper inferior type. */
11082 demangled
.reset (gdb_demangle (mangled
,
11083 (DMGL_PARAMS
| DMGL_ANSI
11084 | DMGL_RET_DROP
)));
11087 canon
= demangled
.get ();
11095 if (canon
== NULL
|| check_physname
)
11097 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11099 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11101 /* It may not mean a bug in GDB. The compiler could also
11102 compute DW_AT_linkage_name incorrectly. But in such case
11103 GDB would need to be bug-to-bug compatible. */
11105 complaint (_("Computed physname <%s> does not match demangled <%s> "
11106 "(from linkage <%s>) - DIE at %s [in module %s]"),
11107 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11108 objfile_name (objfile
));
11110 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11111 is available here - over computed PHYSNAME. It is safer
11112 against both buggy GDB and buggy compilers. */
11126 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
11131 /* Inspect DIE in CU for a namespace alias. If one exists, record
11132 a new symbol for it.
11134 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11137 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11139 struct attribute
*attr
;
11141 /* If the die does not have a name, this is not a namespace
11143 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11147 struct die_info
*d
= die
;
11148 struct dwarf2_cu
*imported_cu
= cu
;
11150 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11151 keep inspecting DIEs until we hit the underlying import. */
11152 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11153 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11155 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11159 d
= follow_die_ref (d
, attr
, &imported_cu
);
11160 if (d
->tag
!= DW_TAG_imported_declaration
)
11164 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11166 complaint (_("DIE at %s has too many recursively imported "
11167 "declarations"), sect_offset_str (d
->sect_off
));
11174 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11176 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11177 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11179 /* This declaration is a global namespace alias. Add
11180 a symbol for it whose type is the aliased namespace. */
11181 new_symbol (die
, type
, cu
);
11190 /* Return the using directives repository (global or local?) to use in the
11191 current context for CU.
11193 For Ada, imported declarations can materialize renamings, which *may* be
11194 global. However it is impossible (for now?) in DWARF to distinguish
11195 "external" imported declarations and "static" ones. As all imported
11196 declarations seem to be static in all other languages, make them all CU-wide
11197 global only in Ada. */
11199 static struct using_direct
**
11200 using_directives (struct dwarf2_cu
*cu
)
11202 if (cu
->language
== language_ada
11203 && cu
->get_builder ()->outermost_context_p ())
11204 return cu
->get_builder ()->get_global_using_directives ();
11206 return cu
->get_builder ()->get_local_using_directives ();
11209 /* Read the import statement specified by the given die and record it. */
11212 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11214 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11215 struct attribute
*import_attr
;
11216 struct die_info
*imported_die
, *child_die
;
11217 struct dwarf2_cu
*imported_cu
;
11218 const char *imported_name
;
11219 const char *imported_name_prefix
;
11220 const char *canonical_name
;
11221 const char *import_alias
;
11222 const char *imported_declaration
= NULL
;
11223 const char *import_prefix
;
11224 std::vector
<const char *> excludes
;
11226 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11227 if (import_attr
== NULL
)
11229 complaint (_("Tag '%s' has no DW_AT_import"),
11230 dwarf_tag_name (die
->tag
));
11235 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11236 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11237 if (imported_name
== NULL
)
11239 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11241 The import in the following code:
11255 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11256 <52> DW_AT_decl_file : 1
11257 <53> DW_AT_decl_line : 6
11258 <54> DW_AT_import : <0x75>
11259 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11260 <59> DW_AT_name : B
11261 <5b> DW_AT_decl_file : 1
11262 <5c> DW_AT_decl_line : 2
11263 <5d> DW_AT_type : <0x6e>
11265 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11266 <76> DW_AT_byte_size : 4
11267 <77> DW_AT_encoding : 5 (signed)
11269 imports the wrong die ( 0x75 instead of 0x58 ).
11270 This case will be ignored until the gcc bug is fixed. */
11274 /* Figure out the local name after import. */
11275 import_alias
= dwarf2_name (die
, cu
);
11277 /* Figure out where the statement is being imported to. */
11278 import_prefix
= determine_prefix (die
, cu
);
11280 /* Figure out what the scope of the imported die is and prepend it
11281 to the name of the imported die. */
11282 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11284 if (imported_die
->tag
!= DW_TAG_namespace
11285 && imported_die
->tag
!= DW_TAG_module
)
11287 imported_declaration
= imported_name
;
11288 canonical_name
= imported_name_prefix
;
11290 else if (strlen (imported_name_prefix
) > 0)
11291 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11292 imported_name_prefix
,
11293 (cu
->language
== language_d
? "." : "::"),
11294 imported_name
, (char *) NULL
);
11296 canonical_name
= imported_name
;
11298 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11299 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11300 child_die
= sibling_die (child_die
))
11302 /* DWARF-4: A Fortran use statement with a “rename list” may be
11303 represented by an imported module entry with an import attribute
11304 referring to the module and owned entries corresponding to those
11305 entities that are renamed as part of being imported. */
11307 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11309 complaint (_("child DW_TAG_imported_declaration expected "
11310 "- DIE at %s [in module %s]"),
11311 sect_offset_str (child_die
->sect_off
),
11312 objfile_name (objfile
));
11316 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11317 if (import_attr
== NULL
)
11319 complaint (_("Tag '%s' has no DW_AT_import"),
11320 dwarf_tag_name (child_die
->tag
));
11325 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11327 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11328 if (imported_name
== NULL
)
11330 complaint (_("child DW_TAG_imported_declaration has unknown "
11331 "imported name - DIE at %s [in module %s]"),
11332 sect_offset_str (child_die
->sect_off
),
11333 objfile_name (objfile
));
11337 excludes
.push_back (imported_name
);
11339 process_die (child_die
, cu
);
11342 add_using_directive (using_directives (cu
),
11346 imported_declaration
,
11349 &objfile
->objfile_obstack
);
11352 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11353 types, but gives them a size of zero. Starting with version 14,
11354 ICC is compatible with GCC. */
11357 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11359 if (!cu
->checked_producer
)
11360 check_producer (cu
);
11362 return cu
->producer_is_icc_lt_14
;
11365 /* ICC generates a DW_AT_type for C void functions. This was observed on
11366 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11367 which says that void functions should not have a DW_AT_type. */
11370 producer_is_icc (struct dwarf2_cu
*cu
)
11372 if (!cu
->checked_producer
)
11373 check_producer (cu
);
11375 return cu
->producer_is_icc
;
11378 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11379 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11380 this, it was first present in GCC release 4.3.0. */
11383 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11385 if (!cu
->checked_producer
)
11386 check_producer (cu
);
11388 return cu
->producer_is_gcc_lt_4_3
;
11391 static file_and_directory
11392 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11394 file_and_directory res
;
11396 /* Find the filename. Do not use dwarf2_name here, since the filename
11397 is not a source language identifier. */
11398 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11399 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11401 if (res
.comp_dir
== NULL
11402 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11403 && IS_ABSOLUTE_PATH (res
.name
))
11405 res
.comp_dir_storage
= ldirname (res
.name
);
11406 if (!res
.comp_dir_storage
.empty ())
11407 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11409 if (res
.comp_dir
!= NULL
)
11411 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11412 directory, get rid of it. */
11413 const char *cp
= strchr (res
.comp_dir
, ':');
11415 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11416 res
.comp_dir
= cp
+ 1;
11419 if (res
.name
== NULL
)
11420 res
.name
= "<unknown>";
11425 /* Handle DW_AT_stmt_list for a compilation unit.
11426 DIE is the DW_TAG_compile_unit die for CU.
11427 COMP_DIR is the compilation directory. LOWPC is passed to
11428 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11431 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11432 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11434 struct dwarf2_per_objfile
*dwarf2_per_objfile
11435 = cu
->per_cu
->dwarf2_per_objfile
;
11436 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11437 struct attribute
*attr
;
11438 struct line_header line_header_local
;
11439 hashval_t line_header_local_hash
;
11441 int decode_mapping
;
11443 gdb_assert (! cu
->per_cu
->is_debug_types
);
11445 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11449 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11451 /* The line header hash table is only created if needed (it exists to
11452 prevent redundant reading of the line table for partial_units).
11453 If we're given a partial_unit, we'll need it. If we're given a
11454 compile_unit, then use the line header hash table if it's already
11455 created, but don't create one just yet. */
11457 if (dwarf2_per_objfile
->line_header_hash
== NULL
11458 && die
->tag
== DW_TAG_partial_unit
)
11460 dwarf2_per_objfile
->line_header_hash
11461 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11462 line_header_eq_voidp
,
11463 free_line_header_voidp
,
11464 &objfile
->objfile_obstack
,
11465 hashtab_obstack_allocate
,
11466 dummy_obstack_deallocate
);
11469 line_header_local
.sect_off
= line_offset
;
11470 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11471 line_header_local_hash
= line_header_hash (&line_header_local
);
11472 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11474 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11475 &line_header_local
,
11476 line_header_local_hash
, NO_INSERT
);
11478 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11479 is not present in *SLOT (since if there is something in *SLOT then
11480 it will be for a partial_unit). */
11481 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11483 gdb_assert (*slot
!= NULL
);
11484 cu
->line_header
= (struct line_header
*) *slot
;
11489 /* dwarf_decode_line_header does not yet provide sufficient information.
11490 We always have to call also dwarf_decode_lines for it. */
11491 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11495 cu
->line_header
= lh
.release ();
11496 cu
->line_header_die_owner
= die
;
11498 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11502 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11503 &line_header_local
,
11504 line_header_local_hash
, INSERT
);
11505 gdb_assert (slot
!= NULL
);
11507 if (slot
!= NULL
&& *slot
== NULL
)
11509 /* This newly decoded line number information unit will be owned
11510 by line_header_hash hash table. */
11511 *slot
= cu
->line_header
;
11512 cu
->line_header_die_owner
= NULL
;
11516 /* We cannot free any current entry in (*slot) as that struct line_header
11517 may be already used by multiple CUs. Create only temporary decoded
11518 line_header for this CU - it may happen at most once for each line
11519 number information unit. And if we're not using line_header_hash
11520 then this is what we want as well. */
11521 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11523 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11524 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11529 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11532 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11534 struct dwarf2_per_objfile
*dwarf2_per_objfile
11535 = cu
->per_cu
->dwarf2_per_objfile
;
11536 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11537 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11538 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11539 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11540 struct attribute
*attr
;
11541 struct die_info
*child_die
;
11542 CORE_ADDR baseaddr
;
11544 prepare_one_comp_unit (cu
, die
, cu
->language
);
11545 baseaddr
= objfile
->text_section_offset ();
11547 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11549 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11550 from finish_block. */
11551 if (lowpc
== ((CORE_ADDR
) -1))
11553 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11555 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11557 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11558 standardised yet. As a workaround for the language detection we fall
11559 back to the DW_AT_producer string. */
11560 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11561 cu
->language
= language_opencl
;
11563 /* Similar hack for Go. */
11564 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11565 set_cu_language (DW_LANG_Go
, cu
);
11567 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11569 /* Decode line number information if present. We do this before
11570 processing child DIEs, so that the line header table is available
11571 for DW_AT_decl_file. */
11572 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11574 /* Process all dies in compilation unit. */
11575 if (die
->child
!= NULL
)
11577 child_die
= die
->child
;
11578 while (child_die
&& child_die
->tag
)
11580 process_die (child_die
, cu
);
11581 child_die
= sibling_die (child_die
);
11585 /* Decode macro information, if present. Dwarf 2 macro information
11586 refers to information in the line number info statement program
11587 header, so we can only read it if we've read the header
11589 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11591 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11592 if (attr
&& cu
->line_header
)
11594 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11595 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11597 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11601 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11602 if (attr
&& cu
->line_header
)
11604 unsigned int macro_offset
= DW_UNSND (attr
);
11606 dwarf_decode_macros (cu
, macro_offset
, 0);
11612 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11614 struct type_unit_group
*tu_group
;
11616 struct attribute
*attr
;
11618 struct signatured_type
*sig_type
;
11620 gdb_assert (per_cu
->is_debug_types
);
11621 sig_type
= (struct signatured_type
*) per_cu
;
11623 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11625 /* If we're using .gdb_index (includes -readnow) then
11626 per_cu->type_unit_group may not have been set up yet. */
11627 if (sig_type
->type_unit_group
== NULL
)
11628 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11629 tu_group
= sig_type
->type_unit_group
;
11631 /* If we've already processed this stmt_list there's no real need to
11632 do it again, we could fake it and just recreate the part we need
11633 (file name,index -> symtab mapping). If data shows this optimization
11634 is useful we can do it then. */
11635 first_time
= tu_group
->compunit_symtab
== NULL
;
11637 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11642 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11643 lh
= dwarf_decode_line_header (line_offset
, this);
11648 start_symtab ("", NULL
, 0);
11651 gdb_assert (tu_group
->symtabs
== NULL
);
11652 gdb_assert (m_builder
== nullptr);
11653 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11654 m_builder
.reset (new struct buildsym_compunit
11655 (COMPUNIT_OBJFILE (cust
), "",
11656 COMPUNIT_DIRNAME (cust
),
11657 compunit_language (cust
),
11663 line_header
= lh
.release ();
11664 line_header_die_owner
= die
;
11668 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11670 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11671 still initializing it, and our caller (a few levels up)
11672 process_full_type_unit still needs to know if this is the first
11675 tu_group
->num_symtabs
= line_header
->file_names_size ();
11676 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11677 line_header
->file_names_size ());
11679 auto &file_names
= line_header
->file_names ();
11680 for (i
= 0; i
< file_names
.size (); ++i
)
11682 file_entry
&fe
= file_names
[i
];
11683 dwarf2_start_subfile (this, fe
.name
,
11684 fe
.include_dir (line_header
));
11685 buildsym_compunit
*b
= get_builder ();
11686 if (b
->get_current_subfile ()->symtab
== NULL
)
11688 /* NOTE: start_subfile will recognize when it's been
11689 passed a file it has already seen. So we can't
11690 assume there's a simple mapping from
11691 cu->line_header->file_names to subfiles, plus
11692 cu->line_header->file_names may contain dups. */
11693 b
->get_current_subfile ()->symtab
11694 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11697 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11698 tu_group
->symtabs
[i
] = fe
.symtab
;
11703 gdb_assert (m_builder
== nullptr);
11704 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11705 m_builder
.reset (new struct buildsym_compunit
11706 (COMPUNIT_OBJFILE (cust
), "",
11707 COMPUNIT_DIRNAME (cust
),
11708 compunit_language (cust
),
11711 auto &file_names
= line_header
->file_names ();
11712 for (i
= 0; i
< file_names
.size (); ++i
)
11714 file_entry
&fe
= file_names
[i
];
11715 fe
.symtab
= tu_group
->symtabs
[i
];
11719 /* The main symtab is allocated last. Type units don't have DW_AT_name
11720 so they don't have a "real" (so to speak) symtab anyway.
11721 There is later code that will assign the main symtab to all symbols
11722 that don't have one. We need to handle the case of a symbol with a
11723 missing symtab (DW_AT_decl_file) anyway. */
11726 /* Process DW_TAG_type_unit.
11727 For TUs we want to skip the first top level sibling if it's not the
11728 actual type being defined by this TU. In this case the first top
11729 level sibling is there to provide context only. */
11732 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11734 struct die_info
*child_die
;
11736 prepare_one_comp_unit (cu
, die
, language_minimal
);
11738 /* Initialize (or reinitialize) the machinery for building symtabs.
11739 We do this before processing child DIEs, so that the line header table
11740 is available for DW_AT_decl_file. */
11741 cu
->setup_type_unit_groups (die
);
11743 if (die
->child
!= NULL
)
11745 child_die
= die
->child
;
11746 while (child_die
&& child_die
->tag
)
11748 process_die (child_die
, cu
);
11749 child_die
= sibling_die (child_die
);
11756 http://gcc.gnu.org/wiki/DebugFission
11757 http://gcc.gnu.org/wiki/DebugFissionDWP
11759 To simplify handling of both DWO files ("object" files with the DWARF info)
11760 and DWP files (a file with the DWOs packaged up into one file), we treat
11761 DWP files as having a collection of virtual DWO files. */
11764 hash_dwo_file (const void *item
)
11766 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11769 hash
= htab_hash_string (dwo_file
->dwo_name
);
11770 if (dwo_file
->comp_dir
!= NULL
)
11771 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11776 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11778 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11779 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11781 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11783 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11784 return lhs
->comp_dir
== rhs
->comp_dir
;
11785 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11788 /* Allocate a hash table for DWO files. */
11791 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11793 auto delete_dwo_file
= [] (void *item
)
11795 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11800 return htab_up (htab_create_alloc_ex (41,
11804 &objfile
->objfile_obstack
,
11805 hashtab_obstack_allocate
,
11806 dummy_obstack_deallocate
));
11809 /* Lookup DWO file DWO_NAME. */
11812 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11813 const char *dwo_name
,
11814 const char *comp_dir
)
11816 struct dwo_file find_entry
;
11819 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11820 dwarf2_per_objfile
->dwo_files
11821 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11823 find_entry
.dwo_name
= dwo_name
;
11824 find_entry
.comp_dir
= comp_dir
;
11825 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11832 hash_dwo_unit (const void *item
)
11834 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11836 /* This drops the top 32 bits of the id, but is ok for a hash. */
11837 return dwo_unit
->signature
;
11841 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11843 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11844 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11846 /* The signature is assumed to be unique within the DWO file.
11847 So while object file CU dwo_id's always have the value zero,
11848 that's OK, assuming each object file DWO file has only one CU,
11849 and that's the rule for now. */
11850 return lhs
->signature
== rhs
->signature
;
11853 /* Allocate a hash table for DWO CUs,TUs.
11854 There is one of these tables for each of CUs,TUs for each DWO file. */
11857 allocate_dwo_unit_table (struct objfile
*objfile
)
11859 /* Start out with a pretty small number.
11860 Generally DWO files contain only one CU and maybe some TUs. */
11861 return htab_create_alloc_ex (3,
11865 &objfile
->objfile_obstack
,
11866 hashtab_obstack_allocate
,
11867 dummy_obstack_deallocate
);
11870 /* die_reader_func for create_dwo_cu. */
11873 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11874 const gdb_byte
*info_ptr
,
11875 struct die_info
*comp_unit_die
,
11877 struct dwo_file
*dwo_file
,
11878 struct dwo_unit
*dwo_unit
)
11880 struct dwarf2_cu
*cu
= reader
->cu
;
11881 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11882 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11884 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11885 if (!signature
.has_value ())
11887 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11888 " its dwo_id [in module %s]"),
11889 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11893 dwo_unit
->dwo_file
= dwo_file
;
11894 dwo_unit
->signature
= *signature
;
11895 dwo_unit
->section
= section
;
11896 dwo_unit
->sect_off
= sect_off
;
11897 dwo_unit
->length
= cu
->per_cu
->length
;
11899 if (dwarf_read_debug
)
11900 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11901 sect_offset_str (sect_off
),
11902 hex_string (dwo_unit
->signature
));
11905 /* Create the dwo_units for the CUs in a DWO_FILE.
11906 Note: This function processes DWO files only, not DWP files. */
11909 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11910 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11911 dwarf2_section_info
§ion
, htab_t
&cus_htab
)
11913 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11914 const gdb_byte
*info_ptr
, *end_ptr
;
11916 dwarf2_read_section (objfile
, §ion
);
11917 info_ptr
= section
.buffer
;
11919 if (info_ptr
== NULL
)
11922 if (dwarf_read_debug
)
11924 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11925 get_section_name (§ion
),
11926 get_section_file_name (§ion
));
11929 end_ptr
= info_ptr
+ section
.size
;
11930 while (info_ptr
< end_ptr
)
11932 struct dwarf2_per_cu_data per_cu
;
11933 struct dwo_unit read_unit
{};
11934 struct dwo_unit
*dwo_unit
;
11936 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11938 memset (&per_cu
, 0, sizeof (per_cu
));
11939 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11940 per_cu
.is_debug_types
= 0;
11941 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11942 per_cu
.section
= §ion
;
11944 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11945 if (!reader
.dummy_p
)
11946 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11947 reader
.has_children
, &dwo_file
, &read_unit
);
11948 info_ptr
+= per_cu
.length
;
11950 // If the unit could not be parsed, skip it.
11951 if (read_unit
.dwo_file
== NULL
)
11954 if (cus_htab
== NULL
)
11955 cus_htab
= allocate_dwo_unit_table (objfile
);
11957 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11958 *dwo_unit
= read_unit
;
11959 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
11960 gdb_assert (slot
!= NULL
);
11963 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11964 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11966 complaint (_("debug cu entry at offset %s is duplicate to"
11967 " the entry at offset %s, signature %s"),
11968 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11969 hex_string (dwo_unit
->signature
));
11971 *slot
= (void *)dwo_unit
;
11975 /* DWP file .debug_{cu,tu}_index section format:
11976 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11980 Both index sections have the same format, and serve to map a 64-bit
11981 signature to a set of section numbers. Each section begins with a header,
11982 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11983 indexes, and a pool of 32-bit section numbers. The index sections will be
11984 aligned at 8-byte boundaries in the file.
11986 The index section header consists of:
11988 V, 32 bit version number
11990 N, 32 bit number of compilation units or type units in the index
11991 M, 32 bit number of slots in the hash table
11993 Numbers are recorded using the byte order of the application binary.
11995 The hash table begins at offset 16 in the section, and consists of an array
11996 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11997 order of the application binary). Unused slots in the hash table are 0.
11998 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12000 The parallel table begins immediately after the hash table
12001 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12002 array of 32-bit indexes (using the byte order of the application binary),
12003 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12004 table contains a 32-bit index into the pool of section numbers. For unused
12005 hash table slots, the corresponding entry in the parallel table will be 0.
12007 The pool of section numbers begins immediately following the hash table
12008 (at offset 16 + 12 * M from the beginning of the section). The pool of
12009 section numbers consists of an array of 32-bit words (using the byte order
12010 of the application binary). Each item in the array is indexed starting
12011 from 0. The hash table entry provides the index of the first section
12012 number in the set. Additional section numbers in the set follow, and the
12013 set is terminated by a 0 entry (section number 0 is not used in ELF).
12015 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12016 section must be the first entry in the set, and the .debug_abbrev.dwo must
12017 be the second entry. Other members of the set may follow in any order.
12023 DWP Version 2 combines all the .debug_info, etc. sections into one,
12024 and the entries in the index tables are now offsets into these sections.
12025 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12028 Index Section Contents:
12030 Hash Table of Signatures dwp_hash_table.hash_table
12031 Parallel Table of Indices dwp_hash_table.unit_table
12032 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12033 Table of Section Sizes dwp_hash_table.v2.sizes
12035 The index section header consists of:
12037 V, 32 bit version number
12038 L, 32 bit number of columns in the table of section offsets
12039 N, 32 bit number of compilation units or type units in the index
12040 M, 32 bit number of slots in the hash table
12042 Numbers are recorded using the byte order of the application binary.
12044 The hash table has the same format as version 1.
12045 The parallel table of indices has the same format as version 1,
12046 except that the entries are origin-1 indices into the table of sections
12047 offsets and the table of section sizes.
12049 The table of offsets begins immediately following the parallel table
12050 (at offset 16 + 12 * M from the beginning of the section). The table is
12051 a two-dimensional array of 32-bit words (using the byte order of the
12052 application binary), with L columns and N+1 rows, in row-major order.
12053 Each row in the array is indexed starting from 0. The first row provides
12054 a key to the remaining rows: each column in this row provides an identifier
12055 for a debug section, and the offsets in the same column of subsequent rows
12056 refer to that section. The section identifiers are:
12058 DW_SECT_INFO 1 .debug_info.dwo
12059 DW_SECT_TYPES 2 .debug_types.dwo
12060 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12061 DW_SECT_LINE 4 .debug_line.dwo
12062 DW_SECT_LOC 5 .debug_loc.dwo
12063 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12064 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12065 DW_SECT_MACRO 8 .debug_macro.dwo
12067 The offsets provided by the CU and TU index sections are the base offsets
12068 for the contributions made by each CU or TU to the corresponding section
12069 in the package file. Each CU and TU header contains an abbrev_offset
12070 field, used to find the abbreviations table for that CU or TU within the
12071 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12072 be interpreted as relative to the base offset given in the index section.
12073 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12074 should be interpreted as relative to the base offset for .debug_line.dwo,
12075 and offsets into other debug sections obtained from DWARF attributes should
12076 also be interpreted as relative to the corresponding base offset.
12078 The table of sizes begins immediately following the table of offsets.
12079 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12080 with L columns and N rows, in row-major order. Each row in the array is
12081 indexed starting from 1 (row 0 is shared by the two tables).
12085 Hash table lookup is handled the same in version 1 and 2:
12087 We assume that N and M will not exceed 2^32 - 1.
12088 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12090 Given a 64-bit compilation unit signature or a type signature S, an entry
12091 in the hash table is located as follows:
12093 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12094 the low-order k bits all set to 1.
12096 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12098 3) If the hash table entry at index H matches the signature, use that
12099 entry. If the hash table entry at index H is unused (all zeroes),
12100 terminate the search: the signature is not present in the table.
12102 4) Let H = (H + H') modulo M. Repeat at Step 3.
12104 Because M > N and H' and M are relatively prime, the search is guaranteed
12105 to stop at an unused slot or find the match. */
12107 /* Create a hash table to map DWO IDs to their CU/TU entry in
12108 .debug_{info,types}.dwo in DWP_FILE.
12109 Returns NULL if there isn't one.
12110 Note: This function processes DWP files only, not DWO files. */
12112 static struct dwp_hash_table
*
12113 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12114 struct dwp_file
*dwp_file
, int is_debug_types
)
12116 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12117 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12118 const gdb_byte
*index_ptr
, *index_end
;
12119 struct dwarf2_section_info
*index
;
12120 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12121 struct dwp_hash_table
*htab
;
12123 if (is_debug_types
)
12124 index
= &dwp_file
->sections
.tu_index
;
12126 index
= &dwp_file
->sections
.cu_index
;
12128 if (dwarf2_section_empty_p (index
))
12130 dwarf2_read_section (objfile
, index
);
12132 index_ptr
= index
->buffer
;
12133 index_end
= index_ptr
+ index
->size
;
12135 version
= read_4_bytes (dbfd
, index_ptr
);
12138 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12142 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12144 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12147 if (version
!= 1 && version
!= 2)
12149 error (_("Dwarf Error: unsupported DWP file version (%s)"
12150 " [in module %s]"),
12151 pulongest (version
), dwp_file
->name
);
12153 if (nr_slots
!= (nr_slots
& -nr_slots
))
12155 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12156 " is not power of 2 [in module %s]"),
12157 pulongest (nr_slots
), dwp_file
->name
);
12160 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12161 htab
->version
= version
;
12162 htab
->nr_columns
= nr_columns
;
12163 htab
->nr_units
= nr_units
;
12164 htab
->nr_slots
= nr_slots
;
12165 htab
->hash_table
= index_ptr
;
12166 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12168 /* Exit early if the table is empty. */
12169 if (nr_slots
== 0 || nr_units
== 0
12170 || (version
== 2 && nr_columns
== 0))
12172 /* All must be zero. */
12173 if (nr_slots
!= 0 || nr_units
!= 0
12174 || (version
== 2 && nr_columns
!= 0))
12176 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
12177 " all zero [in modules %s]"),
12185 htab
->section_pool
.v1
.indices
=
12186 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12187 /* It's harder to decide whether the section is too small in v1.
12188 V1 is deprecated anyway so we punt. */
12192 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12193 int *ids
= htab
->section_pool
.v2
.section_ids
;
12194 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
12195 /* Reverse map for error checking. */
12196 int ids_seen
[DW_SECT_MAX
+ 1];
12199 if (nr_columns
< 2)
12201 error (_("Dwarf Error: bad DWP hash table, too few columns"
12202 " in section table [in module %s]"),
12205 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12207 error (_("Dwarf Error: bad DWP hash table, too many columns"
12208 " in section table [in module %s]"),
12211 memset (ids
, 255, sizeof_ids
);
12212 memset (ids_seen
, 255, sizeof (ids_seen
));
12213 for (i
= 0; i
< nr_columns
; ++i
)
12215 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12217 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12219 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12220 " in section table [in module %s]"),
12221 id
, dwp_file
->name
);
12223 if (ids_seen
[id
] != -1)
12225 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12226 " id %d in section table [in module %s]"),
12227 id
, dwp_file
->name
);
12232 /* Must have exactly one info or types section. */
12233 if (((ids_seen
[DW_SECT_INFO
] != -1)
12234 + (ids_seen
[DW_SECT_TYPES
] != -1))
12237 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12238 " DWO info/types section [in module %s]"),
12241 /* Must have an abbrev section. */
12242 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12244 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12245 " section [in module %s]"),
12248 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12249 htab
->section_pool
.v2
.sizes
=
12250 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12251 * nr_units
* nr_columns
);
12252 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12253 * nr_units
* nr_columns
))
12256 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12257 " [in module %s]"),
12265 /* Update SECTIONS with the data from SECTP.
12267 This function is like the other "locate" section routines that are
12268 passed to bfd_map_over_sections, but in this context the sections to
12269 read comes from the DWP V1 hash table, not the full ELF section table.
12271 The result is non-zero for success, or zero if an error was found. */
12274 locate_v1_virtual_dwo_sections (asection
*sectp
,
12275 struct virtual_v1_dwo_sections
*sections
)
12277 const struct dwop_section_names
*names
= &dwop_section_names
;
12279 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12281 /* There can be only one. */
12282 if (sections
->abbrev
.s
.section
!= NULL
)
12284 sections
->abbrev
.s
.section
= sectp
;
12285 sections
->abbrev
.size
= bfd_section_size (sectp
);
12287 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12288 || section_is_p (sectp
->name
, &names
->types_dwo
))
12290 /* There can be only one. */
12291 if (sections
->info_or_types
.s
.section
!= NULL
)
12293 sections
->info_or_types
.s
.section
= sectp
;
12294 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12296 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12298 /* There can be only one. */
12299 if (sections
->line
.s
.section
!= NULL
)
12301 sections
->line
.s
.section
= sectp
;
12302 sections
->line
.size
= bfd_section_size (sectp
);
12304 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12306 /* There can be only one. */
12307 if (sections
->loc
.s
.section
!= NULL
)
12309 sections
->loc
.s
.section
= sectp
;
12310 sections
->loc
.size
= bfd_section_size (sectp
);
12312 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12314 /* There can be only one. */
12315 if (sections
->macinfo
.s
.section
!= NULL
)
12317 sections
->macinfo
.s
.section
= sectp
;
12318 sections
->macinfo
.size
= bfd_section_size (sectp
);
12320 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12322 /* There can be only one. */
12323 if (sections
->macro
.s
.section
!= NULL
)
12325 sections
->macro
.s
.section
= sectp
;
12326 sections
->macro
.size
= bfd_section_size (sectp
);
12328 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12330 /* There can be only one. */
12331 if (sections
->str_offsets
.s
.section
!= NULL
)
12333 sections
->str_offsets
.s
.section
= sectp
;
12334 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12338 /* No other kind of section is valid. */
12345 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12346 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12347 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12348 This is for DWP version 1 files. */
12350 static struct dwo_unit
*
12351 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12352 struct dwp_file
*dwp_file
,
12353 uint32_t unit_index
,
12354 const char *comp_dir
,
12355 ULONGEST signature
, int is_debug_types
)
12357 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12358 const struct dwp_hash_table
*dwp_htab
=
12359 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12360 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12361 const char *kind
= is_debug_types
? "TU" : "CU";
12362 struct dwo_file
*dwo_file
;
12363 struct dwo_unit
*dwo_unit
;
12364 struct virtual_v1_dwo_sections sections
;
12365 void **dwo_file_slot
;
12368 gdb_assert (dwp_file
->version
== 1);
12370 if (dwarf_read_debug
)
12372 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12374 pulongest (unit_index
), hex_string (signature
),
12378 /* Fetch the sections of this DWO unit.
12379 Put a limit on the number of sections we look for so that bad data
12380 doesn't cause us to loop forever. */
12382 #define MAX_NR_V1_DWO_SECTIONS \
12383 (1 /* .debug_info or .debug_types */ \
12384 + 1 /* .debug_abbrev */ \
12385 + 1 /* .debug_line */ \
12386 + 1 /* .debug_loc */ \
12387 + 1 /* .debug_str_offsets */ \
12388 + 1 /* .debug_macro or .debug_macinfo */ \
12389 + 1 /* trailing zero */)
12391 memset (§ions
, 0, sizeof (sections
));
12393 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12396 uint32_t section_nr
=
12397 read_4_bytes (dbfd
,
12398 dwp_htab
->section_pool
.v1
.indices
12399 + (unit_index
+ i
) * sizeof (uint32_t));
12401 if (section_nr
== 0)
12403 if (section_nr
>= dwp_file
->num_sections
)
12405 error (_("Dwarf Error: bad DWP hash table, section number too large"
12406 " [in module %s]"),
12410 sectp
= dwp_file
->elf_sections
[section_nr
];
12411 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12413 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12414 " [in module %s]"),
12420 || dwarf2_section_empty_p (§ions
.info_or_types
)
12421 || dwarf2_section_empty_p (§ions
.abbrev
))
12423 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12424 " [in module %s]"),
12427 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12429 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12430 " [in module %s]"),
12434 /* It's easier for the rest of the code if we fake a struct dwo_file and
12435 have dwo_unit "live" in that. At least for now.
12437 The DWP file can be made up of a random collection of CUs and TUs.
12438 However, for each CU + set of TUs that came from the same original DWO
12439 file, we can combine them back into a virtual DWO file to save space
12440 (fewer struct dwo_file objects to allocate). Remember that for really
12441 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12443 std::string virtual_dwo_name
=
12444 string_printf ("virtual-dwo/%d-%d-%d-%d",
12445 get_section_id (§ions
.abbrev
),
12446 get_section_id (§ions
.line
),
12447 get_section_id (§ions
.loc
),
12448 get_section_id (§ions
.str_offsets
));
12449 /* Can we use an existing virtual DWO file? */
12450 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12451 virtual_dwo_name
.c_str (),
12453 /* Create one if necessary. */
12454 if (*dwo_file_slot
== NULL
)
12456 if (dwarf_read_debug
)
12458 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12459 virtual_dwo_name
.c_str ());
12461 dwo_file
= new struct dwo_file
;
12462 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12464 dwo_file
->comp_dir
= comp_dir
;
12465 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12466 dwo_file
->sections
.line
= sections
.line
;
12467 dwo_file
->sections
.loc
= sections
.loc
;
12468 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12469 dwo_file
->sections
.macro
= sections
.macro
;
12470 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12471 /* The "str" section is global to the entire DWP file. */
12472 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12473 /* The info or types section is assigned below to dwo_unit,
12474 there's no need to record it in dwo_file.
12475 Also, we can't simply record type sections in dwo_file because
12476 we record a pointer into the vector in dwo_unit. As we collect more
12477 types we'll grow the vector and eventually have to reallocate space
12478 for it, invalidating all copies of pointers into the previous
12480 *dwo_file_slot
= dwo_file
;
12484 if (dwarf_read_debug
)
12486 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12487 virtual_dwo_name
.c_str ());
12489 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12492 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12493 dwo_unit
->dwo_file
= dwo_file
;
12494 dwo_unit
->signature
= signature
;
12495 dwo_unit
->section
=
12496 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12497 *dwo_unit
->section
= sections
.info_or_types
;
12498 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12503 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12504 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12505 piece within that section used by a TU/CU, return a virtual section
12506 of just that piece. */
12508 static struct dwarf2_section_info
12509 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12510 struct dwarf2_section_info
*section
,
12511 bfd_size_type offset
, bfd_size_type size
)
12513 struct dwarf2_section_info result
;
12516 gdb_assert (section
!= NULL
);
12517 gdb_assert (!section
->is_virtual
);
12519 memset (&result
, 0, sizeof (result
));
12520 result
.s
.containing_section
= section
;
12521 result
.is_virtual
= true;
12526 sectp
= get_section_bfd_section (section
);
12528 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12529 bounds of the real section. This is a pretty-rare event, so just
12530 flag an error (easier) instead of a warning and trying to cope. */
12532 || offset
+ size
> bfd_section_size (sectp
))
12534 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12535 " in section %s [in module %s]"),
12536 sectp
? bfd_section_name (sectp
) : "<unknown>",
12537 objfile_name (dwarf2_per_objfile
->objfile
));
12540 result
.virtual_offset
= offset
;
12541 result
.size
= size
;
12545 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12546 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12547 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12548 This is for DWP version 2 files. */
12550 static struct dwo_unit
*
12551 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12552 struct dwp_file
*dwp_file
,
12553 uint32_t unit_index
,
12554 const char *comp_dir
,
12555 ULONGEST signature
, int is_debug_types
)
12557 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12558 const struct dwp_hash_table
*dwp_htab
=
12559 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12560 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12561 const char *kind
= is_debug_types
? "TU" : "CU";
12562 struct dwo_file
*dwo_file
;
12563 struct dwo_unit
*dwo_unit
;
12564 struct virtual_v2_dwo_sections sections
;
12565 void **dwo_file_slot
;
12568 gdb_assert (dwp_file
->version
== 2);
12570 if (dwarf_read_debug
)
12572 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12574 pulongest (unit_index
), hex_string (signature
),
12578 /* Fetch the section offsets of this DWO unit. */
12580 memset (§ions
, 0, sizeof (sections
));
12582 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12584 uint32_t offset
= read_4_bytes (dbfd
,
12585 dwp_htab
->section_pool
.v2
.offsets
12586 + (((unit_index
- 1) * dwp_htab
->nr_columns
12588 * sizeof (uint32_t)));
12589 uint32_t size
= read_4_bytes (dbfd
,
12590 dwp_htab
->section_pool
.v2
.sizes
12591 + (((unit_index
- 1) * dwp_htab
->nr_columns
12593 * sizeof (uint32_t)));
12595 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12598 case DW_SECT_TYPES
:
12599 sections
.info_or_types_offset
= offset
;
12600 sections
.info_or_types_size
= size
;
12602 case DW_SECT_ABBREV
:
12603 sections
.abbrev_offset
= offset
;
12604 sections
.abbrev_size
= size
;
12607 sections
.line_offset
= offset
;
12608 sections
.line_size
= size
;
12611 sections
.loc_offset
= offset
;
12612 sections
.loc_size
= size
;
12614 case DW_SECT_STR_OFFSETS
:
12615 sections
.str_offsets_offset
= offset
;
12616 sections
.str_offsets_size
= size
;
12618 case DW_SECT_MACINFO
:
12619 sections
.macinfo_offset
= offset
;
12620 sections
.macinfo_size
= size
;
12622 case DW_SECT_MACRO
:
12623 sections
.macro_offset
= offset
;
12624 sections
.macro_size
= size
;
12629 /* It's easier for the rest of the code if we fake a struct dwo_file and
12630 have dwo_unit "live" in that. At least for now.
12632 The DWP file can be made up of a random collection of CUs and TUs.
12633 However, for each CU + set of TUs that came from the same original DWO
12634 file, we can combine them back into a virtual DWO file to save space
12635 (fewer struct dwo_file objects to allocate). Remember that for really
12636 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12638 std::string virtual_dwo_name
=
12639 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12640 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12641 (long) (sections
.line_size
? sections
.line_offset
: 0),
12642 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12643 (long) (sections
.str_offsets_size
12644 ? sections
.str_offsets_offset
: 0));
12645 /* Can we use an existing virtual DWO file? */
12646 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12647 virtual_dwo_name
.c_str (),
12649 /* Create one if necessary. */
12650 if (*dwo_file_slot
== NULL
)
12652 if (dwarf_read_debug
)
12654 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12655 virtual_dwo_name
.c_str ());
12657 dwo_file
= new struct dwo_file
;
12658 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12660 dwo_file
->comp_dir
= comp_dir
;
12661 dwo_file
->sections
.abbrev
=
12662 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12663 sections
.abbrev_offset
, sections
.abbrev_size
);
12664 dwo_file
->sections
.line
=
12665 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12666 sections
.line_offset
, sections
.line_size
);
12667 dwo_file
->sections
.loc
=
12668 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12669 sections
.loc_offset
, sections
.loc_size
);
12670 dwo_file
->sections
.macinfo
=
12671 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12672 sections
.macinfo_offset
, sections
.macinfo_size
);
12673 dwo_file
->sections
.macro
=
12674 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12675 sections
.macro_offset
, sections
.macro_size
);
12676 dwo_file
->sections
.str_offsets
=
12677 create_dwp_v2_section (dwarf2_per_objfile
,
12678 &dwp_file
->sections
.str_offsets
,
12679 sections
.str_offsets_offset
,
12680 sections
.str_offsets_size
);
12681 /* The "str" section is global to the entire DWP file. */
12682 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12683 /* The info or types section is assigned below to dwo_unit,
12684 there's no need to record it in dwo_file.
12685 Also, we can't simply record type sections in dwo_file because
12686 we record a pointer into the vector in dwo_unit. As we collect more
12687 types we'll grow the vector and eventually have to reallocate space
12688 for it, invalidating all copies of pointers into the previous
12690 *dwo_file_slot
= dwo_file
;
12694 if (dwarf_read_debug
)
12696 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12697 virtual_dwo_name
.c_str ());
12699 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12702 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12703 dwo_unit
->dwo_file
= dwo_file
;
12704 dwo_unit
->signature
= signature
;
12705 dwo_unit
->section
=
12706 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12707 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12709 ? &dwp_file
->sections
.types
12710 : &dwp_file
->sections
.info
,
12711 sections
.info_or_types_offset
,
12712 sections
.info_or_types_size
);
12713 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12718 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12719 Returns NULL if the signature isn't found. */
12721 static struct dwo_unit
*
12722 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12723 struct dwp_file
*dwp_file
, const char *comp_dir
,
12724 ULONGEST signature
, int is_debug_types
)
12726 const struct dwp_hash_table
*dwp_htab
=
12727 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12728 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12729 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12730 uint32_t hash
= signature
& mask
;
12731 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12734 struct dwo_unit find_dwo_cu
;
12736 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12737 find_dwo_cu
.signature
= signature
;
12738 slot
= htab_find_slot (is_debug_types
12739 ? dwp_file
->loaded_tus
12740 : dwp_file
->loaded_cus
,
12741 &find_dwo_cu
, INSERT
);
12744 return (struct dwo_unit
*) *slot
;
12746 /* Use a for loop so that we don't loop forever on bad debug info. */
12747 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12749 ULONGEST signature_in_table
;
12751 signature_in_table
=
12752 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12753 if (signature_in_table
== signature
)
12755 uint32_t unit_index
=
12756 read_4_bytes (dbfd
,
12757 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12759 if (dwp_file
->version
== 1)
12761 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12762 dwp_file
, unit_index
,
12763 comp_dir
, signature
,
12768 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12769 dwp_file
, unit_index
,
12770 comp_dir
, signature
,
12773 return (struct dwo_unit
*) *slot
;
12775 if (signature_in_table
== 0)
12777 hash
= (hash
+ hash2
) & mask
;
12780 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12781 " [in module %s]"),
12785 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12786 Open the file specified by FILE_NAME and hand it off to BFD for
12787 preliminary analysis. Return a newly initialized bfd *, which
12788 includes a canonicalized copy of FILE_NAME.
12789 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12790 SEARCH_CWD is true if the current directory is to be searched.
12791 It will be searched before debug-file-directory.
12792 If successful, the file is added to the bfd include table of the
12793 objfile's bfd (see gdb_bfd_record_inclusion).
12794 If unable to find/open the file, return NULL.
12795 NOTE: This function is derived from symfile_bfd_open. */
12797 static gdb_bfd_ref_ptr
12798 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12799 const char *file_name
, int is_dwp
, int search_cwd
)
12802 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12803 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12804 to debug_file_directory. */
12805 const char *search_path
;
12806 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12808 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12811 if (*debug_file_directory
!= '\0')
12813 search_path_holder
.reset (concat (".", dirname_separator_string
,
12814 debug_file_directory
,
12816 search_path
= search_path_holder
.get ();
12822 search_path
= debug_file_directory
;
12824 openp_flags flags
= OPF_RETURN_REALPATH
;
12826 flags
|= OPF_SEARCH_IN_PATH
;
12828 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12829 desc
= openp (search_path
, flags
, file_name
,
12830 O_RDONLY
| O_BINARY
, &absolute_name
);
12834 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12836 if (sym_bfd
== NULL
)
12838 bfd_set_cacheable (sym_bfd
.get (), 1);
12840 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12843 /* Success. Record the bfd as having been included by the objfile's bfd.
12844 This is important because things like demangled_names_hash lives in the
12845 objfile's per_bfd space and may have references to things like symbol
12846 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12847 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12852 /* Try to open DWO file FILE_NAME.
12853 COMP_DIR is the DW_AT_comp_dir attribute.
12854 The result is the bfd handle of the file.
12855 If there is a problem finding or opening the file, return NULL.
12856 Upon success, the canonicalized path of the file is stored in the bfd,
12857 same as symfile_bfd_open. */
12859 static gdb_bfd_ref_ptr
12860 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12861 const char *file_name
, const char *comp_dir
)
12863 if (IS_ABSOLUTE_PATH (file_name
))
12864 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12865 0 /*is_dwp*/, 0 /*search_cwd*/);
12867 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12869 if (comp_dir
!= NULL
)
12871 gdb::unique_xmalloc_ptr
<char> path_to_try
12872 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12874 /* NOTE: If comp_dir is a relative path, this will also try the
12875 search path, which seems useful. */
12876 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12877 path_to_try
.get (),
12879 1 /*search_cwd*/));
12884 /* That didn't work, try debug-file-directory, which, despite its name,
12885 is a list of paths. */
12887 if (*debug_file_directory
== '\0')
12890 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12891 0 /*is_dwp*/, 1 /*search_cwd*/);
12894 /* This function is mapped across the sections and remembers the offset and
12895 size of each of the DWO debugging sections we are interested in. */
12898 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12900 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12901 const struct dwop_section_names
*names
= &dwop_section_names
;
12903 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12905 dwo_sections
->abbrev
.s
.section
= sectp
;
12906 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12908 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12910 dwo_sections
->info
.s
.section
= sectp
;
12911 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12913 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12915 dwo_sections
->line
.s
.section
= sectp
;
12916 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12918 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12920 dwo_sections
->loc
.s
.section
= sectp
;
12921 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12923 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12925 dwo_sections
->macinfo
.s
.section
= sectp
;
12926 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12928 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12930 dwo_sections
->macro
.s
.section
= sectp
;
12931 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12933 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12935 dwo_sections
->str
.s
.section
= sectp
;
12936 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12938 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12940 dwo_sections
->str_offsets
.s
.section
= sectp
;
12941 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12943 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12945 struct dwarf2_section_info type_section
;
12947 memset (&type_section
, 0, sizeof (type_section
));
12948 type_section
.s
.section
= sectp
;
12949 type_section
.size
= bfd_section_size (sectp
);
12950 dwo_sections
->types
.push_back (type_section
);
12954 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12955 by PER_CU. This is for the non-DWP case.
12956 The result is NULL if DWO_NAME can't be found. */
12958 static struct dwo_file
*
12959 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12960 const char *dwo_name
, const char *comp_dir
)
12962 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12964 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12967 if (dwarf_read_debug
)
12968 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12972 dwo_file_up
dwo_file (new struct dwo_file
);
12973 dwo_file
->dwo_name
= dwo_name
;
12974 dwo_file
->comp_dir
= comp_dir
;
12975 dwo_file
->dbfd
= std::move (dbfd
);
12977 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12978 &dwo_file
->sections
);
12980 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12981 dwo_file
->sections
.info
, dwo_file
->cus
);
12983 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12984 dwo_file
->sections
.types
, dwo_file
->tus
);
12986 if (dwarf_read_debug
)
12987 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12989 return dwo_file
.release ();
12992 /* This function is mapped across the sections and remembers the offset and
12993 size of each of the DWP debugging sections common to version 1 and 2 that
12994 we are interested in. */
12997 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12998 void *dwp_file_ptr
)
13000 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13001 const struct dwop_section_names
*names
= &dwop_section_names
;
13002 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13004 /* Record the ELF section number for later lookup: this is what the
13005 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13006 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13007 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13009 /* Look for specific sections that we need. */
13010 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13012 dwp_file
->sections
.str
.s
.section
= sectp
;
13013 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
13015 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13017 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13018 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
13020 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13022 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13023 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
13027 /* This function is mapped across the sections and remembers the offset and
13028 size of each of the DWP version 2 debugging sections that we are interested
13029 in. This is split into a separate function because we don't know if we
13030 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13033 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13035 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13036 const struct dwop_section_names
*names
= &dwop_section_names
;
13037 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13039 /* Record the ELF section number for later lookup: this is what the
13040 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13041 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13042 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13044 /* Look for specific sections that we need. */
13045 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13047 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13048 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13050 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13052 dwp_file
->sections
.info
.s
.section
= sectp
;
13053 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13055 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13057 dwp_file
->sections
.line
.s
.section
= sectp
;
13058 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13060 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13062 dwp_file
->sections
.loc
.s
.section
= sectp
;
13063 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
13065 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13067 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13068 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
13070 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13072 dwp_file
->sections
.macro
.s
.section
= sectp
;
13073 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13075 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13077 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13078 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13080 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13082 dwp_file
->sections
.types
.s
.section
= sectp
;
13083 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13087 /* Hash function for dwp_file loaded CUs/TUs. */
13090 hash_dwp_loaded_cutus (const void *item
)
13092 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13094 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13095 return dwo_unit
->signature
;
13098 /* Equality function for dwp_file loaded CUs/TUs. */
13101 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13103 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13104 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13106 return dua
->signature
== dub
->signature
;
13109 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13112 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13114 return htab_create_alloc_ex (3,
13115 hash_dwp_loaded_cutus
,
13116 eq_dwp_loaded_cutus
,
13118 &objfile
->objfile_obstack
,
13119 hashtab_obstack_allocate
,
13120 dummy_obstack_deallocate
);
13123 /* Try to open DWP file FILE_NAME.
13124 The result is the bfd handle of the file.
13125 If there is a problem finding or opening the file, return NULL.
13126 Upon success, the canonicalized path of the file is stored in the bfd,
13127 same as symfile_bfd_open. */
13129 static gdb_bfd_ref_ptr
13130 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13131 const char *file_name
)
13133 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13135 1 /*search_cwd*/));
13139 /* Work around upstream bug 15652.
13140 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13141 [Whether that's a "bug" is debatable, but it is getting in our way.]
13142 We have no real idea where the dwp file is, because gdb's realpath-ing
13143 of the executable's path may have discarded the needed info.
13144 [IWBN if the dwp file name was recorded in the executable, akin to
13145 .gnu_debuglink, but that doesn't exist yet.]
13146 Strip the directory from FILE_NAME and search again. */
13147 if (*debug_file_directory
!= '\0')
13149 /* Don't implicitly search the current directory here.
13150 If the user wants to search "." to handle this case,
13151 it must be added to debug-file-directory. */
13152 return try_open_dwop_file (dwarf2_per_objfile
,
13153 lbasename (file_name
), 1 /*is_dwp*/,
13160 /* Initialize the use of the DWP file for the current objfile.
13161 By convention the name of the DWP file is ${objfile}.dwp.
13162 The result is NULL if it can't be found. */
13164 static std::unique_ptr
<struct dwp_file
>
13165 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13167 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13169 /* Try to find first .dwp for the binary file before any symbolic links
13172 /* If the objfile is a debug file, find the name of the real binary
13173 file and get the name of dwp file from there. */
13174 std::string dwp_name
;
13175 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13177 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13178 const char *backlink_basename
= lbasename (backlink
->original_name
);
13180 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13183 dwp_name
= objfile
->original_name
;
13185 dwp_name
+= ".dwp";
13187 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13189 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13191 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13192 dwp_name
= objfile_name (objfile
);
13193 dwp_name
+= ".dwp";
13194 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13199 if (dwarf_read_debug
)
13200 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13201 return std::unique_ptr
<dwp_file
> ();
13204 const char *name
= bfd_get_filename (dbfd
.get ());
13205 std::unique_ptr
<struct dwp_file
> dwp_file
13206 (new struct dwp_file (name
, std::move (dbfd
)));
13208 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13209 dwp_file
->elf_sections
=
13210 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13211 dwp_file
->num_sections
, asection
*);
13213 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13214 dwarf2_locate_common_dwp_sections
,
13217 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13220 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13223 /* The DWP file version is stored in the hash table. Oh well. */
13224 if (dwp_file
->cus
&& dwp_file
->tus
13225 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13227 /* Technically speaking, we should try to limp along, but this is
13228 pretty bizarre. We use pulongest here because that's the established
13229 portability solution (e.g, we cannot use %u for uint32_t). */
13230 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13231 " TU version %s [in DWP file %s]"),
13232 pulongest (dwp_file
->cus
->version
),
13233 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13237 dwp_file
->version
= dwp_file
->cus
->version
;
13238 else if (dwp_file
->tus
)
13239 dwp_file
->version
= dwp_file
->tus
->version
;
13241 dwp_file
->version
= 2;
13243 if (dwp_file
->version
== 2)
13244 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13245 dwarf2_locate_v2_dwp_sections
,
13248 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13249 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13251 if (dwarf_read_debug
)
13253 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13254 fprintf_unfiltered (gdb_stdlog
,
13255 " %s CUs, %s TUs\n",
13256 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13257 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13263 /* Wrapper around open_and_init_dwp_file, only open it once. */
13265 static struct dwp_file
*
13266 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13268 if (! dwarf2_per_objfile
->dwp_checked
)
13270 dwarf2_per_objfile
->dwp_file
13271 = open_and_init_dwp_file (dwarf2_per_objfile
);
13272 dwarf2_per_objfile
->dwp_checked
= 1;
13274 return dwarf2_per_objfile
->dwp_file
.get ();
13277 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13278 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13279 or in the DWP file for the objfile, referenced by THIS_UNIT.
13280 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13281 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13283 This is called, for example, when wanting to read a variable with a
13284 complex location. Therefore we don't want to do file i/o for every call.
13285 Therefore we don't want to look for a DWO file on every call.
13286 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13287 then we check if we've already seen DWO_NAME, and only THEN do we check
13290 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13291 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13293 static struct dwo_unit
*
13294 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13295 const char *dwo_name
, const char *comp_dir
,
13296 ULONGEST signature
, int is_debug_types
)
13298 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13299 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13300 const char *kind
= is_debug_types
? "TU" : "CU";
13301 void **dwo_file_slot
;
13302 struct dwo_file
*dwo_file
;
13303 struct dwp_file
*dwp_file
;
13305 /* First see if there's a DWP file.
13306 If we have a DWP file but didn't find the DWO inside it, don't
13307 look for the original DWO file. It makes gdb behave differently
13308 depending on whether one is debugging in the build tree. */
13310 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13311 if (dwp_file
!= NULL
)
13313 const struct dwp_hash_table
*dwp_htab
=
13314 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13316 if (dwp_htab
!= NULL
)
13318 struct dwo_unit
*dwo_cutu
=
13319 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13320 signature
, is_debug_types
);
13322 if (dwo_cutu
!= NULL
)
13324 if (dwarf_read_debug
)
13326 fprintf_unfiltered (gdb_stdlog
,
13327 "Virtual DWO %s %s found: @%s\n",
13328 kind
, hex_string (signature
),
13329 host_address_to_string (dwo_cutu
));
13337 /* No DWP file, look for the DWO file. */
13339 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13340 dwo_name
, comp_dir
);
13341 if (*dwo_file_slot
== NULL
)
13343 /* Read in the file and build a table of the CUs/TUs it contains. */
13344 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13346 /* NOTE: This will be NULL if unable to open the file. */
13347 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13349 if (dwo_file
!= NULL
)
13351 struct dwo_unit
*dwo_cutu
= NULL
;
13353 if (is_debug_types
&& dwo_file
->tus
)
13355 struct dwo_unit find_dwo_cutu
;
13357 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13358 find_dwo_cutu
.signature
= signature
;
13360 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13362 else if (!is_debug_types
&& dwo_file
->cus
)
13364 struct dwo_unit find_dwo_cutu
;
13366 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13367 find_dwo_cutu
.signature
= signature
;
13368 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13372 if (dwo_cutu
!= NULL
)
13374 if (dwarf_read_debug
)
13376 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13377 kind
, dwo_name
, hex_string (signature
),
13378 host_address_to_string (dwo_cutu
));
13385 /* We didn't find it. This could mean a dwo_id mismatch, or
13386 someone deleted the DWO/DWP file, or the search path isn't set up
13387 correctly to find the file. */
13389 if (dwarf_read_debug
)
13391 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13392 kind
, dwo_name
, hex_string (signature
));
13395 /* This is a warning and not a complaint because it can be caused by
13396 pilot error (e.g., user accidentally deleting the DWO). */
13398 /* Print the name of the DWP file if we looked there, helps the user
13399 better diagnose the problem. */
13400 std::string dwp_text
;
13402 if (dwp_file
!= NULL
)
13403 dwp_text
= string_printf (" [in DWP file %s]",
13404 lbasename (dwp_file
->name
));
13406 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13407 " [in module %s]"),
13408 kind
, dwo_name
, hex_string (signature
),
13410 this_unit
->is_debug_types
? "TU" : "CU",
13411 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13416 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13417 See lookup_dwo_cutu_unit for details. */
13419 static struct dwo_unit
*
13420 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13421 const char *dwo_name
, const char *comp_dir
,
13422 ULONGEST signature
)
13424 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13427 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13428 See lookup_dwo_cutu_unit for details. */
13430 static struct dwo_unit
*
13431 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13432 const char *dwo_name
, const char *comp_dir
)
13434 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13437 /* Traversal function for queue_and_load_all_dwo_tus. */
13440 queue_and_load_dwo_tu (void **slot
, void *info
)
13442 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13443 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13444 ULONGEST signature
= dwo_unit
->signature
;
13445 struct signatured_type
*sig_type
=
13446 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13448 if (sig_type
!= NULL
)
13450 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13452 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13453 a real dependency of PER_CU on SIG_TYPE. That is detected later
13454 while processing PER_CU. */
13455 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13456 load_full_type_unit (sig_cu
);
13457 per_cu
->imported_symtabs_push (sig_cu
);
13463 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13464 The DWO may have the only definition of the type, though it may not be
13465 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13466 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13469 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13471 struct dwo_unit
*dwo_unit
;
13472 struct dwo_file
*dwo_file
;
13474 gdb_assert (!per_cu
->is_debug_types
);
13475 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13476 gdb_assert (per_cu
->cu
!= NULL
);
13478 dwo_unit
= per_cu
->cu
->dwo_unit
;
13479 gdb_assert (dwo_unit
!= NULL
);
13481 dwo_file
= dwo_unit
->dwo_file
;
13482 if (dwo_file
->tus
!= NULL
)
13483 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13486 /* Read in various DIEs. */
13488 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13489 Inherit only the children of the DW_AT_abstract_origin DIE not being
13490 already referenced by DW_AT_abstract_origin from the children of the
13494 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13496 struct die_info
*child_die
;
13497 sect_offset
*offsetp
;
13498 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13499 struct die_info
*origin_die
;
13500 /* Iterator of the ORIGIN_DIE children. */
13501 struct die_info
*origin_child_die
;
13502 struct attribute
*attr
;
13503 struct dwarf2_cu
*origin_cu
;
13504 struct pending
**origin_previous_list_in_scope
;
13506 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13510 /* Note that following die references may follow to a die in a
13514 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13516 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13518 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13519 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13521 if (die
->tag
!= origin_die
->tag
13522 && !(die
->tag
== DW_TAG_inlined_subroutine
13523 && origin_die
->tag
== DW_TAG_subprogram
))
13524 complaint (_("DIE %s and its abstract origin %s have different tags"),
13525 sect_offset_str (die
->sect_off
),
13526 sect_offset_str (origin_die
->sect_off
));
13528 std::vector
<sect_offset
> offsets
;
13530 for (child_die
= die
->child
;
13531 child_die
&& child_die
->tag
;
13532 child_die
= sibling_die (child_die
))
13534 struct die_info
*child_origin_die
;
13535 struct dwarf2_cu
*child_origin_cu
;
13537 /* We are trying to process concrete instance entries:
13538 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13539 it's not relevant to our analysis here. i.e. detecting DIEs that are
13540 present in the abstract instance but not referenced in the concrete
13542 if (child_die
->tag
== DW_TAG_call_site
13543 || child_die
->tag
== DW_TAG_GNU_call_site
)
13546 /* For each CHILD_DIE, find the corresponding child of
13547 ORIGIN_DIE. If there is more than one layer of
13548 DW_AT_abstract_origin, follow them all; there shouldn't be,
13549 but GCC versions at least through 4.4 generate this (GCC PR
13551 child_origin_die
= child_die
;
13552 child_origin_cu
= cu
;
13555 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13559 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13563 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13564 counterpart may exist. */
13565 if (child_origin_die
!= child_die
)
13567 if (child_die
->tag
!= child_origin_die
->tag
13568 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13569 && child_origin_die
->tag
== DW_TAG_subprogram
))
13570 complaint (_("Child DIE %s and its abstract origin %s have "
13572 sect_offset_str (child_die
->sect_off
),
13573 sect_offset_str (child_origin_die
->sect_off
));
13574 if (child_origin_die
->parent
!= origin_die
)
13575 complaint (_("Child DIE %s and its abstract origin %s have "
13576 "different parents"),
13577 sect_offset_str (child_die
->sect_off
),
13578 sect_offset_str (child_origin_die
->sect_off
));
13580 offsets
.push_back (child_origin_die
->sect_off
);
13583 std::sort (offsets
.begin (), offsets
.end ());
13584 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13585 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13586 if (offsetp
[-1] == *offsetp
)
13587 complaint (_("Multiple children of DIE %s refer "
13588 "to DIE %s as their abstract origin"),
13589 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13591 offsetp
= offsets
.data ();
13592 origin_child_die
= origin_die
->child
;
13593 while (origin_child_die
&& origin_child_die
->tag
)
13595 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13596 while (offsetp
< offsets_end
13597 && *offsetp
< origin_child_die
->sect_off
)
13599 if (offsetp
>= offsets_end
13600 || *offsetp
> origin_child_die
->sect_off
)
13602 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13603 Check whether we're already processing ORIGIN_CHILD_DIE.
13604 This can happen with mutually referenced abstract_origins.
13606 if (!origin_child_die
->in_process
)
13607 process_die (origin_child_die
, origin_cu
);
13609 origin_child_die
= sibling_die (origin_child_die
);
13611 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13613 if (cu
!= origin_cu
)
13614 compute_delayed_physnames (origin_cu
);
13618 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13620 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13621 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13622 struct context_stack
*newobj
;
13625 struct die_info
*child_die
;
13626 struct attribute
*attr
, *call_line
, *call_file
;
13628 CORE_ADDR baseaddr
;
13629 struct block
*block
;
13630 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13631 std::vector
<struct symbol
*> template_args
;
13632 struct template_symbol
*templ_func
= NULL
;
13636 /* If we do not have call site information, we can't show the
13637 caller of this inlined function. That's too confusing, so
13638 only use the scope for local variables. */
13639 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13640 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13641 if (call_line
== NULL
|| call_file
== NULL
)
13643 read_lexical_block_scope (die
, cu
);
13648 baseaddr
= objfile
->text_section_offset ();
13650 name
= dwarf2_name (die
, cu
);
13652 /* Ignore functions with missing or empty names. These are actually
13653 illegal according to the DWARF standard. */
13656 complaint (_("missing name for subprogram DIE at %s"),
13657 sect_offset_str (die
->sect_off
));
13661 /* Ignore functions with missing or invalid low and high pc attributes. */
13662 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13663 <= PC_BOUNDS_INVALID
)
13665 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13666 if (!attr
|| !DW_UNSND (attr
))
13667 complaint (_("cannot get low and high bounds "
13668 "for subprogram DIE at %s"),
13669 sect_offset_str (die
->sect_off
));
13673 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13674 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13676 /* If we have any template arguments, then we must allocate a
13677 different sort of symbol. */
13678 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13680 if (child_die
->tag
== DW_TAG_template_type_param
13681 || child_die
->tag
== DW_TAG_template_value_param
)
13683 templ_func
= allocate_template_symbol (objfile
);
13684 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13689 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13690 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13691 (struct symbol
*) templ_func
);
13693 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13694 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13697 /* If there is a location expression for DW_AT_frame_base, record
13699 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13700 if (attr
!= nullptr)
13701 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13703 /* If there is a location for the static link, record it. */
13704 newobj
->static_link
= NULL
;
13705 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13706 if (attr
!= nullptr)
13708 newobj
->static_link
13709 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13710 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13711 dwarf2_per_cu_addr_type (cu
->per_cu
));
13714 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13716 if (die
->child
!= NULL
)
13718 child_die
= die
->child
;
13719 while (child_die
&& child_die
->tag
)
13721 if (child_die
->tag
== DW_TAG_template_type_param
13722 || child_die
->tag
== DW_TAG_template_value_param
)
13724 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13727 template_args
.push_back (arg
);
13730 process_die (child_die
, cu
);
13731 child_die
= sibling_die (child_die
);
13735 inherit_abstract_dies (die
, cu
);
13737 /* If we have a DW_AT_specification, we might need to import using
13738 directives from the context of the specification DIE. See the
13739 comment in determine_prefix. */
13740 if (cu
->language
== language_cplus
13741 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13743 struct dwarf2_cu
*spec_cu
= cu
;
13744 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13748 child_die
= spec_die
->child
;
13749 while (child_die
&& child_die
->tag
)
13751 if (child_die
->tag
== DW_TAG_imported_module
)
13752 process_die (child_die
, spec_cu
);
13753 child_die
= sibling_die (child_die
);
13756 /* In some cases, GCC generates specification DIEs that
13757 themselves contain DW_AT_specification attributes. */
13758 spec_die
= die_specification (spec_die
, &spec_cu
);
13762 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13763 /* Make a block for the local symbols within. */
13764 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13765 cstk
.static_link
, lowpc
, highpc
);
13767 /* For C++, set the block's scope. */
13768 if ((cu
->language
== language_cplus
13769 || cu
->language
== language_fortran
13770 || cu
->language
== language_d
13771 || cu
->language
== language_rust
)
13772 && cu
->processing_has_namespace_info
)
13773 block_set_scope (block
, determine_prefix (die
, cu
),
13774 &objfile
->objfile_obstack
);
13776 /* If we have address ranges, record them. */
13777 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13779 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13781 /* Attach template arguments to function. */
13782 if (!template_args
.empty ())
13784 gdb_assert (templ_func
!= NULL
);
13786 templ_func
->n_template_arguments
= template_args
.size ();
13787 templ_func
->template_arguments
13788 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13789 templ_func
->n_template_arguments
);
13790 memcpy (templ_func
->template_arguments
,
13791 template_args
.data (),
13792 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13794 /* Make sure that the symtab is set on the new symbols. Even
13795 though they don't appear in this symtab directly, other parts
13796 of gdb assume that symbols do, and this is reasonably
13798 for (symbol
*sym
: template_args
)
13799 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13802 /* In C++, we can have functions nested inside functions (e.g., when
13803 a function declares a class that has methods). This means that
13804 when we finish processing a function scope, we may need to go
13805 back to building a containing block's symbol lists. */
13806 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13807 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13809 /* If we've finished processing a top-level function, subsequent
13810 symbols go in the file symbol list. */
13811 if (cu
->get_builder ()->outermost_context_p ())
13812 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13815 /* Process all the DIES contained within a lexical block scope. Start
13816 a new scope, process the dies, and then close the scope. */
13819 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13821 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13822 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13823 CORE_ADDR lowpc
, highpc
;
13824 struct die_info
*child_die
;
13825 CORE_ADDR baseaddr
;
13827 baseaddr
= objfile
->text_section_offset ();
13829 /* Ignore blocks with missing or invalid low and high pc attributes. */
13830 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13831 as multiple lexical blocks? Handling children in a sane way would
13832 be nasty. Might be easier to properly extend generic blocks to
13833 describe ranges. */
13834 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13836 case PC_BOUNDS_NOT_PRESENT
:
13837 /* DW_TAG_lexical_block has no attributes, process its children as if
13838 there was no wrapping by that DW_TAG_lexical_block.
13839 GCC does no longer produces such DWARF since GCC r224161. */
13840 for (child_die
= die
->child
;
13841 child_die
!= NULL
&& child_die
->tag
;
13842 child_die
= sibling_die (child_die
))
13843 process_die (child_die
, cu
);
13845 case PC_BOUNDS_INVALID
:
13848 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13849 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13851 cu
->get_builder ()->push_context (0, lowpc
);
13852 if (die
->child
!= NULL
)
13854 child_die
= die
->child
;
13855 while (child_die
&& child_die
->tag
)
13857 process_die (child_die
, cu
);
13858 child_die
= sibling_die (child_die
);
13861 inherit_abstract_dies (die
, cu
);
13862 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13864 if (*cu
->get_builder ()->get_local_symbols () != NULL
13865 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13867 struct block
*block
13868 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13869 cstk
.start_addr
, highpc
);
13871 /* Note that recording ranges after traversing children, as we
13872 do here, means that recording a parent's ranges entails
13873 walking across all its children's ranges as they appear in
13874 the address map, which is quadratic behavior.
13876 It would be nicer to record the parent's ranges before
13877 traversing its children, simply overriding whatever you find
13878 there. But since we don't even decide whether to create a
13879 block until after we've traversed its children, that's hard
13881 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13883 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13884 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13887 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13890 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13892 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13893 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13894 CORE_ADDR pc
, baseaddr
;
13895 struct attribute
*attr
;
13896 struct call_site
*call_site
, call_site_local
;
13899 struct die_info
*child_die
;
13901 baseaddr
= objfile
->text_section_offset ();
13903 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13906 /* This was a pre-DWARF-5 GNU extension alias
13907 for DW_AT_call_return_pc. */
13908 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13912 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13913 "DIE %s [in module %s]"),
13914 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13917 pc
= attr_value_as_address (attr
) + baseaddr
;
13918 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13920 if (cu
->call_site_htab
== NULL
)
13921 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13922 NULL
, &objfile
->objfile_obstack
,
13923 hashtab_obstack_allocate
, NULL
);
13924 call_site_local
.pc
= pc
;
13925 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13928 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13929 "DIE %s [in module %s]"),
13930 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13931 objfile_name (objfile
));
13935 /* Count parameters at the caller. */
13938 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13939 child_die
= sibling_die (child_die
))
13941 if (child_die
->tag
!= DW_TAG_call_site_parameter
13942 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13944 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13945 "DW_TAG_call_site child DIE %s [in module %s]"),
13946 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13947 objfile_name (objfile
));
13955 = ((struct call_site
*)
13956 obstack_alloc (&objfile
->objfile_obstack
,
13957 sizeof (*call_site
)
13958 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13960 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13961 call_site
->pc
= pc
;
13963 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13964 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13966 struct die_info
*func_die
;
13968 /* Skip also over DW_TAG_inlined_subroutine. */
13969 for (func_die
= die
->parent
;
13970 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13971 && func_die
->tag
!= DW_TAG_subroutine_type
;
13972 func_die
= func_die
->parent
);
13974 /* DW_AT_call_all_calls is a superset
13975 of DW_AT_call_all_tail_calls. */
13977 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13978 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13979 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13980 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13982 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13983 not complete. But keep CALL_SITE for look ups via call_site_htab,
13984 both the initial caller containing the real return address PC and
13985 the final callee containing the current PC of a chain of tail
13986 calls do not need to have the tail call list complete. But any
13987 function candidate for a virtual tail call frame searched via
13988 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13989 determined unambiguously. */
13993 struct type
*func_type
= NULL
;
13996 func_type
= get_die_type (func_die
, cu
);
13997 if (func_type
!= NULL
)
13999 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14001 /* Enlist this call site to the function. */
14002 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14003 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14006 complaint (_("Cannot find function owning DW_TAG_call_site "
14007 "DIE %s [in module %s]"),
14008 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14012 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14014 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14016 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14019 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14020 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14022 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14023 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14024 /* Keep NULL DWARF_BLOCK. */;
14025 else if (attr_form_is_block (attr
))
14027 struct dwarf2_locexpr_baton
*dlbaton
;
14029 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14030 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14031 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14032 dlbaton
->per_cu
= cu
->per_cu
;
14034 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14036 else if (attr_form_is_ref (attr
))
14038 struct dwarf2_cu
*target_cu
= cu
;
14039 struct die_info
*target_die
;
14041 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14042 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14043 if (die_is_declaration (target_die
, target_cu
))
14045 const char *target_physname
;
14047 /* Prefer the mangled name; otherwise compute the demangled one. */
14048 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14049 if (target_physname
== NULL
)
14050 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14051 if (target_physname
== NULL
)
14052 complaint (_("DW_AT_call_target target DIE has invalid "
14053 "physname, for referencing DIE %s [in module %s]"),
14054 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14056 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14062 /* DW_AT_entry_pc should be preferred. */
14063 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14064 <= PC_BOUNDS_INVALID
)
14065 complaint (_("DW_AT_call_target target DIE has invalid "
14066 "low pc, for referencing DIE %s [in module %s]"),
14067 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14070 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14071 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14076 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14077 "block nor reference, for DIE %s [in module %s]"),
14078 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14080 call_site
->per_cu
= cu
->per_cu
;
14082 for (child_die
= die
->child
;
14083 child_die
&& child_die
->tag
;
14084 child_die
= sibling_die (child_die
))
14086 struct call_site_parameter
*parameter
;
14087 struct attribute
*loc
, *origin
;
14089 if (child_die
->tag
!= DW_TAG_call_site_parameter
14090 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14092 /* Already printed the complaint above. */
14096 gdb_assert (call_site
->parameter_count
< nparams
);
14097 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14099 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14100 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14101 register is contained in DW_AT_call_value. */
14103 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14104 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14105 if (origin
== NULL
)
14107 /* This was a pre-DWARF-5 GNU extension alias
14108 for DW_AT_call_parameter. */
14109 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14111 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14113 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14115 sect_offset sect_off
14116 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14117 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14119 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14120 binding can be done only inside one CU. Such referenced DIE
14121 therefore cannot be even moved to DW_TAG_partial_unit. */
14122 complaint (_("DW_AT_call_parameter offset is not in CU for "
14123 "DW_TAG_call_site child DIE %s [in module %s]"),
14124 sect_offset_str (child_die
->sect_off
),
14125 objfile_name (objfile
));
14128 parameter
->u
.param_cu_off
14129 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14131 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14133 complaint (_("No DW_FORM_block* DW_AT_location for "
14134 "DW_TAG_call_site child DIE %s [in module %s]"),
14135 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14140 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14141 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14142 if (parameter
->u
.dwarf_reg
!= -1)
14143 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14144 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14145 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14146 ¶meter
->u
.fb_offset
))
14147 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14150 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14151 "for DW_FORM_block* DW_AT_location is supported for "
14152 "DW_TAG_call_site child DIE %s "
14154 sect_offset_str (child_die
->sect_off
),
14155 objfile_name (objfile
));
14160 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14162 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14163 if (!attr_form_is_block (attr
))
14165 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14166 "DW_TAG_call_site child DIE %s [in module %s]"),
14167 sect_offset_str (child_die
->sect_off
),
14168 objfile_name (objfile
));
14171 parameter
->value
= DW_BLOCK (attr
)->data
;
14172 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14174 /* Parameters are not pre-cleared by memset above. */
14175 parameter
->data_value
= NULL
;
14176 parameter
->data_value_size
= 0;
14177 call_site
->parameter_count
++;
14179 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14181 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14182 if (attr
!= nullptr)
14184 if (!attr_form_is_block (attr
))
14185 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14186 "DW_TAG_call_site child DIE %s [in module %s]"),
14187 sect_offset_str (child_die
->sect_off
),
14188 objfile_name (objfile
));
14191 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14192 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14198 /* Helper function for read_variable. If DIE represents a virtual
14199 table, then return the type of the concrete object that is
14200 associated with the virtual table. Otherwise, return NULL. */
14202 static struct type
*
14203 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14205 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14209 /* Find the type DIE. */
14210 struct die_info
*type_die
= NULL
;
14211 struct dwarf2_cu
*type_cu
= cu
;
14213 if (attr_form_is_ref (attr
))
14214 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14215 if (type_die
== NULL
)
14218 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14220 return die_containing_type (type_die
, type_cu
);
14223 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14226 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14228 struct rust_vtable_symbol
*storage
= NULL
;
14230 if (cu
->language
== language_rust
)
14232 struct type
*containing_type
= rust_containing_type (die
, cu
);
14234 if (containing_type
!= NULL
)
14236 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14238 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
14239 initialize_objfile_symbol (storage
);
14240 storage
->concrete_type
= containing_type
;
14241 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14245 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14246 struct attribute
*abstract_origin
14247 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14248 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14249 if (res
== NULL
&& loc
&& abstract_origin
)
14251 /* We have a variable without a name, but with a location and an abstract
14252 origin. This may be a concrete instance of an abstract variable
14253 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14255 struct dwarf2_cu
*origin_cu
= cu
;
14256 struct die_info
*origin_die
14257 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14258 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14259 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
14263 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14264 reading .debug_rnglists.
14265 Callback's type should be:
14266 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14267 Return true if the attributes are present and valid, otherwise,
14270 template <typename Callback
>
14272 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14273 Callback
&&callback
)
14275 struct dwarf2_per_objfile
*dwarf2_per_objfile
14276 = cu
->per_cu
->dwarf2_per_objfile
;
14277 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14278 bfd
*obfd
= objfile
->obfd
;
14279 /* Base address selection entry. */
14282 const gdb_byte
*buffer
;
14283 CORE_ADDR baseaddr
;
14284 bool overflow
= false;
14286 found_base
= cu
->base_known
;
14287 base
= cu
->base_address
;
14289 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14290 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14292 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14296 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14298 baseaddr
= objfile
->text_section_offset ();
14302 /* Initialize it due to a false compiler warning. */
14303 CORE_ADDR range_beginning
= 0, range_end
= 0;
14304 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14305 + dwarf2_per_objfile
->rnglists
.size
);
14306 unsigned int bytes_read
;
14308 if (buffer
== buf_end
)
14313 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14316 case DW_RLE_end_of_list
:
14318 case DW_RLE_base_address
:
14319 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14324 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14326 buffer
+= bytes_read
;
14328 case DW_RLE_start_length
:
14329 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14334 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14335 buffer
+= bytes_read
;
14336 range_end
= (range_beginning
14337 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14338 buffer
+= bytes_read
;
14339 if (buffer
> buf_end
)
14345 case DW_RLE_offset_pair
:
14346 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14347 buffer
+= bytes_read
;
14348 if (buffer
> buf_end
)
14353 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14354 buffer
+= bytes_read
;
14355 if (buffer
> buf_end
)
14361 case DW_RLE_start_end
:
14362 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14367 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14368 buffer
+= bytes_read
;
14369 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14370 buffer
+= bytes_read
;
14373 complaint (_("Invalid .debug_rnglists data (no base address)"));
14376 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14378 if (rlet
== DW_RLE_base_address
)
14383 /* We have no valid base address for the ranges
14385 complaint (_("Invalid .debug_rnglists data (no base address)"));
14389 if (range_beginning
> range_end
)
14391 /* Inverted range entries are invalid. */
14392 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14396 /* Empty range entries have no effect. */
14397 if (range_beginning
== range_end
)
14400 range_beginning
+= base
;
14403 /* A not-uncommon case of bad debug info.
14404 Don't pollute the addrmap with bad data. */
14405 if (range_beginning
+ baseaddr
== 0
14406 && !dwarf2_per_objfile
->has_section_at_zero
)
14408 complaint (_(".debug_rnglists entry has start address of zero"
14409 " [in module %s]"), objfile_name (objfile
));
14413 callback (range_beginning
, range_end
);
14418 complaint (_("Offset %d is not terminated "
14419 "for DW_AT_ranges attribute"),
14427 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14428 Callback's type should be:
14429 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14430 Return 1 if the attributes are present and valid, otherwise, return 0. */
14432 template <typename Callback
>
14434 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14435 Callback
&&callback
)
14437 struct dwarf2_per_objfile
*dwarf2_per_objfile
14438 = cu
->per_cu
->dwarf2_per_objfile
;
14439 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14440 struct comp_unit_head
*cu_header
= &cu
->header
;
14441 bfd
*obfd
= objfile
->obfd
;
14442 unsigned int addr_size
= cu_header
->addr_size
;
14443 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14444 /* Base address selection entry. */
14447 unsigned int dummy
;
14448 const gdb_byte
*buffer
;
14449 CORE_ADDR baseaddr
;
14451 if (cu_header
->version
>= 5)
14452 return dwarf2_rnglists_process (offset
, cu
, callback
);
14454 found_base
= cu
->base_known
;
14455 base
= cu
->base_address
;
14457 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14458 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14460 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14464 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14466 baseaddr
= objfile
->text_section_offset ();
14470 CORE_ADDR range_beginning
, range_end
;
14472 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14473 buffer
+= addr_size
;
14474 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14475 buffer
+= addr_size
;
14476 offset
+= 2 * addr_size
;
14478 /* An end of list marker is a pair of zero addresses. */
14479 if (range_beginning
== 0 && range_end
== 0)
14480 /* Found the end of list entry. */
14483 /* Each base address selection entry is a pair of 2 values.
14484 The first is the largest possible address, the second is
14485 the base address. Check for a base address here. */
14486 if ((range_beginning
& mask
) == mask
)
14488 /* If we found the largest possible address, then we already
14489 have the base address in range_end. */
14497 /* We have no valid base address for the ranges
14499 complaint (_("Invalid .debug_ranges data (no base address)"));
14503 if (range_beginning
> range_end
)
14505 /* Inverted range entries are invalid. */
14506 complaint (_("Invalid .debug_ranges data (inverted range)"));
14510 /* Empty range entries have no effect. */
14511 if (range_beginning
== range_end
)
14514 range_beginning
+= base
;
14517 /* A not-uncommon case of bad debug info.
14518 Don't pollute the addrmap with bad data. */
14519 if (range_beginning
+ baseaddr
== 0
14520 && !dwarf2_per_objfile
->has_section_at_zero
)
14522 complaint (_(".debug_ranges entry has start address of zero"
14523 " [in module %s]"), objfile_name (objfile
));
14527 callback (range_beginning
, range_end
);
14533 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14534 Return 1 if the attributes are present and valid, otherwise, return 0.
14535 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14538 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14539 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14540 dwarf2_psymtab
*ranges_pst
)
14542 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14543 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14544 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14547 CORE_ADDR high
= 0;
14550 retval
= dwarf2_ranges_process (offset
, cu
,
14551 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14553 if (ranges_pst
!= NULL
)
14558 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14559 range_beginning
+ baseaddr
)
14561 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14562 range_end
+ baseaddr
)
14564 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14565 lowpc
, highpc
- 1, ranges_pst
);
14568 /* FIXME: This is recording everything as a low-high
14569 segment of consecutive addresses. We should have a
14570 data structure for discontiguous block ranges
14574 low
= range_beginning
;
14580 if (range_beginning
< low
)
14581 low
= range_beginning
;
14582 if (range_end
> high
)
14590 /* If the first entry is an end-of-list marker, the range
14591 describes an empty scope, i.e. no instructions. */
14597 *high_return
= high
;
14601 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14602 definition for the return value. *LOWPC and *HIGHPC are set iff
14603 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14605 static enum pc_bounds_kind
14606 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14607 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14608 dwarf2_psymtab
*pst
)
14610 struct dwarf2_per_objfile
*dwarf2_per_objfile
14611 = cu
->per_cu
->dwarf2_per_objfile
;
14612 struct attribute
*attr
;
14613 struct attribute
*attr_high
;
14615 CORE_ADDR high
= 0;
14616 enum pc_bounds_kind ret
;
14618 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14621 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14622 if (attr
!= nullptr)
14624 low
= attr_value_as_address (attr
);
14625 high
= attr_value_as_address (attr_high
);
14626 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14630 /* Found high w/o low attribute. */
14631 return PC_BOUNDS_INVALID
;
14633 /* Found consecutive range of addresses. */
14634 ret
= PC_BOUNDS_HIGH_LOW
;
14638 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14641 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14642 We take advantage of the fact that DW_AT_ranges does not appear
14643 in DW_TAG_compile_unit of DWO files. */
14644 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14645 unsigned int ranges_offset
= (DW_UNSND (attr
)
14646 + (need_ranges_base
14650 /* Value of the DW_AT_ranges attribute is the offset in the
14651 .debug_ranges section. */
14652 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14653 return PC_BOUNDS_INVALID
;
14654 /* Found discontinuous range of addresses. */
14655 ret
= PC_BOUNDS_RANGES
;
14658 return PC_BOUNDS_NOT_PRESENT
;
14661 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14663 return PC_BOUNDS_INVALID
;
14665 /* When using the GNU linker, .gnu.linkonce. sections are used to
14666 eliminate duplicate copies of functions and vtables and such.
14667 The linker will arbitrarily choose one and discard the others.
14668 The AT_*_pc values for such functions refer to local labels in
14669 these sections. If the section from that file was discarded, the
14670 labels are not in the output, so the relocs get a value of 0.
14671 If this is a discarded function, mark the pc bounds as invalid,
14672 so that GDB will ignore it. */
14673 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14674 return PC_BOUNDS_INVALID
;
14682 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14683 its low and high PC addresses. Do nothing if these addresses could not
14684 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14685 and HIGHPC to the high address if greater than HIGHPC. */
14688 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14689 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14690 struct dwarf2_cu
*cu
)
14692 CORE_ADDR low
, high
;
14693 struct die_info
*child
= die
->child
;
14695 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14697 *lowpc
= std::min (*lowpc
, low
);
14698 *highpc
= std::max (*highpc
, high
);
14701 /* If the language does not allow nested subprograms (either inside
14702 subprograms or lexical blocks), we're done. */
14703 if (cu
->language
!= language_ada
)
14706 /* Check all the children of the given DIE. If it contains nested
14707 subprograms, then check their pc bounds. Likewise, we need to
14708 check lexical blocks as well, as they may also contain subprogram
14710 while (child
&& child
->tag
)
14712 if (child
->tag
== DW_TAG_subprogram
14713 || child
->tag
== DW_TAG_lexical_block
)
14714 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14715 child
= sibling_die (child
);
14719 /* Get the low and high pc's represented by the scope DIE, and store
14720 them in *LOWPC and *HIGHPC. If the correct values can't be
14721 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14724 get_scope_pc_bounds (struct die_info
*die
,
14725 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14726 struct dwarf2_cu
*cu
)
14728 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14729 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14730 CORE_ADDR current_low
, current_high
;
14732 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14733 >= PC_BOUNDS_RANGES
)
14735 best_low
= current_low
;
14736 best_high
= current_high
;
14740 struct die_info
*child
= die
->child
;
14742 while (child
&& child
->tag
)
14744 switch (child
->tag
) {
14745 case DW_TAG_subprogram
:
14746 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14748 case DW_TAG_namespace
:
14749 case DW_TAG_module
:
14750 /* FIXME: carlton/2004-01-16: Should we do this for
14751 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14752 that current GCC's always emit the DIEs corresponding
14753 to definitions of methods of classes as children of a
14754 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14755 the DIEs giving the declarations, which could be
14756 anywhere). But I don't see any reason why the
14757 standards says that they have to be there. */
14758 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14760 if (current_low
!= ((CORE_ADDR
) -1))
14762 best_low
= std::min (best_low
, current_low
);
14763 best_high
= std::max (best_high
, current_high
);
14771 child
= sibling_die (child
);
14776 *highpc
= best_high
;
14779 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14783 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14784 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14786 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14787 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14788 struct attribute
*attr
;
14789 struct attribute
*attr_high
;
14791 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14794 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14795 if (attr
!= nullptr)
14797 CORE_ADDR low
= attr_value_as_address (attr
);
14798 CORE_ADDR high
= attr_value_as_address (attr_high
);
14800 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14803 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14804 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14805 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14809 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14810 if (attr
!= nullptr)
14812 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14813 We take advantage of the fact that DW_AT_ranges does not appear
14814 in DW_TAG_compile_unit of DWO files. */
14815 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14817 /* The value of the DW_AT_ranges attribute is the offset of the
14818 address range list in the .debug_ranges section. */
14819 unsigned long offset
= (DW_UNSND (attr
)
14820 + (need_ranges_base
? cu
->ranges_base
: 0));
14822 std::vector
<blockrange
> blockvec
;
14823 dwarf2_ranges_process (offset
, cu
,
14824 [&] (CORE_ADDR start
, CORE_ADDR end
)
14828 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14829 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14830 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14831 blockvec
.emplace_back (start
, end
);
14834 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14838 /* Check whether the producer field indicates either of GCC < 4.6, or the
14839 Intel C/C++ compiler, and cache the result in CU. */
14842 check_producer (struct dwarf2_cu
*cu
)
14846 if (cu
->producer
== NULL
)
14848 /* For unknown compilers expect their behavior is DWARF version
14851 GCC started to support .debug_types sections by -gdwarf-4 since
14852 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14853 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14854 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14855 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14857 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14859 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14860 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14862 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14864 cu
->producer_is_icc
= true;
14865 cu
->producer_is_icc_lt_14
= major
< 14;
14867 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14868 cu
->producer_is_codewarrior
= true;
14871 /* For other non-GCC compilers, expect their behavior is DWARF version
14875 cu
->checked_producer
= true;
14878 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14879 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14880 during 4.6.0 experimental. */
14883 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14885 if (!cu
->checked_producer
)
14886 check_producer (cu
);
14888 return cu
->producer_is_gxx_lt_4_6
;
14892 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14893 with incorrect is_stmt attributes. */
14896 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14898 if (!cu
->checked_producer
)
14899 check_producer (cu
);
14901 return cu
->producer_is_codewarrior
;
14904 /* Return the default accessibility type if it is not overridden by
14905 DW_AT_accessibility. */
14907 static enum dwarf_access_attribute
14908 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14910 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14912 /* The default DWARF 2 accessibility for members is public, the default
14913 accessibility for inheritance is private. */
14915 if (die
->tag
!= DW_TAG_inheritance
)
14916 return DW_ACCESS_public
;
14918 return DW_ACCESS_private
;
14922 /* DWARF 3+ defines the default accessibility a different way. The same
14923 rules apply now for DW_TAG_inheritance as for the members and it only
14924 depends on the container kind. */
14926 if (die
->parent
->tag
== DW_TAG_class_type
)
14927 return DW_ACCESS_private
;
14929 return DW_ACCESS_public
;
14933 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14934 offset. If the attribute was not found return 0, otherwise return
14935 1. If it was found but could not properly be handled, set *OFFSET
14939 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14942 struct attribute
*attr
;
14944 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14949 /* Note that we do not check for a section offset first here.
14950 This is because DW_AT_data_member_location is new in DWARF 4,
14951 so if we see it, we can assume that a constant form is really
14952 a constant and not a section offset. */
14953 if (attr_form_is_constant (attr
))
14954 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14955 else if (attr_form_is_section_offset (attr
))
14956 dwarf2_complex_location_expr_complaint ();
14957 else if (attr_form_is_block (attr
))
14958 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14960 dwarf2_complex_location_expr_complaint ();
14968 /* Add an aggregate field to the field list. */
14971 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14972 struct dwarf2_cu
*cu
)
14974 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14975 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14976 struct nextfield
*new_field
;
14977 struct attribute
*attr
;
14979 const char *fieldname
= "";
14981 if (die
->tag
== DW_TAG_inheritance
)
14983 fip
->baseclasses
.emplace_back ();
14984 new_field
= &fip
->baseclasses
.back ();
14988 fip
->fields
.emplace_back ();
14989 new_field
= &fip
->fields
.back ();
14994 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14995 if (attr
!= nullptr)
14996 new_field
->accessibility
= DW_UNSND (attr
);
14998 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14999 if (new_field
->accessibility
!= DW_ACCESS_public
)
15000 fip
->non_public_fields
= 1;
15002 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15003 if (attr
!= nullptr)
15004 new_field
->virtuality
= DW_UNSND (attr
);
15006 new_field
->virtuality
= DW_VIRTUALITY_none
;
15008 fp
= &new_field
->field
;
15010 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15014 /* Data member other than a C++ static data member. */
15016 /* Get type of field. */
15017 fp
->type
= die_type (die
, cu
);
15019 SET_FIELD_BITPOS (*fp
, 0);
15021 /* Get bit size of field (zero if none). */
15022 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15023 if (attr
!= nullptr)
15025 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15029 FIELD_BITSIZE (*fp
) = 0;
15032 /* Get bit offset of field. */
15033 if (handle_data_member_location (die
, cu
, &offset
))
15034 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15035 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15036 if (attr
!= nullptr)
15038 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15040 /* For big endian bits, the DW_AT_bit_offset gives the
15041 additional bit offset from the MSB of the containing
15042 anonymous object to the MSB of the field. We don't
15043 have to do anything special since we don't need to
15044 know the size of the anonymous object. */
15045 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15049 /* For little endian bits, compute the bit offset to the
15050 MSB of the anonymous object, subtract off the number of
15051 bits from the MSB of the field to the MSB of the
15052 object, and then subtract off the number of bits of
15053 the field itself. The result is the bit offset of
15054 the LSB of the field. */
15055 int anonymous_size
;
15056 int bit_offset
= DW_UNSND (attr
);
15058 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15059 if (attr
!= nullptr)
15061 /* The size of the anonymous object containing
15062 the bit field is explicit, so use the
15063 indicated size (in bytes). */
15064 anonymous_size
= DW_UNSND (attr
);
15068 /* The size of the anonymous object containing
15069 the bit field must be inferred from the type
15070 attribute of the data member containing the
15072 anonymous_size
= TYPE_LENGTH (fp
->type
);
15074 SET_FIELD_BITPOS (*fp
,
15075 (FIELD_BITPOS (*fp
)
15076 + anonymous_size
* bits_per_byte
15077 - bit_offset
- FIELD_BITSIZE (*fp
)));
15080 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15082 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15083 + dwarf2_get_attr_constant_value (attr
, 0)));
15085 /* Get name of field. */
15086 fieldname
= dwarf2_name (die
, cu
);
15087 if (fieldname
== NULL
)
15090 /* The name is already allocated along with this objfile, so we don't
15091 need to duplicate it for the type. */
15092 fp
->name
= fieldname
;
15094 /* Change accessibility for artificial fields (e.g. virtual table
15095 pointer or virtual base class pointer) to private. */
15096 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15098 FIELD_ARTIFICIAL (*fp
) = 1;
15099 new_field
->accessibility
= DW_ACCESS_private
;
15100 fip
->non_public_fields
= 1;
15103 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15105 /* C++ static member. */
15107 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15108 is a declaration, but all versions of G++ as of this writing
15109 (so through at least 3.2.1) incorrectly generate
15110 DW_TAG_variable tags. */
15112 const char *physname
;
15114 /* Get name of field. */
15115 fieldname
= dwarf2_name (die
, cu
);
15116 if (fieldname
== NULL
)
15119 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15121 /* Only create a symbol if this is an external value.
15122 new_symbol checks this and puts the value in the global symbol
15123 table, which we want. If it is not external, new_symbol
15124 will try to put the value in cu->list_in_scope which is wrong. */
15125 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15127 /* A static const member, not much different than an enum as far as
15128 we're concerned, except that we can support more types. */
15129 new_symbol (die
, NULL
, cu
);
15132 /* Get physical name. */
15133 physname
= dwarf2_physname (fieldname
, die
, cu
);
15135 /* The name is already allocated along with this objfile, so we don't
15136 need to duplicate it for the type. */
15137 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15138 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15139 FIELD_NAME (*fp
) = fieldname
;
15141 else if (die
->tag
== DW_TAG_inheritance
)
15145 /* C++ base class field. */
15146 if (handle_data_member_location (die
, cu
, &offset
))
15147 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15148 FIELD_BITSIZE (*fp
) = 0;
15149 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15150 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
15152 else if (die
->tag
== DW_TAG_variant_part
)
15154 /* process_structure_scope will treat this DIE as a union. */
15155 process_structure_scope (die
, cu
);
15157 /* The variant part is relative to the start of the enclosing
15159 SET_FIELD_BITPOS (*fp
, 0);
15160 fp
->type
= get_die_type (die
, cu
);
15161 fp
->artificial
= 1;
15162 fp
->name
= "<<variant>>";
15164 /* Normally a DW_TAG_variant_part won't have a size, but our
15165 representation requires one, so set it to the maximum of the
15166 child sizes, being sure to account for the offset at which
15167 each child is seen. */
15168 if (TYPE_LENGTH (fp
->type
) == 0)
15171 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
15173 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
15174 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
15178 TYPE_LENGTH (fp
->type
) = max
;
15182 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15185 /* Can the type given by DIE define another type? */
15188 type_can_define_types (const struct die_info
*die
)
15192 case DW_TAG_typedef
:
15193 case DW_TAG_class_type
:
15194 case DW_TAG_structure_type
:
15195 case DW_TAG_union_type
:
15196 case DW_TAG_enumeration_type
:
15204 /* Add a type definition defined in the scope of the FIP's class. */
15207 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15208 struct dwarf2_cu
*cu
)
15210 struct decl_field fp
;
15211 memset (&fp
, 0, sizeof (fp
));
15213 gdb_assert (type_can_define_types (die
));
15215 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15216 fp
.name
= dwarf2_name (die
, cu
);
15217 fp
.type
= read_type_die (die
, cu
);
15219 /* Save accessibility. */
15220 enum dwarf_access_attribute accessibility
;
15221 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15223 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15225 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15226 switch (accessibility
)
15228 case DW_ACCESS_public
:
15229 /* The assumed value if neither private nor protected. */
15231 case DW_ACCESS_private
:
15234 case DW_ACCESS_protected
:
15235 fp
.is_protected
= 1;
15238 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15241 if (die
->tag
== DW_TAG_typedef
)
15242 fip
->typedef_field_list
.push_back (fp
);
15244 fip
->nested_types_list
.push_back (fp
);
15247 /* Create the vector of fields, and attach it to the type. */
15250 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15251 struct dwarf2_cu
*cu
)
15253 int nfields
= fip
->nfields
;
15255 /* Record the field count, allocate space for the array of fields,
15256 and create blank accessibility bitfields if necessary. */
15257 TYPE_NFIELDS (type
) = nfields
;
15258 TYPE_FIELDS (type
) = (struct field
*)
15259 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15261 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15263 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15265 TYPE_FIELD_PRIVATE_BITS (type
) =
15266 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15267 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15269 TYPE_FIELD_PROTECTED_BITS (type
) =
15270 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15271 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15273 TYPE_FIELD_IGNORE_BITS (type
) =
15274 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15275 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15278 /* If the type has baseclasses, allocate and clear a bit vector for
15279 TYPE_FIELD_VIRTUAL_BITS. */
15280 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15282 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15283 unsigned char *pointer
;
15285 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15286 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15287 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15288 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15289 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15292 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15294 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15296 for (int index
= 0; index
< nfields
; ++index
)
15298 struct nextfield
&field
= fip
->fields
[index
];
15300 if (field
.variant
.is_discriminant
)
15301 di
->discriminant_index
= index
;
15302 else if (field
.variant
.default_branch
)
15303 di
->default_index
= index
;
15305 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15309 /* Copy the saved-up fields into the field vector. */
15310 for (int i
= 0; i
< nfields
; ++i
)
15312 struct nextfield
&field
15313 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15314 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15316 TYPE_FIELD (type
, i
) = field
.field
;
15317 switch (field
.accessibility
)
15319 case DW_ACCESS_private
:
15320 if (cu
->language
!= language_ada
)
15321 SET_TYPE_FIELD_PRIVATE (type
, i
);
15324 case DW_ACCESS_protected
:
15325 if (cu
->language
!= language_ada
)
15326 SET_TYPE_FIELD_PROTECTED (type
, i
);
15329 case DW_ACCESS_public
:
15333 /* Unknown accessibility. Complain and treat it as public. */
15335 complaint (_("unsupported accessibility %d"),
15336 field
.accessibility
);
15340 if (i
< fip
->baseclasses
.size ())
15342 switch (field
.virtuality
)
15344 case DW_VIRTUALITY_virtual
:
15345 case DW_VIRTUALITY_pure_virtual
:
15346 if (cu
->language
== language_ada
)
15347 error (_("unexpected virtuality in component of Ada type"));
15348 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15355 /* Return true if this member function is a constructor, false
15359 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15361 const char *fieldname
;
15362 const char *type_name
;
15365 if (die
->parent
== NULL
)
15368 if (die
->parent
->tag
!= DW_TAG_structure_type
15369 && die
->parent
->tag
!= DW_TAG_union_type
15370 && die
->parent
->tag
!= DW_TAG_class_type
)
15373 fieldname
= dwarf2_name (die
, cu
);
15374 type_name
= dwarf2_name (die
->parent
, cu
);
15375 if (fieldname
== NULL
|| type_name
== NULL
)
15378 len
= strlen (fieldname
);
15379 return (strncmp (fieldname
, type_name
, len
) == 0
15380 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15383 /* Check if the given VALUE is a recognized enum
15384 dwarf_defaulted_attribute constant according to DWARF5 spec,
15388 is_valid_DW_AT_defaulted (ULONGEST value
)
15392 case DW_DEFAULTED_no
:
15393 case DW_DEFAULTED_in_class
:
15394 case DW_DEFAULTED_out_of_class
:
15398 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15402 /* Add a member function to the proper fieldlist. */
15405 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15406 struct type
*type
, struct dwarf2_cu
*cu
)
15408 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15409 struct attribute
*attr
;
15411 struct fnfieldlist
*flp
= nullptr;
15412 struct fn_field
*fnp
;
15413 const char *fieldname
;
15414 struct type
*this_type
;
15415 enum dwarf_access_attribute accessibility
;
15417 if (cu
->language
== language_ada
)
15418 error (_("unexpected member function in Ada type"));
15420 /* Get name of member function. */
15421 fieldname
= dwarf2_name (die
, cu
);
15422 if (fieldname
== NULL
)
15425 /* Look up member function name in fieldlist. */
15426 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15428 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15430 flp
= &fip
->fnfieldlists
[i
];
15435 /* Create a new fnfieldlist if necessary. */
15436 if (flp
== nullptr)
15438 fip
->fnfieldlists
.emplace_back ();
15439 flp
= &fip
->fnfieldlists
.back ();
15440 flp
->name
= fieldname
;
15441 i
= fip
->fnfieldlists
.size () - 1;
15444 /* Create a new member function field and add it to the vector of
15446 flp
->fnfields
.emplace_back ();
15447 fnp
= &flp
->fnfields
.back ();
15449 /* Delay processing of the physname until later. */
15450 if (cu
->language
== language_cplus
)
15451 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15455 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15456 fnp
->physname
= physname
? physname
: "";
15459 fnp
->type
= alloc_type (objfile
);
15460 this_type
= read_type_die (die
, cu
);
15461 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15463 int nparams
= TYPE_NFIELDS (this_type
);
15465 /* TYPE is the domain of this method, and THIS_TYPE is the type
15466 of the method itself (TYPE_CODE_METHOD). */
15467 smash_to_method_type (fnp
->type
, type
,
15468 TYPE_TARGET_TYPE (this_type
),
15469 TYPE_FIELDS (this_type
),
15470 TYPE_NFIELDS (this_type
),
15471 TYPE_VARARGS (this_type
));
15473 /* Handle static member functions.
15474 Dwarf2 has no clean way to discern C++ static and non-static
15475 member functions. G++ helps GDB by marking the first
15476 parameter for non-static member functions (which is the this
15477 pointer) as artificial. We obtain this information from
15478 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15479 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15480 fnp
->voffset
= VOFFSET_STATIC
;
15483 complaint (_("member function type missing for '%s'"),
15484 dwarf2_full_name (fieldname
, die
, cu
));
15486 /* Get fcontext from DW_AT_containing_type if present. */
15487 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15488 fnp
->fcontext
= die_containing_type (die
, cu
);
15490 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15491 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15493 /* Get accessibility. */
15494 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15495 if (attr
!= nullptr)
15496 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15498 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15499 switch (accessibility
)
15501 case DW_ACCESS_private
:
15502 fnp
->is_private
= 1;
15504 case DW_ACCESS_protected
:
15505 fnp
->is_protected
= 1;
15509 /* Check for artificial methods. */
15510 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15511 if (attr
&& DW_UNSND (attr
) != 0)
15512 fnp
->is_artificial
= 1;
15514 /* Check for defaulted methods. */
15515 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15516 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15517 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15519 /* Check for deleted methods. */
15520 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15521 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15522 fnp
->is_deleted
= 1;
15524 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15526 /* Get index in virtual function table if it is a virtual member
15527 function. For older versions of GCC, this is an offset in the
15528 appropriate virtual table, as specified by DW_AT_containing_type.
15529 For everyone else, it is an expression to be evaluated relative
15530 to the object address. */
15532 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15533 if (attr
!= nullptr)
15535 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15537 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15539 /* Old-style GCC. */
15540 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15542 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15543 || (DW_BLOCK (attr
)->size
> 1
15544 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15545 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15547 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15548 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15549 dwarf2_complex_location_expr_complaint ();
15551 fnp
->voffset
/= cu
->header
.addr_size
;
15555 dwarf2_complex_location_expr_complaint ();
15557 if (!fnp
->fcontext
)
15559 /* If there is no `this' field and no DW_AT_containing_type,
15560 we cannot actually find a base class context for the
15562 if (TYPE_NFIELDS (this_type
) == 0
15563 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15565 complaint (_("cannot determine context for virtual member "
15566 "function \"%s\" (offset %s)"),
15567 fieldname
, sect_offset_str (die
->sect_off
));
15572 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15576 else if (attr_form_is_section_offset (attr
))
15578 dwarf2_complex_location_expr_complaint ();
15582 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15588 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15589 if (attr
&& DW_UNSND (attr
))
15591 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15592 complaint (_("Member function \"%s\" (offset %s) is virtual "
15593 "but the vtable offset is not specified"),
15594 fieldname
, sect_offset_str (die
->sect_off
));
15595 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15596 TYPE_CPLUS_DYNAMIC (type
) = 1;
15601 /* Create the vector of member function fields, and attach it to the type. */
15604 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15605 struct dwarf2_cu
*cu
)
15607 if (cu
->language
== language_ada
)
15608 error (_("unexpected member functions in Ada type"));
15610 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15611 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15613 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15615 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15617 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15618 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15620 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15621 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15622 fn_flp
->fn_fields
= (struct fn_field
*)
15623 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15625 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15626 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15629 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15632 /* Returns non-zero if NAME is the name of a vtable member in CU's
15633 language, zero otherwise. */
15635 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15637 static const char vptr
[] = "_vptr";
15639 /* Look for the C++ form of the vtable. */
15640 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15646 /* GCC outputs unnamed structures that are really pointers to member
15647 functions, with the ABI-specified layout. If TYPE describes
15648 such a structure, smash it into a member function type.
15650 GCC shouldn't do this; it should just output pointer to member DIEs.
15651 This is GCC PR debug/28767. */
15654 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15656 struct type
*pfn_type
, *self_type
, *new_type
;
15658 /* Check for a structure with no name and two children. */
15659 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15662 /* Check for __pfn and __delta members. */
15663 if (TYPE_FIELD_NAME (type
, 0) == NULL
15664 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15665 || TYPE_FIELD_NAME (type
, 1) == NULL
15666 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15669 /* Find the type of the method. */
15670 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15671 if (pfn_type
== NULL
15672 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15673 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15676 /* Look for the "this" argument. */
15677 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15678 if (TYPE_NFIELDS (pfn_type
) == 0
15679 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15680 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15683 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15684 new_type
= alloc_type (objfile
);
15685 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15686 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15687 TYPE_VARARGS (pfn_type
));
15688 smash_to_methodptr_type (type
, new_type
);
15691 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15692 appropriate error checking and issuing complaints if there is a
15696 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15698 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15700 if (attr
== nullptr)
15703 if (!attr_form_is_constant (attr
))
15705 complaint (_("DW_AT_alignment must have constant form"
15706 " - DIE at %s [in module %s]"),
15707 sect_offset_str (die
->sect_off
),
15708 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15713 if (attr
->form
== DW_FORM_sdata
)
15715 LONGEST val
= DW_SND (attr
);
15718 complaint (_("DW_AT_alignment value must not be negative"
15719 " - DIE at %s [in module %s]"),
15720 sect_offset_str (die
->sect_off
),
15721 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15727 align
= DW_UNSND (attr
);
15731 complaint (_("DW_AT_alignment value must not be zero"
15732 " - DIE at %s [in module %s]"),
15733 sect_offset_str (die
->sect_off
),
15734 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15737 if ((align
& (align
- 1)) != 0)
15739 complaint (_("DW_AT_alignment value must be a power of 2"
15740 " - DIE at %s [in module %s]"),
15741 sect_offset_str (die
->sect_off
),
15742 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15749 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15750 the alignment for TYPE. */
15753 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15756 if (!set_type_align (type
, get_alignment (cu
, die
)))
15757 complaint (_("DW_AT_alignment value too large"
15758 " - DIE at %s [in module %s]"),
15759 sect_offset_str (die
->sect_off
),
15760 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15763 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15764 constant for a type, according to DWARF5 spec, Table 5.5. */
15767 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15772 case DW_CC_pass_by_reference
:
15773 case DW_CC_pass_by_value
:
15777 complaint (_("unrecognized DW_AT_calling_convention value "
15778 "(%s) for a type"), pulongest (value
));
15783 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15784 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15785 also according to GNU-specific values (see include/dwarf2.h). */
15788 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15793 case DW_CC_program
:
15797 case DW_CC_GNU_renesas_sh
:
15798 case DW_CC_GNU_borland_fastcall_i386
:
15799 case DW_CC_GDB_IBM_OpenCL
:
15803 complaint (_("unrecognized DW_AT_calling_convention value "
15804 "(%s) for a subroutine"), pulongest (value
));
15809 /* Called when we find the DIE that starts a structure or union scope
15810 (definition) to create a type for the structure or union. Fill in
15811 the type's name and general properties; the members will not be
15812 processed until process_structure_scope. A symbol table entry for
15813 the type will also not be done until process_structure_scope (assuming
15814 the type has a name).
15816 NOTE: we need to call these functions regardless of whether or not the
15817 DIE has a DW_AT_name attribute, since it might be an anonymous
15818 structure or union. This gets the type entered into our set of
15819 user defined types. */
15821 static struct type
*
15822 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15824 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15826 struct attribute
*attr
;
15829 /* If the definition of this type lives in .debug_types, read that type.
15830 Don't follow DW_AT_specification though, that will take us back up
15831 the chain and we want to go down. */
15832 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15833 if (attr
!= nullptr)
15835 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15837 /* The type's CU may not be the same as CU.
15838 Ensure TYPE is recorded with CU in die_type_hash. */
15839 return set_die_type (die
, type
, cu
);
15842 type
= alloc_type (objfile
);
15843 INIT_CPLUS_SPECIFIC (type
);
15845 name
= dwarf2_name (die
, cu
);
15848 if (cu
->language
== language_cplus
15849 || cu
->language
== language_d
15850 || cu
->language
== language_rust
)
15852 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15854 /* dwarf2_full_name might have already finished building the DIE's
15855 type. If so, there is no need to continue. */
15856 if (get_die_type (die
, cu
) != NULL
)
15857 return get_die_type (die
, cu
);
15859 TYPE_NAME (type
) = full_name
;
15863 /* The name is already allocated along with this objfile, so
15864 we don't need to duplicate it for the type. */
15865 TYPE_NAME (type
) = name
;
15869 if (die
->tag
== DW_TAG_structure_type
)
15871 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15873 else if (die
->tag
== DW_TAG_union_type
)
15875 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15877 else if (die
->tag
== DW_TAG_variant_part
)
15879 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15880 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15884 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15887 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15888 TYPE_DECLARED_CLASS (type
) = 1;
15890 /* Store the calling convention in the type if it's available in
15891 the die. Otherwise the calling convention remains set to
15892 the default value DW_CC_normal. */
15893 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15894 if (attr
!= nullptr
15895 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15897 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15898 TYPE_CPLUS_CALLING_CONVENTION (type
)
15899 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15902 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15903 if (attr
!= nullptr)
15905 if (attr_form_is_constant (attr
))
15906 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15909 /* For the moment, dynamic type sizes are not supported
15910 by GDB's struct type. The actual size is determined
15911 on-demand when resolving the type of a given object,
15912 so set the type's length to zero for now. Otherwise,
15913 we record an expression as the length, and that expression
15914 could lead to a very large value, which could eventually
15915 lead to us trying to allocate that much memory when creating
15916 a value of that type. */
15917 TYPE_LENGTH (type
) = 0;
15922 TYPE_LENGTH (type
) = 0;
15925 maybe_set_alignment (cu
, die
, type
);
15927 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15929 /* ICC<14 does not output the required DW_AT_declaration on
15930 incomplete types, but gives them a size of zero. */
15931 TYPE_STUB (type
) = 1;
15934 TYPE_STUB_SUPPORTED (type
) = 1;
15936 if (die_is_declaration (die
, cu
))
15937 TYPE_STUB (type
) = 1;
15938 else if (attr
== NULL
&& die
->child
== NULL
15939 && producer_is_realview (cu
->producer
))
15940 /* RealView does not output the required DW_AT_declaration
15941 on incomplete types. */
15942 TYPE_STUB (type
) = 1;
15944 /* We need to add the type field to the die immediately so we don't
15945 infinitely recurse when dealing with pointers to the structure
15946 type within the structure itself. */
15947 set_die_type (die
, type
, cu
);
15949 /* set_die_type should be already done. */
15950 set_descriptive_type (type
, die
, cu
);
15955 /* A helper for process_structure_scope that handles a single member
15959 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15960 struct field_info
*fi
,
15961 std::vector
<struct symbol
*> *template_args
,
15962 struct dwarf2_cu
*cu
)
15964 if (child_die
->tag
== DW_TAG_member
15965 || child_die
->tag
== DW_TAG_variable
15966 || child_die
->tag
== DW_TAG_variant_part
)
15968 /* NOTE: carlton/2002-11-05: A C++ static data member
15969 should be a DW_TAG_member that is a declaration, but
15970 all versions of G++ as of this writing (so through at
15971 least 3.2.1) incorrectly generate DW_TAG_variable
15972 tags for them instead. */
15973 dwarf2_add_field (fi
, child_die
, cu
);
15975 else if (child_die
->tag
== DW_TAG_subprogram
)
15977 /* Rust doesn't have member functions in the C++ sense.
15978 However, it does emit ordinary functions as children
15979 of a struct DIE. */
15980 if (cu
->language
== language_rust
)
15981 read_func_scope (child_die
, cu
);
15984 /* C++ member function. */
15985 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15988 else if (child_die
->tag
== DW_TAG_inheritance
)
15990 /* C++ base class field. */
15991 dwarf2_add_field (fi
, child_die
, cu
);
15993 else if (type_can_define_types (child_die
))
15994 dwarf2_add_type_defn (fi
, child_die
, cu
);
15995 else if (child_die
->tag
== DW_TAG_template_type_param
15996 || child_die
->tag
== DW_TAG_template_value_param
)
15998 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16001 template_args
->push_back (arg
);
16003 else if (child_die
->tag
== DW_TAG_variant
)
16005 /* In a variant we want to get the discriminant and also add a
16006 field for our sole member child. */
16007 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
16009 for (die_info
*variant_child
= child_die
->child
;
16010 variant_child
!= NULL
;
16011 variant_child
= sibling_die (variant_child
))
16013 if (variant_child
->tag
== DW_TAG_member
)
16015 handle_struct_member_die (variant_child
, type
, fi
,
16016 template_args
, cu
);
16017 /* Only handle the one. */
16022 /* We don't handle this but we might as well report it if we see
16024 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
16025 complaint (_("DW_AT_discr_list is not supported yet"
16026 " - DIE at %s [in module %s]"),
16027 sect_offset_str (child_die
->sect_off
),
16028 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16030 /* The first field was just added, so we can stash the
16031 discriminant there. */
16032 gdb_assert (!fi
->fields
.empty ());
16034 fi
->fields
.back ().variant
.default_branch
= true;
16036 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16040 /* Finish creating a structure or union type, including filling in
16041 its members and creating a symbol for it. */
16044 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16046 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16047 struct die_info
*child_die
;
16050 type
= get_die_type (die
, cu
);
16052 type
= read_structure_type (die
, cu
);
16054 /* When reading a DW_TAG_variant_part, we need to notice when we
16055 read the discriminant member, so we can record it later in the
16056 discriminant_info. */
16057 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16058 sect_offset discr_offset
{};
16059 bool has_template_parameters
= false;
16061 if (is_variant_part
)
16063 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16066 /* Maybe it's a univariant form, an extension we support.
16067 In this case arrange not to check the offset. */
16068 is_variant_part
= false;
16070 else if (attr_form_is_ref (discr
))
16072 struct dwarf2_cu
*target_cu
= cu
;
16073 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16075 discr_offset
= target_die
->sect_off
;
16079 complaint (_("DW_AT_discr does not have DIE reference form"
16080 " - DIE at %s [in module %s]"),
16081 sect_offset_str (die
->sect_off
),
16082 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16083 is_variant_part
= false;
16087 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16089 struct field_info fi
;
16090 std::vector
<struct symbol
*> template_args
;
16092 child_die
= die
->child
;
16094 while (child_die
&& child_die
->tag
)
16096 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16098 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16099 fi
.fields
.back ().variant
.is_discriminant
= true;
16101 child_die
= sibling_die (child_die
);
16104 /* Attach template arguments to type. */
16105 if (!template_args
.empty ())
16107 has_template_parameters
= true;
16108 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16109 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16110 TYPE_TEMPLATE_ARGUMENTS (type
)
16111 = XOBNEWVEC (&objfile
->objfile_obstack
,
16113 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16114 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16115 template_args
.data (),
16116 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16117 * sizeof (struct symbol
*)));
16120 /* Attach fields and member functions to the type. */
16122 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16123 if (!fi
.fnfieldlists
.empty ())
16125 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16127 /* Get the type which refers to the base class (possibly this
16128 class itself) which contains the vtable pointer for the current
16129 class from the DW_AT_containing_type attribute. This use of
16130 DW_AT_containing_type is a GNU extension. */
16132 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16134 struct type
*t
= die_containing_type (die
, cu
);
16136 set_type_vptr_basetype (type
, t
);
16141 /* Our own class provides vtbl ptr. */
16142 for (i
= TYPE_NFIELDS (t
) - 1;
16143 i
>= TYPE_N_BASECLASSES (t
);
16146 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16148 if (is_vtable_name (fieldname
, cu
))
16150 set_type_vptr_fieldno (type
, i
);
16155 /* Complain if virtual function table field not found. */
16156 if (i
< TYPE_N_BASECLASSES (t
))
16157 complaint (_("virtual function table pointer "
16158 "not found when defining class '%s'"),
16159 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16163 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16166 else if (cu
->producer
16167 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16169 /* The IBM XLC compiler does not provide direct indication
16170 of the containing type, but the vtable pointer is
16171 always named __vfp. */
16175 for (i
= TYPE_NFIELDS (type
) - 1;
16176 i
>= TYPE_N_BASECLASSES (type
);
16179 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16181 set_type_vptr_fieldno (type
, i
);
16182 set_type_vptr_basetype (type
, type
);
16189 /* Copy fi.typedef_field_list linked list elements content into the
16190 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16191 if (!fi
.typedef_field_list
.empty ())
16193 int count
= fi
.typedef_field_list
.size ();
16195 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16196 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16197 = ((struct decl_field
*)
16199 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16200 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16202 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16203 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16206 /* Copy fi.nested_types_list linked list elements content into the
16207 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16208 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16210 int count
= fi
.nested_types_list
.size ();
16212 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16213 TYPE_NESTED_TYPES_ARRAY (type
)
16214 = ((struct decl_field
*)
16215 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16216 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16218 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16219 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16223 quirk_gcc_member_function_pointer (type
, objfile
);
16224 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16225 cu
->rust_unions
.push_back (type
);
16227 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16228 snapshots) has been known to create a die giving a declaration
16229 for a class that has, as a child, a die giving a definition for a
16230 nested class. So we have to process our children even if the
16231 current die is a declaration. Normally, of course, a declaration
16232 won't have any children at all. */
16234 child_die
= die
->child
;
16236 while (child_die
!= NULL
&& child_die
->tag
)
16238 if (child_die
->tag
== DW_TAG_member
16239 || child_die
->tag
== DW_TAG_variable
16240 || child_die
->tag
== DW_TAG_inheritance
16241 || child_die
->tag
== DW_TAG_template_value_param
16242 || child_die
->tag
== DW_TAG_template_type_param
)
16247 process_die (child_die
, cu
);
16249 child_die
= sibling_die (child_die
);
16252 /* Do not consider external references. According to the DWARF standard,
16253 these DIEs are identified by the fact that they have no byte_size
16254 attribute, and a declaration attribute. */
16255 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16256 || !die_is_declaration (die
, cu
))
16258 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16260 if (has_template_parameters
)
16262 struct symtab
*symtab
;
16263 if (sym
!= nullptr)
16264 symtab
= symbol_symtab (sym
);
16265 else if (cu
->line_header
!= nullptr)
16267 /* Any related symtab will do. */
16269 = cu
->line_header
->file_names ()[0].symtab
;
16274 complaint (_("could not find suitable "
16275 "symtab for template parameter"
16276 " - DIE at %s [in module %s]"),
16277 sect_offset_str (die
->sect_off
),
16278 objfile_name (objfile
));
16281 if (symtab
!= nullptr)
16283 /* Make sure that the symtab is set on the new symbols.
16284 Even though they don't appear in this symtab directly,
16285 other parts of gdb assume that symbols do, and this is
16286 reasonably true. */
16287 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16288 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16294 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16295 update TYPE using some information only available in DIE's children. */
16298 update_enumeration_type_from_children (struct die_info
*die
,
16300 struct dwarf2_cu
*cu
)
16302 struct die_info
*child_die
;
16303 int unsigned_enum
= 1;
16307 auto_obstack obstack
;
16309 for (child_die
= die
->child
;
16310 child_die
!= NULL
&& child_die
->tag
;
16311 child_die
= sibling_die (child_die
))
16313 struct attribute
*attr
;
16315 const gdb_byte
*bytes
;
16316 struct dwarf2_locexpr_baton
*baton
;
16319 if (child_die
->tag
!= DW_TAG_enumerator
)
16322 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16326 name
= dwarf2_name (child_die
, cu
);
16328 name
= "<anonymous enumerator>";
16330 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16331 &value
, &bytes
, &baton
);
16337 else if ((mask
& value
) != 0)
16342 /* If we already know that the enum type is neither unsigned, nor
16343 a flag type, no need to look at the rest of the enumerates. */
16344 if (!unsigned_enum
&& !flag_enum
)
16349 TYPE_UNSIGNED (type
) = 1;
16351 TYPE_FLAG_ENUM (type
) = 1;
16354 /* Given a DW_AT_enumeration_type die, set its type. We do not
16355 complete the type's fields yet, or create any symbols. */
16357 static struct type
*
16358 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16360 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16362 struct attribute
*attr
;
16365 /* If the definition of this type lives in .debug_types, read that type.
16366 Don't follow DW_AT_specification though, that will take us back up
16367 the chain and we want to go down. */
16368 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16369 if (attr
!= nullptr)
16371 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16373 /* The type's CU may not be the same as CU.
16374 Ensure TYPE is recorded with CU in die_type_hash. */
16375 return set_die_type (die
, type
, cu
);
16378 type
= alloc_type (objfile
);
16380 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16381 name
= dwarf2_full_name (NULL
, die
, cu
);
16383 TYPE_NAME (type
) = name
;
16385 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16388 struct type
*underlying_type
= die_type (die
, cu
);
16390 TYPE_TARGET_TYPE (type
) = underlying_type
;
16393 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16394 if (attr
!= nullptr)
16396 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16400 TYPE_LENGTH (type
) = 0;
16403 maybe_set_alignment (cu
, die
, type
);
16405 /* The enumeration DIE can be incomplete. In Ada, any type can be
16406 declared as private in the package spec, and then defined only
16407 inside the package body. Such types are known as Taft Amendment
16408 Types. When another package uses such a type, an incomplete DIE
16409 may be generated by the compiler. */
16410 if (die_is_declaration (die
, cu
))
16411 TYPE_STUB (type
) = 1;
16413 /* Finish the creation of this type by using the enum's children.
16414 We must call this even when the underlying type has been provided
16415 so that we can determine if we're looking at a "flag" enum. */
16416 update_enumeration_type_from_children (die
, type
, cu
);
16418 /* If this type has an underlying type that is not a stub, then we
16419 may use its attributes. We always use the "unsigned" attribute
16420 in this situation, because ordinarily we guess whether the type
16421 is unsigned -- but the guess can be wrong and the underlying type
16422 can tell us the reality. However, we defer to a local size
16423 attribute if one exists, because this lets the compiler override
16424 the underlying type if needed. */
16425 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16427 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16428 if (TYPE_LENGTH (type
) == 0)
16429 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16430 if (TYPE_RAW_ALIGN (type
) == 0
16431 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16432 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16435 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16437 return set_die_type (die
, type
, cu
);
16440 /* Given a pointer to a die which begins an enumeration, process all
16441 the dies that define the members of the enumeration, and create the
16442 symbol for the enumeration type.
16444 NOTE: We reverse the order of the element list. */
16447 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16449 struct type
*this_type
;
16451 this_type
= get_die_type (die
, cu
);
16452 if (this_type
== NULL
)
16453 this_type
= read_enumeration_type (die
, cu
);
16455 if (die
->child
!= NULL
)
16457 struct die_info
*child_die
;
16458 struct symbol
*sym
;
16459 std::vector
<struct field
> fields
;
16462 child_die
= die
->child
;
16463 while (child_die
&& child_die
->tag
)
16465 if (child_die
->tag
!= DW_TAG_enumerator
)
16467 process_die (child_die
, cu
);
16471 name
= dwarf2_name (child_die
, cu
);
16474 sym
= new_symbol (child_die
, this_type
, cu
);
16476 fields
.emplace_back ();
16477 struct field
&field
= fields
.back ();
16479 FIELD_NAME (field
) = sym
->linkage_name ();
16480 FIELD_TYPE (field
) = NULL
;
16481 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
16482 FIELD_BITSIZE (field
) = 0;
16486 child_die
= sibling_die (child_die
);
16489 if (!fields
.empty ())
16491 TYPE_NFIELDS (this_type
) = fields
.size ();
16492 TYPE_FIELDS (this_type
) = (struct field
*)
16493 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
16494 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
16495 sizeof (struct field
) * fields
.size ());
16499 /* If we are reading an enum from a .debug_types unit, and the enum
16500 is a declaration, and the enum is not the signatured type in the
16501 unit, then we do not want to add a symbol for it. Adding a
16502 symbol would in some cases obscure the true definition of the
16503 enum, giving users an incomplete type when the definition is
16504 actually available. Note that we do not want to do this for all
16505 enums which are just declarations, because C++0x allows forward
16506 enum declarations. */
16507 if (cu
->per_cu
->is_debug_types
16508 && die_is_declaration (die
, cu
))
16510 struct signatured_type
*sig_type
;
16512 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16513 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16514 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16518 new_symbol (die
, this_type
, cu
);
16521 /* Extract all information from a DW_TAG_array_type DIE and put it in
16522 the DIE's type field. For now, this only handles one dimensional
16525 static struct type
*
16526 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16528 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16529 struct die_info
*child_die
;
16531 struct type
*element_type
, *range_type
, *index_type
;
16532 struct attribute
*attr
;
16534 struct dynamic_prop
*byte_stride_prop
= NULL
;
16535 unsigned int bit_stride
= 0;
16537 element_type
= die_type (die
, cu
);
16539 /* The die_type call above may have already set the type for this DIE. */
16540 type
= get_die_type (die
, cu
);
16544 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16548 struct type
*prop_type
16549 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16552 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16553 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16557 complaint (_("unable to read array DW_AT_byte_stride "
16558 " - DIE at %s [in module %s]"),
16559 sect_offset_str (die
->sect_off
),
16560 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16561 /* Ignore this attribute. We will likely not be able to print
16562 arrays of this type correctly, but there is little we can do
16563 to help if we cannot read the attribute's value. */
16564 byte_stride_prop
= NULL
;
16568 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16570 bit_stride
= DW_UNSND (attr
);
16572 /* Irix 6.2 native cc creates array types without children for
16573 arrays with unspecified length. */
16574 if (die
->child
== NULL
)
16576 index_type
= objfile_type (objfile
)->builtin_int
;
16577 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16578 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16579 byte_stride_prop
, bit_stride
);
16580 return set_die_type (die
, type
, cu
);
16583 std::vector
<struct type
*> range_types
;
16584 child_die
= die
->child
;
16585 while (child_die
&& child_die
->tag
)
16587 if (child_die
->tag
== DW_TAG_subrange_type
)
16589 struct type
*child_type
= read_type_die (child_die
, cu
);
16591 if (child_type
!= NULL
)
16593 /* The range type was succesfully read. Save it for the
16594 array type creation. */
16595 range_types
.push_back (child_type
);
16598 child_die
= sibling_die (child_die
);
16601 /* Dwarf2 dimensions are output from left to right, create the
16602 necessary array types in backwards order. */
16604 type
= element_type
;
16606 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16610 while (i
< range_types
.size ())
16611 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16612 byte_stride_prop
, bit_stride
);
16616 size_t ndim
= range_types
.size ();
16618 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16619 byte_stride_prop
, bit_stride
);
16622 /* Understand Dwarf2 support for vector types (like they occur on
16623 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16624 array type. This is not part of the Dwarf2/3 standard yet, but a
16625 custom vendor extension. The main difference between a regular
16626 array and the vector variant is that vectors are passed by value
16628 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16629 if (attr
!= nullptr)
16630 make_vector_type (type
);
16632 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16633 implementation may choose to implement triple vectors using this
16635 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16636 if (attr
!= nullptr)
16638 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16639 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16641 complaint (_("DW_AT_byte_size for array type smaller "
16642 "than the total size of elements"));
16645 name
= dwarf2_name (die
, cu
);
16647 TYPE_NAME (type
) = name
;
16649 maybe_set_alignment (cu
, die
, type
);
16651 /* Install the type in the die. */
16652 set_die_type (die
, type
, cu
);
16654 /* set_die_type should be already done. */
16655 set_descriptive_type (type
, die
, cu
);
16660 static enum dwarf_array_dim_ordering
16661 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16663 struct attribute
*attr
;
16665 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16667 if (attr
!= nullptr)
16668 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16670 /* GNU F77 is a special case, as at 08/2004 array type info is the
16671 opposite order to the dwarf2 specification, but data is still
16672 laid out as per normal fortran.
16674 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16675 version checking. */
16677 if (cu
->language
== language_fortran
16678 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16680 return DW_ORD_row_major
;
16683 switch (cu
->language_defn
->la_array_ordering
)
16685 case array_column_major
:
16686 return DW_ORD_col_major
;
16687 case array_row_major
:
16689 return DW_ORD_row_major
;
16693 /* Extract all information from a DW_TAG_set_type DIE and put it in
16694 the DIE's type field. */
16696 static struct type
*
16697 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16699 struct type
*domain_type
, *set_type
;
16700 struct attribute
*attr
;
16702 domain_type
= die_type (die
, cu
);
16704 /* The die_type call above may have already set the type for this DIE. */
16705 set_type
= get_die_type (die
, cu
);
16709 set_type
= create_set_type (NULL
, domain_type
);
16711 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16712 if (attr
!= nullptr)
16713 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16715 maybe_set_alignment (cu
, die
, set_type
);
16717 return set_die_type (die
, set_type
, cu
);
16720 /* A helper for read_common_block that creates a locexpr baton.
16721 SYM is the symbol which we are marking as computed.
16722 COMMON_DIE is the DIE for the common block.
16723 COMMON_LOC is the location expression attribute for the common
16725 MEMBER_LOC is the location expression attribute for the particular
16726 member of the common block that we are processing.
16727 CU is the CU from which the above come. */
16730 mark_common_block_symbol_computed (struct symbol
*sym
,
16731 struct die_info
*common_die
,
16732 struct attribute
*common_loc
,
16733 struct attribute
*member_loc
,
16734 struct dwarf2_cu
*cu
)
16736 struct dwarf2_per_objfile
*dwarf2_per_objfile
16737 = cu
->per_cu
->dwarf2_per_objfile
;
16738 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16739 struct dwarf2_locexpr_baton
*baton
;
16741 unsigned int cu_off
;
16742 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16743 LONGEST offset
= 0;
16745 gdb_assert (common_loc
&& member_loc
);
16746 gdb_assert (attr_form_is_block (common_loc
));
16747 gdb_assert (attr_form_is_block (member_loc
)
16748 || attr_form_is_constant (member_loc
));
16750 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16751 baton
->per_cu
= cu
->per_cu
;
16752 gdb_assert (baton
->per_cu
);
16754 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16756 if (attr_form_is_constant (member_loc
))
16758 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16759 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16762 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16764 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16767 *ptr
++ = DW_OP_call4
;
16768 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16769 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16772 if (attr_form_is_constant (member_loc
))
16774 *ptr
++ = DW_OP_addr
;
16775 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16776 ptr
+= cu
->header
.addr_size
;
16780 /* We have to copy the data here, because DW_OP_call4 will only
16781 use a DW_AT_location attribute. */
16782 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16783 ptr
+= DW_BLOCK (member_loc
)->size
;
16786 *ptr
++ = DW_OP_plus
;
16787 gdb_assert (ptr
- baton
->data
== baton
->size
);
16789 SYMBOL_LOCATION_BATON (sym
) = baton
;
16790 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16793 /* Create appropriate locally-scoped variables for all the
16794 DW_TAG_common_block entries. Also create a struct common_block
16795 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16796 is used to separate the common blocks name namespace from regular
16800 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16802 struct attribute
*attr
;
16804 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16805 if (attr
!= nullptr)
16807 /* Support the .debug_loc offsets. */
16808 if (attr_form_is_block (attr
))
16812 else if (attr_form_is_section_offset (attr
))
16814 dwarf2_complex_location_expr_complaint ();
16819 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16820 "common block member");
16825 if (die
->child
!= NULL
)
16827 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16828 struct die_info
*child_die
;
16829 size_t n_entries
= 0, size
;
16830 struct common_block
*common_block
;
16831 struct symbol
*sym
;
16833 for (child_die
= die
->child
;
16834 child_die
&& child_die
->tag
;
16835 child_die
= sibling_die (child_die
))
16838 size
= (sizeof (struct common_block
)
16839 + (n_entries
- 1) * sizeof (struct symbol
*));
16841 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16843 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16844 common_block
->n_entries
= 0;
16846 for (child_die
= die
->child
;
16847 child_die
&& child_die
->tag
;
16848 child_die
= sibling_die (child_die
))
16850 /* Create the symbol in the DW_TAG_common_block block in the current
16852 sym
= new_symbol (child_die
, NULL
, cu
);
16855 struct attribute
*member_loc
;
16857 common_block
->contents
[common_block
->n_entries
++] = sym
;
16859 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16863 /* GDB has handled this for a long time, but it is
16864 not specified by DWARF. It seems to have been
16865 emitted by gfortran at least as recently as:
16866 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16867 complaint (_("Variable in common block has "
16868 "DW_AT_data_member_location "
16869 "- DIE at %s [in module %s]"),
16870 sect_offset_str (child_die
->sect_off
),
16871 objfile_name (objfile
));
16873 if (attr_form_is_section_offset (member_loc
))
16874 dwarf2_complex_location_expr_complaint ();
16875 else if (attr_form_is_constant (member_loc
)
16876 || attr_form_is_block (member_loc
))
16878 if (attr
!= nullptr)
16879 mark_common_block_symbol_computed (sym
, die
, attr
,
16883 dwarf2_complex_location_expr_complaint ();
16888 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16889 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16893 /* Create a type for a C++ namespace. */
16895 static struct type
*
16896 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16898 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16899 const char *previous_prefix
, *name
;
16903 /* For extensions, reuse the type of the original namespace. */
16904 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16906 struct die_info
*ext_die
;
16907 struct dwarf2_cu
*ext_cu
= cu
;
16909 ext_die
= dwarf2_extension (die
, &ext_cu
);
16910 type
= read_type_die (ext_die
, ext_cu
);
16912 /* EXT_CU may not be the same as CU.
16913 Ensure TYPE is recorded with CU in die_type_hash. */
16914 return set_die_type (die
, type
, cu
);
16917 name
= namespace_name (die
, &is_anonymous
, cu
);
16919 /* Now build the name of the current namespace. */
16921 previous_prefix
= determine_prefix (die
, cu
);
16922 if (previous_prefix
[0] != '\0')
16923 name
= typename_concat (&objfile
->objfile_obstack
,
16924 previous_prefix
, name
, 0, cu
);
16926 /* Create the type. */
16927 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16929 return set_die_type (die
, type
, cu
);
16932 /* Read a namespace scope. */
16935 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16937 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16940 /* Add a symbol associated to this if we haven't seen the namespace
16941 before. Also, add a using directive if it's an anonymous
16944 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16948 type
= read_type_die (die
, cu
);
16949 new_symbol (die
, type
, cu
);
16951 namespace_name (die
, &is_anonymous
, cu
);
16954 const char *previous_prefix
= determine_prefix (die
, cu
);
16956 std::vector
<const char *> excludes
;
16957 add_using_directive (using_directives (cu
),
16958 previous_prefix
, TYPE_NAME (type
), NULL
,
16959 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16963 if (die
->child
!= NULL
)
16965 struct die_info
*child_die
= die
->child
;
16967 while (child_die
&& child_die
->tag
)
16969 process_die (child_die
, cu
);
16970 child_die
= sibling_die (child_die
);
16975 /* Read a Fortran module as type. This DIE can be only a declaration used for
16976 imported module. Still we need that type as local Fortran "use ... only"
16977 declaration imports depend on the created type in determine_prefix. */
16979 static struct type
*
16980 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16982 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16983 const char *module_name
;
16986 module_name
= dwarf2_name (die
, cu
);
16987 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16989 return set_die_type (die
, type
, cu
);
16992 /* Read a Fortran module. */
16995 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16997 struct die_info
*child_die
= die
->child
;
17000 type
= read_type_die (die
, cu
);
17001 new_symbol (die
, type
, cu
);
17003 while (child_die
&& child_die
->tag
)
17005 process_die (child_die
, cu
);
17006 child_die
= sibling_die (child_die
);
17010 /* Return the name of the namespace represented by DIE. Set
17011 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17014 static const char *
17015 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17017 struct die_info
*current_die
;
17018 const char *name
= NULL
;
17020 /* Loop through the extensions until we find a name. */
17022 for (current_die
= die
;
17023 current_die
!= NULL
;
17024 current_die
= dwarf2_extension (die
, &cu
))
17026 /* We don't use dwarf2_name here so that we can detect the absence
17027 of a name -> anonymous namespace. */
17028 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17034 /* Is it an anonymous namespace? */
17036 *is_anonymous
= (name
== NULL
);
17038 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17043 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17044 the user defined type vector. */
17046 static struct type
*
17047 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17049 struct gdbarch
*gdbarch
17050 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17051 struct comp_unit_head
*cu_header
= &cu
->header
;
17053 struct attribute
*attr_byte_size
;
17054 struct attribute
*attr_address_class
;
17055 int byte_size
, addr_class
;
17056 struct type
*target_type
;
17058 target_type
= die_type (die
, cu
);
17060 /* The die_type call above may have already set the type for this DIE. */
17061 type
= get_die_type (die
, cu
);
17065 type
= lookup_pointer_type (target_type
);
17067 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17068 if (attr_byte_size
)
17069 byte_size
= DW_UNSND (attr_byte_size
);
17071 byte_size
= cu_header
->addr_size
;
17073 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17074 if (attr_address_class
)
17075 addr_class
= DW_UNSND (attr_address_class
);
17077 addr_class
= DW_ADDR_none
;
17079 ULONGEST alignment
= get_alignment (cu
, die
);
17081 /* If the pointer size, alignment, or address class is different
17082 than the default, create a type variant marked as such and set
17083 the length accordingly. */
17084 if (TYPE_LENGTH (type
) != byte_size
17085 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17086 && alignment
!= TYPE_RAW_ALIGN (type
))
17087 || addr_class
!= DW_ADDR_none
)
17089 if (gdbarch_address_class_type_flags_p (gdbarch
))
17093 type_flags
= gdbarch_address_class_type_flags
17094 (gdbarch
, byte_size
, addr_class
);
17095 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17097 type
= make_type_with_address_space (type
, type_flags
);
17099 else if (TYPE_LENGTH (type
) != byte_size
)
17101 complaint (_("invalid pointer size %d"), byte_size
);
17103 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17105 complaint (_("Invalid DW_AT_alignment"
17106 " - DIE at %s [in module %s]"),
17107 sect_offset_str (die
->sect_off
),
17108 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17112 /* Should we also complain about unhandled address classes? */
17116 TYPE_LENGTH (type
) = byte_size
;
17117 set_type_align (type
, alignment
);
17118 return set_die_type (die
, type
, cu
);
17121 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17122 the user defined type vector. */
17124 static struct type
*
17125 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17128 struct type
*to_type
;
17129 struct type
*domain
;
17131 to_type
= die_type (die
, cu
);
17132 domain
= die_containing_type (die
, cu
);
17134 /* The calls above may have already set the type for this DIE. */
17135 type
= get_die_type (die
, cu
);
17139 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17140 type
= lookup_methodptr_type (to_type
);
17141 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17143 struct type
*new_type
17144 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17146 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17147 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17148 TYPE_VARARGS (to_type
));
17149 type
= lookup_methodptr_type (new_type
);
17152 type
= lookup_memberptr_type (to_type
, domain
);
17154 return set_die_type (die
, type
, cu
);
17157 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17158 the user defined type vector. */
17160 static struct type
*
17161 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17162 enum type_code refcode
)
17164 struct comp_unit_head
*cu_header
= &cu
->header
;
17165 struct type
*type
, *target_type
;
17166 struct attribute
*attr
;
17168 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17170 target_type
= die_type (die
, cu
);
17172 /* The die_type call above may have already set the type for this DIE. */
17173 type
= get_die_type (die
, cu
);
17177 type
= lookup_reference_type (target_type
, refcode
);
17178 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17179 if (attr
!= nullptr)
17181 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17185 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17187 maybe_set_alignment (cu
, die
, type
);
17188 return set_die_type (die
, type
, cu
);
17191 /* Add the given cv-qualifiers to the element type of the array. GCC
17192 outputs DWARF type qualifiers that apply to an array, not the
17193 element type. But GDB relies on the array element type to carry
17194 the cv-qualifiers. This mimics section 6.7.3 of the C99
17197 static struct type
*
17198 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17199 struct type
*base_type
, int cnst
, int voltl
)
17201 struct type
*el_type
, *inner_array
;
17203 base_type
= copy_type (base_type
);
17204 inner_array
= base_type
;
17206 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17208 TYPE_TARGET_TYPE (inner_array
) =
17209 copy_type (TYPE_TARGET_TYPE (inner_array
));
17210 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17213 el_type
= TYPE_TARGET_TYPE (inner_array
);
17214 cnst
|= TYPE_CONST (el_type
);
17215 voltl
|= TYPE_VOLATILE (el_type
);
17216 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17218 return set_die_type (die
, base_type
, cu
);
17221 static struct type
*
17222 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17224 struct type
*base_type
, *cv_type
;
17226 base_type
= die_type (die
, cu
);
17228 /* The die_type call above may have already set the type for this DIE. */
17229 cv_type
= get_die_type (die
, cu
);
17233 /* In case the const qualifier is applied to an array type, the element type
17234 is so qualified, not the array type (section 6.7.3 of C99). */
17235 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17236 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17238 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17239 return set_die_type (die
, cv_type
, cu
);
17242 static struct type
*
17243 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17245 struct type
*base_type
, *cv_type
;
17247 base_type
= die_type (die
, cu
);
17249 /* The die_type call above may have already set the type for this DIE. */
17250 cv_type
= get_die_type (die
, cu
);
17254 /* In case the volatile qualifier is applied to an array type, the
17255 element type is so qualified, not the array type (section 6.7.3
17257 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17258 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17260 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17261 return set_die_type (die
, cv_type
, cu
);
17264 /* Handle DW_TAG_restrict_type. */
17266 static struct type
*
17267 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17269 struct type
*base_type
, *cv_type
;
17271 base_type
= die_type (die
, cu
);
17273 /* The die_type call above may have already set the type for this DIE. */
17274 cv_type
= get_die_type (die
, cu
);
17278 cv_type
= make_restrict_type (base_type
);
17279 return set_die_type (die
, cv_type
, cu
);
17282 /* Handle DW_TAG_atomic_type. */
17284 static struct type
*
17285 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17287 struct type
*base_type
, *cv_type
;
17289 base_type
= die_type (die
, cu
);
17291 /* The die_type call above may have already set the type for this DIE. */
17292 cv_type
= get_die_type (die
, cu
);
17296 cv_type
= make_atomic_type (base_type
);
17297 return set_die_type (die
, cv_type
, cu
);
17300 /* Extract all information from a DW_TAG_string_type DIE and add to
17301 the user defined type vector. It isn't really a user defined type,
17302 but it behaves like one, with other DIE's using an AT_user_def_type
17303 attribute to reference it. */
17305 static struct type
*
17306 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17308 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17309 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17310 struct type
*type
, *range_type
, *index_type
, *char_type
;
17311 struct attribute
*attr
;
17312 struct dynamic_prop prop
;
17313 bool length_is_constant
= true;
17316 /* There are a couple of places where bit sizes might be made use of
17317 when parsing a DW_TAG_string_type, however, no producer that we know
17318 of make use of these. Handling bit sizes that are a multiple of the
17319 byte size is easy enough, but what about other bit sizes? Lets deal
17320 with that problem when we have to. Warn about these attributes being
17321 unsupported, then parse the type and ignore them like we always
17323 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17324 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17326 static bool warning_printed
= false;
17327 if (!warning_printed
)
17329 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17330 "currently supported on DW_TAG_string_type."));
17331 warning_printed
= true;
17335 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17336 if (attr
!= nullptr && !attr_form_is_constant (attr
))
17338 /* The string length describes the location at which the length of
17339 the string can be found. The size of the length field can be
17340 specified with one of the attributes below. */
17341 struct type
*prop_type
;
17342 struct attribute
*len
17343 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17344 if (len
== nullptr)
17345 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17346 if (len
!= nullptr && attr_form_is_constant (len
))
17348 /* Pass 0 as the default as we know this attribute is constant
17349 and the default value will not be returned. */
17350 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
17351 prop_type
= dwarf2_per_cu_int_type (cu
->per_cu
, sz
, true);
17355 /* If the size is not specified then we assume it is the size of
17356 an address on this target. */
17357 prop_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, true);
17360 /* Convert the attribute into a dynamic property. */
17361 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17364 length_is_constant
= false;
17366 else if (attr
!= nullptr)
17368 /* This DW_AT_string_length just contains the length with no
17369 indirection. There's no need to create a dynamic property in this
17370 case. Pass 0 for the default value as we know it will not be
17371 returned in this case. */
17372 length
= dwarf2_get_attr_constant_value (attr
, 0);
17374 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17376 /* We don't currently support non-constant byte sizes for strings. */
17377 length
= dwarf2_get_attr_constant_value (attr
, 1);
17381 /* Use 1 as a fallback length if we have nothing else. */
17385 index_type
= objfile_type (objfile
)->builtin_int
;
17386 if (length_is_constant
)
17387 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17390 struct dynamic_prop low_bound
;
17392 low_bound
.kind
= PROP_CONST
;
17393 low_bound
.data
.const_val
= 1;
17394 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17396 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17397 type
= create_string_type (NULL
, char_type
, range_type
);
17399 return set_die_type (die
, type
, cu
);
17402 /* Assuming that DIE corresponds to a function, returns nonzero
17403 if the function is prototyped. */
17406 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17408 struct attribute
*attr
;
17410 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17411 if (attr
&& (DW_UNSND (attr
) != 0))
17414 /* The DWARF standard implies that the DW_AT_prototyped attribute
17415 is only meaningful for C, but the concept also extends to other
17416 languages that allow unprototyped functions (Eg: Objective C).
17417 For all other languages, assume that functions are always
17419 if (cu
->language
!= language_c
17420 && cu
->language
!= language_objc
17421 && cu
->language
!= language_opencl
)
17424 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17425 prototyped and unprototyped functions; default to prototyped,
17426 since that is more common in modern code (and RealView warns
17427 about unprototyped functions). */
17428 if (producer_is_realview (cu
->producer
))
17434 /* Handle DIES due to C code like:
17438 int (*funcp)(int a, long l);
17442 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17444 static struct type
*
17445 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17447 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17448 struct type
*type
; /* Type that this function returns. */
17449 struct type
*ftype
; /* Function that returns above type. */
17450 struct attribute
*attr
;
17452 type
= die_type (die
, cu
);
17454 /* The die_type call above may have already set the type for this DIE. */
17455 ftype
= get_die_type (die
, cu
);
17459 ftype
= lookup_function_type (type
);
17461 if (prototyped_function_p (die
, cu
))
17462 TYPE_PROTOTYPED (ftype
) = 1;
17464 /* Store the calling convention in the type if it's available in
17465 the subroutine die. Otherwise set the calling convention to
17466 the default value DW_CC_normal. */
17467 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17468 if (attr
!= nullptr
17469 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17470 TYPE_CALLING_CONVENTION (ftype
)
17471 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17472 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17473 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17475 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17477 /* Record whether the function returns normally to its caller or not
17478 if the DWARF producer set that information. */
17479 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17480 if (attr
&& (DW_UNSND (attr
) != 0))
17481 TYPE_NO_RETURN (ftype
) = 1;
17483 /* We need to add the subroutine type to the die immediately so
17484 we don't infinitely recurse when dealing with parameters
17485 declared as the same subroutine type. */
17486 set_die_type (die
, ftype
, cu
);
17488 if (die
->child
!= NULL
)
17490 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17491 struct die_info
*child_die
;
17492 int nparams
, iparams
;
17494 /* Count the number of parameters.
17495 FIXME: GDB currently ignores vararg functions, but knows about
17496 vararg member functions. */
17498 child_die
= die
->child
;
17499 while (child_die
&& child_die
->tag
)
17501 if (child_die
->tag
== DW_TAG_formal_parameter
)
17503 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17504 TYPE_VARARGS (ftype
) = 1;
17505 child_die
= sibling_die (child_die
);
17508 /* Allocate storage for parameters and fill them in. */
17509 TYPE_NFIELDS (ftype
) = nparams
;
17510 TYPE_FIELDS (ftype
) = (struct field
*)
17511 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17513 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17514 even if we error out during the parameters reading below. */
17515 for (iparams
= 0; iparams
< nparams
; iparams
++)
17516 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17519 child_die
= die
->child
;
17520 while (child_die
&& child_die
->tag
)
17522 if (child_die
->tag
== DW_TAG_formal_parameter
)
17524 struct type
*arg_type
;
17526 /* DWARF version 2 has no clean way to discern C++
17527 static and non-static member functions. G++ helps
17528 GDB by marking the first parameter for non-static
17529 member functions (which is the this pointer) as
17530 artificial. We pass this information to
17531 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17533 DWARF version 3 added DW_AT_object_pointer, which GCC
17534 4.5 does not yet generate. */
17535 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17536 if (attr
!= nullptr)
17537 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17539 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17540 arg_type
= die_type (child_die
, cu
);
17542 /* RealView does not mark THIS as const, which the testsuite
17543 expects. GCC marks THIS as const in method definitions,
17544 but not in the class specifications (GCC PR 43053). */
17545 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17546 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17549 struct dwarf2_cu
*arg_cu
= cu
;
17550 const char *name
= dwarf2_name (child_die
, cu
);
17552 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17553 if (attr
!= nullptr)
17555 /* If the compiler emits this, use it. */
17556 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17559 else if (name
&& strcmp (name
, "this") == 0)
17560 /* Function definitions will have the argument names. */
17562 else if (name
== NULL
&& iparams
== 0)
17563 /* Declarations may not have the names, so like
17564 elsewhere in GDB, assume an artificial first
17565 argument is "this". */
17569 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17573 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17576 child_die
= sibling_die (child_die
);
17583 static struct type
*
17584 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17586 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17587 const char *name
= NULL
;
17588 struct type
*this_type
, *target_type
;
17590 name
= dwarf2_full_name (NULL
, die
, cu
);
17591 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17592 TYPE_TARGET_STUB (this_type
) = 1;
17593 set_die_type (die
, this_type
, cu
);
17594 target_type
= die_type (die
, cu
);
17595 if (target_type
!= this_type
)
17596 TYPE_TARGET_TYPE (this_type
) = target_type
;
17599 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17600 spec and cause infinite loops in GDB. */
17601 complaint (_("Self-referential DW_TAG_typedef "
17602 "- DIE at %s [in module %s]"),
17603 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17604 TYPE_TARGET_TYPE (this_type
) = NULL
;
17609 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17610 (which may be different from NAME) to the architecture back-end to allow
17611 it to guess the correct format if necessary. */
17613 static struct type
*
17614 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17615 const char *name_hint
, enum bfd_endian byte_order
)
17617 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17618 const struct floatformat
**format
;
17621 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17623 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17625 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17630 /* Allocate an integer type of size BITS and name NAME. */
17632 static struct type
*
17633 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17634 int bits
, int unsigned_p
, const char *name
)
17638 /* Versions of Intel's C Compiler generate an integer type called "void"
17639 instead of using DW_TAG_unspecified_type. This has been seen on
17640 at least versions 14, 17, and 18. */
17641 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17642 && strcmp (name
, "void") == 0)
17643 type
= objfile_type (objfile
)->builtin_void
;
17645 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17650 /* Initialise and return a floating point type of size BITS suitable for
17651 use as a component of a complex number. The NAME_HINT is passed through
17652 when initialising the floating point type and is the name of the complex
17655 As DWARF doesn't currently provide an explicit name for the components
17656 of a complex number, but it can be helpful to have these components
17657 named, we try to select a suitable name based on the size of the
17659 static struct type
*
17660 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17661 struct objfile
*objfile
,
17662 int bits
, const char *name_hint
,
17663 enum bfd_endian byte_order
)
17665 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17666 struct type
*tt
= nullptr;
17668 /* Try to find a suitable floating point builtin type of size BITS.
17669 We're going to use the name of this type as the name for the complex
17670 target type that we are about to create. */
17671 switch (cu
->language
)
17673 case language_fortran
:
17677 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17680 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17682 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17684 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17692 tt
= builtin_type (gdbarch
)->builtin_float
;
17695 tt
= builtin_type (gdbarch
)->builtin_double
;
17697 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17699 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17705 /* If the type we found doesn't match the size we were looking for, then
17706 pretend we didn't find a type at all, the complex target type we
17707 create will then be nameless. */
17708 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17711 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17712 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17715 /* Find a representation of a given base type and install
17716 it in the TYPE field of the die. */
17718 static struct type
*
17719 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17721 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17723 struct attribute
*attr
;
17724 int encoding
= 0, bits
= 0;
17728 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17729 if (attr
!= nullptr)
17730 encoding
= DW_UNSND (attr
);
17731 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17732 if (attr
!= nullptr)
17733 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17734 name
= dwarf2_name (die
, cu
);
17736 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17738 arch
= get_objfile_arch (objfile
);
17739 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17741 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17744 int endianity
= DW_UNSND (attr
);
17749 byte_order
= BFD_ENDIAN_BIG
;
17751 case DW_END_little
:
17752 byte_order
= BFD_ENDIAN_LITTLE
;
17755 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17762 case DW_ATE_address
:
17763 /* Turn DW_ATE_address into a void * pointer. */
17764 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17765 type
= init_pointer_type (objfile
, bits
, name
, type
);
17767 case DW_ATE_boolean
:
17768 type
= init_boolean_type (objfile
, bits
, 1, name
);
17770 case DW_ATE_complex_float
:
17771 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17773 type
= init_complex_type (objfile
, name
, type
);
17775 case DW_ATE_decimal_float
:
17776 type
= init_decfloat_type (objfile
, bits
, name
);
17779 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17781 case DW_ATE_signed
:
17782 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17784 case DW_ATE_unsigned
:
17785 if (cu
->language
== language_fortran
17787 && startswith (name
, "character("))
17788 type
= init_character_type (objfile
, bits
, 1, name
);
17790 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17792 case DW_ATE_signed_char
:
17793 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17794 || cu
->language
== language_pascal
17795 || cu
->language
== language_fortran
)
17796 type
= init_character_type (objfile
, bits
, 0, name
);
17798 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17800 case DW_ATE_unsigned_char
:
17801 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17802 || cu
->language
== language_pascal
17803 || cu
->language
== language_fortran
17804 || cu
->language
== language_rust
)
17805 type
= init_character_type (objfile
, bits
, 1, name
);
17807 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17812 type
= builtin_type (arch
)->builtin_char16
;
17813 else if (bits
== 32)
17814 type
= builtin_type (arch
)->builtin_char32
;
17817 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17819 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17821 return set_die_type (die
, type
, cu
);
17826 complaint (_("unsupported DW_AT_encoding: '%s'"),
17827 dwarf_type_encoding_name (encoding
));
17828 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17832 if (name
&& strcmp (name
, "char") == 0)
17833 TYPE_NOSIGN (type
) = 1;
17835 maybe_set_alignment (cu
, die
, type
);
17837 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17839 return set_die_type (die
, type
, cu
);
17842 /* Parse dwarf attribute if it's a block, reference or constant and put the
17843 resulting value of the attribute into struct bound_prop.
17844 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17847 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17848 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17849 struct type
*default_type
)
17851 struct dwarf2_property_baton
*baton
;
17852 struct obstack
*obstack
17853 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17855 gdb_assert (default_type
!= NULL
);
17857 if (attr
== NULL
|| prop
== NULL
)
17860 if (attr_form_is_block (attr
))
17862 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17863 baton
->property_type
= default_type
;
17864 baton
->locexpr
.per_cu
= cu
->per_cu
;
17865 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17866 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17867 switch (attr
->name
)
17869 case DW_AT_string_length
:
17870 baton
->locexpr
.is_reference
= true;
17873 baton
->locexpr
.is_reference
= false;
17876 prop
->data
.baton
= baton
;
17877 prop
->kind
= PROP_LOCEXPR
;
17878 gdb_assert (prop
->data
.baton
!= NULL
);
17880 else if (attr_form_is_ref (attr
))
17882 struct dwarf2_cu
*target_cu
= cu
;
17883 struct die_info
*target_die
;
17884 struct attribute
*target_attr
;
17886 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17887 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17888 if (target_attr
== NULL
)
17889 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17891 if (target_attr
== NULL
)
17894 switch (target_attr
->name
)
17896 case DW_AT_location
:
17897 if (attr_form_is_section_offset (target_attr
))
17899 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17900 baton
->property_type
= die_type (target_die
, target_cu
);
17901 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17902 prop
->data
.baton
= baton
;
17903 prop
->kind
= PROP_LOCLIST
;
17904 gdb_assert (prop
->data
.baton
!= NULL
);
17906 else if (attr_form_is_block (target_attr
))
17908 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17909 baton
->property_type
= die_type (target_die
, target_cu
);
17910 baton
->locexpr
.per_cu
= cu
->per_cu
;
17911 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17912 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17913 baton
->locexpr
.is_reference
= true;
17914 prop
->data
.baton
= baton
;
17915 prop
->kind
= PROP_LOCEXPR
;
17916 gdb_assert (prop
->data
.baton
!= NULL
);
17920 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17921 "dynamic property");
17925 case DW_AT_data_member_location
:
17929 if (!handle_data_member_location (target_die
, target_cu
,
17933 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17934 baton
->property_type
= read_type_die (target_die
->parent
,
17936 baton
->offset_info
.offset
= offset
;
17937 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17938 prop
->data
.baton
= baton
;
17939 prop
->kind
= PROP_ADDR_OFFSET
;
17944 else if (attr_form_is_constant (attr
))
17946 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17947 prop
->kind
= PROP_CONST
;
17951 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17952 dwarf2_name (die
, cu
));
17959 /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
17960 UNSIGNED_P controls if the integer is unsigned or not. */
17962 static struct type
*
17963 dwarf2_per_cu_int_type (struct dwarf2_per_cu_data
*per_cu
,
17964 int size_in_bytes
, bool unsigned_p
)
17966 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
17967 struct type
*int_type
;
17969 /* Helper macro to examine the various builtin types. */
17970 #define TRY_TYPE(F) \
17971 int_type = (unsigned_p \
17972 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17973 : objfile_type (objfile)->builtin_ ## F); \
17974 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17981 TRY_TYPE (long_long
);
17985 gdb_assert_not_reached ("unable to find suitable integer type");
17988 /* Find an integer type the same size as the address size given in the
17989 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
17990 is unsigned or not. */
17992 static struct type
*
17993 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
17996 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
17997 return dwarf2_per_cu_int_type (per_cu
, addr_size
, unsigned_p
);
18000 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18001 present (which is valid) then compute the default type based on the
18002 compilation units address size. */
18004 static struct type
*
18005 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18007 struct type
*index_type
= die_type (die
, cu
);
18009 /* Dwarf-2 specifications explicitly allows to create subrange types
18010 without specifying a base type.
18011 In that case, the base type must be set to the type of
18012 the lower bound, upper bound or count, in that order, if any of these
18013 three attributes references an object that has a type.
18014 If no base type is found, the Dwarf-2 specifications say that
18015 a signed integer type of size equal to the size of an address should
18017 For the following C code: `extern char gdb_int [];'
18018 GCC produces an empty range DIE.
18019 FIXME: muller/2010-05-28: Possible references to object for low bound,
18020 high bound or count are not yet handled by this code. */
18021 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
18022 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18027 /* Read the given DW_AT_subrange DIE. */
18029 static struct type
*
18030 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18032 struct type
*base_type
, *orig_base_type
;
18033 struct type
*range_type
;
18034 struct attribute
*attr
;
18035 struct dynamic_prop low
, high
;
18036 int low_default_is_valid
;
18037 int high_bound_is_count
= 0;
18039 ULONGEST negative_mask
;
18041 orig_base_type
= read_subrange_index_type (die
, cu
);
18043 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18044 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18045 creating the range type, but we use the result of check_typedef
18046 when examining properties of the type. */
18047 base_type
= check_typedef (orig_base_type
);
18049 /* The die_type call above may have already set the type for this DIE. */
18050 range_type
= get_die_type (die
, cu
);
18054 low
.kind
= PROP_CONST
;
18055 high
.kind
= PROP_CONST
;
18056 high
.data
.const_val
= 0;
18058 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18059 omitting DW_AT_lower_bound. */
18060 switch (cu
->language
)
18063 case language_cplus
:
18064 low
.data
.const_val
= 0;
18065 low_default_is_valid
= 1;
18067 case language_fortran
:
18068 low
.data
.const_val
= 1;
18069 low_default_is_valid
= 1;
18072 case language_objc
:
18073 case language_rust
:
18074 low
.data
.const_val
= 0;
18075 low_default_is_valid
= (cu
->header
.version
>= 4);
18079 case language_pascal
:
18080 low
.data
.const_val
= 1;
18081 low_default_is_valid
= (cu
->header
.version
>= 4);
18084 low
.data
.const_val
= 0;
18085 low_default_is_valid
= 0;
18089 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18090 if (attr
!= nullptr)
18091 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18092 else if (!low_default_is_valid
)
18093 complaint (_("Missing DW_AT_lower_bound "
18094 "- DIE at %s [in module %s]"),
18095 sect_offset_str (die
->sect_off
),
18096 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18098 struct attribute
*attr_ub
, *attr_count
;
18099 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18100 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18102 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18103 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18105 /* If bounds are constant do the final calculation here. */
18106 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
18107 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
18109 high_bound_is_count
= 1;
18113 if (attr_ub
!= NULL
)
18114 complaint (_("Unresolved DW_AT_upper_bound "
18115 "- DIE at %s [in module %s]"),
18116 sect_offset_str (die
->sect_off
),
18117 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18118 if (attr_count
!= NULL
)
18119 complaint (_("Unresolved DW_AT_count "
18120 "- DIE at %s [in module %s]"),
18121 sect_offset_str (die
->sect_off
),
18122 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18127 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18128 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
18129 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
18131 /* Normally, the DWARF producers are expected to use a signed
18132 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18133 But this is unfortunately not always the case, as witnessed
18134 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18135 is used instead. To work around that ambiguity, we treat
18136 the bounds as signed, and thus sign-extend their values, when
18137 the base type is signed. */
18139 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18140 if (low
.kind
== PROP_CONST
18141 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18142 low
.data
.const_val
|= negative_mask
;
18143 if (high
.kind
== PROP_CONST
18144 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18145 high
.data
.const_val
|= negative_mask
;
18147 /* Check for bit and byte strides. */
18148 struct dynamic_prop byte_stride_prop
;
18149 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18150 if (attr_byte_stride
!= nullptr)
18152 struct type
*prop_type
18153 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18154 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18158 struct dynamic_prop bit_stride_prop
;
18159 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18160 if (attr_bit_stride
!= nullptr)
18162 /* It only makes sense to have either a bit or byte stride. */
18163 if (attr_byte_stride
!= nullptr)
18165 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18166 "- DIE at %s [in module %s]"),
18167 sect_offset_str (die
->sect_off
),
18168 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18169 attr_bit_stride
= nullptr;
18173 struct type
*prop_type
18174 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18175 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18180 if (attr_byte_stride
!= nullptr
18181 || attr_bit_stride
!= nullptr)
18183 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18184 struct dynamic_prop
*stride
18185 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18188 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18189 &high
, bias
, stride
, byte_stride_p
);
18192 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18194 if (high_bound_is_count
)
18195 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18197 /* Ada expects an empty array on no boundary attributes. */
18198 if (attr
== NULL
&& cu
->language
!= language_ada
)
18199 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18201 name
= dwarf2_name (die
, cu
);
18203 TYPE_NAME (range_type
) = name
;
18205 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18206 if (attr
!= nullptr)
18207 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18209 maybe_set_alignment (cu
, die
, range_type
);
18211 set_die_type (die
, range_type
, cu
);
18213 /* set_die_type should be already done. */
18214 set_descriptive_type (range_type
, die
, cu
);
18219 static struct type
*
18220 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18224 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18226 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18228 /* In Ada, an unspecified type is typically used when the description
18229 of the type is deferred to a different unit. When encountering
18230 such a type, we treat it as a stub, and try to resolve it later on,
18232 if (cu
->language
== language_ada
)
18233 TYPE_STUB (type
) = 1;
18235 return set_die_type (die
, type
, cu
);
18238 /* Read a single die and all its descendents. Set the die's sibling
18239 field to NULL; set other fields in the die correctly, and set all
18240 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18241 location of the info_ptr after reading all of those dies. PARENT
18242 is the parent of the die in question. */
18244 static struct die_info
*
18245 read_die_and_children (const struct die_reader_specs
*reader
,
18246 const gdb_byte
*info_ptr
,
18247 const gdb_byte
**new_info_ptr
,
18248 struct die_info
*parent
)
18250 struct die_info
*die
;
18251 const gdb_byte
*cur_ptr
;
18254 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18257 *new_info_ptr
= cur_ptr
;
18260 store_in_ref_table (die
, reader
->cu
);
18263 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18267 *new_info_ptr
= cur_ptr
;
18270 die
->sibling
= NULL
;
18271 die
->parent
= parent
;
18275 /* Read a die, all of its descendents, and all of its siblings; set
18276 all of the fields of all of the dies correctly. Arguments are as
18277 in read_die_and_children. */
18279 static struct die_info
*
18280 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18281 const gdb_byte
*info_ptr
,
18282 const gdb_byte
**new_info_ptr
,
18283 struct die_info
*parent
)
18285 struct die_info
*first_die
, *last_sibling
;
18286 const gdb_byte
*cur_ptr
;
18288 cur_ptr
= info_ptr
;
18289 first_die
= last_sibling
= NULL
;
18293 struct die_info
*die
18294 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18298 *new_info_ptr
= cur_ptr
;
18305 last_sibling
->sibling
= die
;
18307 last_sibling
= die
;
18311 /* Read a die, all of its descendents, and all of its siblings; set
18312 all of the fields of all of the dies correctly. Arguments are as
18313 in read_die_and_children.
18314 This the main entry point for reading a DIE and all its children. */
18316 static struct die_info
*
18317 read_die_and_siblings (const struct die_reader_specs
*reader
,
18318 const gdb_byte
*info_ptr
,
18319 const gdb_byte
**new_info_ptr
,
18320 struct die_info
*parent
)
18322 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18323 new_info_ptr
, parent
);
18325 if (dwarf_die_debug
)
18327 fprintf_unfiltered (gdb_stdlog
,
18328 "Read die from %s@0x%x of %s:\n",
18329 get_section_name (reader
->die_section
),
18330 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18331 bfd_get_filename (reader
->abfd
));
18332 dump_die (die
, dwarf_die_debug
);
18338 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18340 The caller is responsible for filling in the extra attributes
18341 and updating (*DIEP)->num_attrs.
18342 Set DIEP to point to a newly allocated die with its information,
18343 except for its child, sibling, and parent fields.
18344 Set HAS_CHILDREN to tell whether the die has children or not. */
18346 static const gdb_byte
*
18347 read_full_die_1 (const struct die_reader_specs
*reader
,
18348 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18349 int *has_children
, int num_extra_attrs
)
18351 unsigned int abbrev_number
, bytes_read
, i
;
18352 struct abbrev_info
*abbrev
;
18353 struct die_info
*die
;
18354 struct dwarf2_cu
*cu
= reader
->cu
;
18355 bfd
*abfd
= reader
->abfd
;
18357 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18358 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18359 info_ptr
+= bytes_read
;
18360 if (!abbrev_number
)
18367 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18369 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18371 bfd_get_filename (abfd
));
18373 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18374 die
->sect_off
= sect_off
;
18375 die
->tag
= abbrev
->tag
;
18376 die
->abbrev
= abbrev_number
;
18378 /* Make the result usable.
18379 The caller needs to update num_attrs after adding the extra
18381 die
->num_attrs
= abbrev
->num_attrs
;
18383 std::vector
<int> indexes_that_need_reprocess
;
18384 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18386 bool need_reprocess
;
18388 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18389 info_ptr
, &need_reprocess
);
18390 if (need_reprocess
)
18391 indexes_that_need_reprocess
.push_back (i
);
18394 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
18395 if (attr
!= nullptr)
18396 cu
->str_offsets_base
= DW_UNSND (attr
);
18398 auto maybe_addr_base
= lookup_addr_base(die
);
18399 if (maybe_addr_base
.has_value ())
18400 cu
->addr_base
= *maybe_addr_base
;
18401 for (int index
: indexes_that_need_reprocess
)
18402 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18404 *has_children
= abbrev
->has_children
;
18408 /* Read a die and all its attributes.
18409 Set DIEP to point to a newly allocated die with its information,
18410 except for its child, sibling, and parent fields.
18411 Set HAS_CHILDREN to tell whether the die has children or not. */
18413 static const gdb_byte
*
18414 read_full_die (const struct die_reader_specs
*reader
,
18415 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18418 const gdb_byte
*result
;
18420 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18422 if (dwarf_die_debug
)
18424 fprintf_unfiltered (gdb_stdlog
,
18425 "Read die from %s@0x%x of %s:\n",
18426 get_section_name (reader
->die_section
),
18427 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18428 bfd_get_filename (reader
->abfd
));
18429 dump_die (*diep
, dwarf_die_debug
);
18435 /* Abbreviation tables.
18437 In DWARF version 2, the description of the debugging information is
18438 stored in a separate .debug_abbrev section. Before we read any
18439 dies from a section we read in all abbreviations and install them
18440 in a hash table. */
18442 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18444 struct abbrev_info
*
18445 abbrev_table::alloc_abbrev ()
18447 struct abbrev_info
*abbrev
;
18449 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18450 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18455 /* Add an abbreviation to the table. */
18458 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18459 struct abbrev_info
*abbrev
)
18461 unsigned int hash_number
;
18463 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18464 abbrev
->next
= m_abbrevs
[hash_number
];
18465 m_abbrevs
[hash_number
] = abbrev
;
18468 /* Look up an abbrev in the table.
18469 Returns NULL if the abbrev is not found. */
18471 struct abbrev_info
*
18472 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18474 unsigned int hash_number
;
18475 struct abbrev_info
*abbrev
;
18477 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18478 abbrev
= m_abbrevs
[hash_number
];
18482 if (abbrev
->number
== abbrev_number
)
18484 abbrev
= abbrev
->next
;
18489 /* Read in an abbrev table. */
18491 static abbrev_table_up
18492 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18493 struct dwarf2_section_info
*section
,
18494 sect_offset sect_off
)
18496 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18497 bfd
*abfd
= get_section_bfd_owner (section
);
18498 const gdb_byte
*abbrev_ptr
;
18499 struct abbrev_info
*cur_abbrev
;
18500 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18501 unsigned int abbrev_form
;
18502 std::vector
<struct attr_abbrev
> cur_attrs
;
18504 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18506 dwarf2_read_section (objfile
, section
);
18507 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18508 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18509 abbrev_ptr
+= bytes_read
;
18511 /* Loop until we reach an abbrev number of 0. */
18512 while (abbrev_number
)
18514 cur_attrs
.clear ();
18515 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18517 /* read in abbrev header */
18518 cur_abbrev
->number
= abbrev_number
;
18520 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18521 abbrev_ptr
+= bytes_read
;
18522 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18525 /* now read in declarations */
18528 LONGEST implicit_const
;
18530 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18531 abbrev_ptr
+= bytes_read
;
18532 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18533 abbrev_ptr
+= bytes_read
;
18534 if (abbrev_form
== DW_FORM_implicit_const
)
18536 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18538 abbrev_ptr
+= bytes_read
;
18542 /* Initialize it due to a false compiler warning. */
18543 implicit_const
= -1;
18546 if (abbrev_name
== 0)
18549 cur_attrs
.emplace_back ();
18550 struct attr_abbrev
&cur_attr
= cur_attrs
.back ();
18551 cur_attr
.name
= (enum dwarf_attribute
) abbrev_name
;
18552 cur_attr
.form
= (enum dwarf_form
) abbrev_form
;
18553 cur_attr
.implicit_const
= implicit_const
;
18554 ++cur_abbrev
->num_attrs
;
18557 cur_abbrev
->attrs
=
18558 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18559 cur_abbrev
->num_attrs
);
18560 memcpy (cur_abbrev
->attrs
, cur_attrs
.data (),
18561 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18563 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18565 /* Get next abbreviation.
18566 Under Irix6 the abbreviations for a compilation unit are not
18567 always properly terminated with an abbrev number of 0.
18568 Exit loop if we encounter an abbreviation which we have
18569 already read (which means we are about to read the abbreviations
18570 for the next compile unit) or if the end of the abbreviation
18571 table is reached. */
18572 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18574 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18575 abbrev_ptr
+= bytes_read
;
18576 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18580 return abbrev_table
;
18583 /* Returns nonzero if TAG represents a type that we might generate a partial
18587 is_type_tag_for_partial (int tag
)
18592 /* Some types that would be reasonable to generate partial symbols for,
18593 that we don't at present. */
18594 case DW_TAG_array_type
:
18595 case DW_TAG_file_type
:
18596 case DW_TAG_ptr_to_member_type
:
18597 case DW_TAG_set_type
:
18598 case DW_TAG_string_type
:
18599 case DW_TAG_subroutine_type
:
18601 case DW_TAG_base_type
:
18602 case DW_TAG_class_type
:
18603 case DW_TAG_interface_type
:
18604 case DW_TAG_enumeration_type
:
18605 case DW_TAG_structure_type
:
18606 case DW_TAG_subrange_type
:
18607 case DW_TAG_typedef
:
18608 case DW_TAG_union_type
:
18615 /* Load all DIEs that are interesting for partial symbols into memory. */
18617 static struct partial_die_info
*
18618 load_partial_dies (const struct die_reader_specs
*reader
,
18619 const gdb_byte
*info_ptr
, int building_psymtab
)
18621 struct dwarf2_cu
*cu
= reader
->cu
;
18622 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18623 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18624 unsigned int bytes_read
;
18625 unsigned int load_all
= 0;
18626 int nesting_level
= 1;
18631 gdb_assert (cu
->per_cu
!= NULL
);
18632 if (cu
->per_cu
->load_all_dies
)
18636 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18640 &cu
->comp_unit_obstack
,
18641 hashtab_obstack_allocate
,
18642 dummy_obstack_deallocate
);
18646 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18648 /* A NULL abbrev means the end of a series of children. */
18649 if (abbrev
== NULL
)
18651 if (--nesting_level
== 0)
18654 info_ptr
+= bytes_read
;
18655 last_die
= parent_die
;
18656 parent_die
= parent_die
->die_parent
;
18660 /* Check for template arguments. We never save these; if
18661 they're seen, we just mark the parent, and go on our way. */
18662 if (parent_die
!= NULL
18663 && cu
->language
== language_cplus
18664 && (abbrev
->tag
== DW_TAG_template_type_param
18665 || abbrev
->tag
== DW_TAG_template_value_param
))
18667 parent_die
->has_template_arguments
= 1;
18671 /* We don't need a partial DIE for the template argument. */
18672 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18677 /* We only recurse into c++ subprograms looking for template arguments.
18678 Skip their other children. */
18680 && cu
->language
== language_cplus
18681 && parent_die
!= NULL
18682 && parent_die
->tag
== DW_TAG_subprogram
)
18684 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18688 /* Check whether this DIE is interesting enough to save. Normally
18689 we would not be interested in members here, but there may be
18690 later variables referencing them via DW_AT_specification (for
18691 static members). */
18693 && !is_type_tag_for_partial (abbrev
->tag
)
18694 && abbrev
->tag
!= DW_TAG_constant
18695 && abbrev
->tag
!= DW_TAG_enumerator
18696 && abbrev
->tag
!= DW_TAG_subprogram
18697 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18698 && abbrev
->tag
!= DW_TAG_lexical_block
18699 && abbrev
->tag
!= DW_TAG_variable
18700 && abbrev
->tag
!= DW_TAG_namespace
18701 && abbrev
->tag
!= DW_TAG_module
18702 && abbrev
->tag
!= DW_TAG_member
18703 && abbrev
->tag
!= DW_TAG_imported_unit
18704 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18706 /* Otherwise we skip to the next sibling, if any. */
18707 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18711 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18714 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18716 /* This two-pass algorithm for processing partial symbols has a
18717 high cost in cache pressure. Thus, handle some simple cases
18718 here which cover the majority of C partial symbols. DIEs
18719 which neither have specification tags in them, nor could have
18720 specification tags elsewhere pointing at them, can simply be
18721 processed and discarded.
18723 This segment is also optional; scan_partial_symbols and
18724 add_partial_symbol will handle these DIEs if we chain
18725 them in normally. When compilers which do not emit large
18726 quantities of duplicate debug information are more common,
18727 this code can probably be removed. */
18729 /* Any complete simple types at the top level (pretty much all
18730 of them, for a language without namespaces), can be processed
18732 if (parent_die
== NULL
18733 && pdi
.has_specification
== 0
18734 && pdi
.is_declaration
== 0
18735 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18736 || pdi
.tag
== DW_TAG_base_type
18737 || pdi
.tag
== DW_TAG_subrange_type
))
18739 if (building_psymtab
&& pdi
.name
!= NULL
)
18740 add_psymbol_to_list (pdi
.name
, false,
18741 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18742 psymbol_placement::STATIC
,
18743 0, cu
->language
, objfile
);
18744 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18748 /* The exception for DW_TAG_typedef with has_children above is
18749 a workaround of GCC PR debug/47510. In the case of this complaint
18750 type_name_or_error will error on such types later.
18752 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18753 it could not find the child DIEs referenced later, this is checked
18754 above. In correct DWARF DW_TAG_typedef should have no children. */
18756 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18757 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18758 "- DIE at %s [in module %s]"),
18759 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18761 /* If we're at the second level, and we're an enumerator, and
18762 our parent has no specification (meaning possibly lives in a
18763 namespace elsewhere), then we can add the partial symbol now
18764 instead of queueing it. */
18765 if (pdi
.tag
== DW_TAG_enumerator
18766 && parent_die
!= NULL
18767 && parent_die
->die_parent
== NULL
18768 && parent_die
->tag
== DW_TAG_enumeration_type
18769 && parent_die
->has_specification
== 0)
18771 if (pdi
.name
== NULL
)
18772 complaint (_("malformed enumerator DIE ignored"));
18773 else if (building_psymtab
)
18774 add_psymbol_to_list (pdi
.name
, false,
18775 VAR_DOMAIN
, LOC_CONST
, -1,
18776 cu
->language
== language_cplus
18777 ? psymbol_placement::GLOBAL
18778 : psymbol_placement::STATIC
,
18779 0, cu
->language
, objfile
);
18781 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18785 struct partial_die_info
*part_die
18786 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18788 /* We'll save this DIE so link it in. */
18789 part_die
->die_parent
= parent_die
;
18790 part_die
->die_sibling
= NULL
;
18791 part_die
->die_child
= NULL
;
18793 if (last_die
&& last_die
== parent_die
)
18794 last_die
->die_child
= part_die
;
18796 last_die
->die_sibling
= part_die
;
18798 last_die
= part_die
;
18800 if (first_die
== NULL
)
18801 first_die
= part_die
;
18803 /* Maybe add the DIE to the hash table. Not all DIEs that we
18804 find interesting need to be in the hash table, because we
18805 also have the parent/sibling/child chains; only those that we
18806 might refer to by offset later during partial symbol reading.
18808 For now this means things that might have be the target of a
18809 DW_AT_specification, DW_AT_abstract_origin, or
18810 DW_AT_extension. DW_AT_extension will refer only to
18811 namespaces; DW_AT_abstract_origin refers to functions (and
18812 many things under the function DIE, but we do not recurse
18813 into function DIEs during partial symbol reading) and
18814 possibly variables as well; DW_AT_specification refers to
18815 declarations. Declarations ought to have the DW_AT_declaration
18816 flag. It happens that GCC forgets to put it in sometimes, but
18817 only for functions, not for types.
18819 Adding more things than necessary to the hash table is harmless
18820 except for the performance cost. Adding too few will result in
18821 wasted time in find_partial_die, when we reread the compilation
18822 unit with load_all_dies set. */
18825 || abbrev
->tag
== DW_TAG_constant
18826 || abbrev
->tag
== DW_TAG_subprogram
18827 || abbrev
->tag
== DW_TAG_variable
18828 || abbrev
->tag
== DW_TAG_namespace
18829 || part_die
->is_declaration
)
18833 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18834 to_underlying (part_die
->sect_off
),
18839 /* For some DIEs we want to follow their children (if any). For C
18840 we have no reason to follow the children of structures; for other
18841 languages we have to, so that we can get at method physnames
18842 to infer fully qualified class names, for DW_AT_specification,
18843 and for C++ template arguments. For C++, we also look one level
18844 inside functions to find template arguments (if the name of the
18845 function does not already contain the template arguments).
18847 For Ada and Fortran, we need to scan the children of subprograms
18848 and lexical blocks as well because these languages allow the
18849 definition of nested entities that could be interesting for the
18850 debugger, such as nested subprograms for instance. */
18851 if (last_die
->has_children
18853 || last_die
->tag
== DW_TAG_namespace
18854 || last_die
->tag
== DW_TAG_module
18855 || last_die
->tag
== DW_TAG_enumeration_type
18856 || (cu
->language
== language_cplus
18857 && last_die
->tag
== DW_TAG_subprogram
18858 && (last_die
->name
== NULL
18859 || strchr (last_die
->name
, '<') == NULL
))
18860 || (cu
->language
!= language_c
18861 && (last_die
->tag
== DW_TAG_class_type
18862 || last_die
->tag
== DW_TAG_interface_type
18863 || last_die
->tag
== DW_TAG_structure_type
18864 || last_die
->tag
== DW_TAG_union_type
))
18865 || ((cu
->language
== language_ada
18866 || cu
->language
== language_fortran
)
18867 && (last_die
->tag
== DW_TAG_subprogram
18868 || last_die
->tag
== DW_TAG_lexical_block
))))
18871 parent_die
= last_die
;
18875 /* Otherwise we skip to the next sibling, if any. */
18876 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18878 /* Back to the top, do it again. */
18882 partial_die_info::partial_die_info (sect_offset sect_off_
,
18883 struct abbrev_info
*abbrev
)
18884 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18888 /* Read a minimal amount of information into the minimal die structure.
18889 INFO_PTR should point just after the initial uleb128 of a DIE. */
18892 partial_die_info::read (const struct die_reader_specs
*reader
,
18893 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18895 struct dwarf2_cu
*cu
= reader
->cu
;
18896 struct dwarf2_per_objfile
*dwarf2_per_objfile
18897 = cu
->per_cu
->dwarf2_per_objfile
;
18899 int has_low_pc_attr
= 0;
18900 int has_high_pc_attr
= 0;
18901 int high_pc_relative
= 0;
18903 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
18904 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18906 bool need_reprocess
;
18907 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
18908 info_ptr
, &need_reprocess
);
18909 /* String and address offsets that need to do the reprocessing have
18910 already been read at this point, so there is no need to wait until
18911 the loop terminates to do the reprocessing. */
18912 if (need_reprocess
)
18913 read_attribute_reprocess (reader
, &attr_vec
[i
]);
18914 attribute
&attr
= attr_vec
[i
];
18915 /* Store the data if it is of an attribute we want to keep in a
18916 partial symbol table. */
18922 case DW_TAG_compile_unit
:
18923 case DW_TAG_partial_unit
:
18924 case DW_TAG_type_unit
:
18925 /* Compilation units have a DW_AT_name that is a filename, not
18926 a source language identifier. */
18927 case DW_TAG_enumeration_type
:
18928 case DW_TAG_enumerator
:
18929 /* These tags always have simple identifiers already; no need
18930 to canonicalize them. */
18931 name
= DW_STRING (&attr
);
18935 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18938 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18939 &objfile
->per_bfd
->storage_obstack
);
18944 case DW_AT_linkage_name
:
18945 case DW_AT_MIPS_linkage_name
:
18946 /* Note that both forms of linkage name might appear. We
18947 assume they will be the same, and we only store the last
18949 linkage_name
= DW_STRING (&attr
);
18952 has_low_pc_attr
= 1;
18953 lowpc
= attr_value_as_address (&attr
);
18955 case DW_AT_high_pc
:
18956 has_high_pc_attr
= 1;
18957 highpc
= attr_value_as_address (&attr
);
18958 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18959 high_pc_relative
= 1;
18961 case DW_AT_location
:
18962 /* Support the .debug_loc offsets. */
18963 if (attr_form_is_block (&attr
))
18965 d
.locdesc
= DW_BLOCK (&attr
);
18967 else if (attr_form_is_section_offset (&attr
))
18969 dwarf2_complex_location_expr_complaint ();
18973 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18974 "partial symbol information");
18977 case DW_AT_external
:
18978 is_external
= DW_UNSND (&attr
);
18980 case DW_AT_declaration
:
18981 is_declaration
= DW_UNSND (&attr
);
18986 case DW_AT_abstract_origin
:
18987 case DW_AT_specification
:
18988 case DW_AT_extension
:
18989 has_specification
= 1;
18990 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18991 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18992 || cu
->per_cu
->is_dwz
);
18994 case DW_AT_sibling
:
18995 /* Ignore absolute siblings, they might point outside of
18996 the current compile unit. */
18997 if (attr
.form
== DW_FORM_ref_addr
)
18998 complaint (_("ignoring absolute DW_AT_sibling"));
19001 const gdb_byte
*buffer
= reader
->buffer
;
19002 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
19003 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19005 if (sibling_ptr
< info_ptr
)
19006 complaint (_("DW_AT_sibling points backwards"));
19007 else if (sibling_ptr
> reader
->buffer_end
)
19008 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
19010 sibling
= sibling_ptr
;
19013 case DW_AT_byte_size
:
19016 case DW_AT_const_value
:
19017 has_const_value
= 1;
19019 case DW_AT_calling_convention
:
19020 /* DWARF doesn't provide a way to identify a program's source-level
19021 entry point. DW_AT_calling_convention attributes are only meant
19022 to describe functions' calling conventions.
19024 However, because it's a necessary piece of information in
19025 Fortran, and before DWARF 4 DW_CC_program was the only
19026 piece of debugging information whose definition refers to
19027 a 'main program' at all, several compilers marked Fortran
19028 main programs with DW_CC_program --- even when those
19029 functions use the standard calling conventions.
19031 Although DWARF now specifies a way to provide this
19032 information, we support this practice for backward
19034 if (DW_UNSND (&attr
) == DW_CC_program
19035 && cu
->language
== language_fortran
)
19036 main_subprogram
= 1;
19039 if (DW_UNSND (&attr
) == DW_INL_inlined
19040 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
19041 may_be_inlined
= 1;
19045 if (tag
== DW_TAG_imported_unit
)
19047 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
19048 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19049 || cu
->per_cu
->is_dwz
);
19053 case DW_AT_main_subprogram
:
19054 main_subprogram
= DW_UNSND (&attr
);
19059 /* It would be nice to reuse dwarf2_get_pc_bounds here,
19060 but that requires a full DIE, so instead we just
19062 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
19063 unsigned int ranges_offset
= (DW_UNSND (&attr
)
19064 + (need_ranges_base
19068 /* Value of the DW_AT_ranges attribute is the offset in the
19069 .debug_ranges section. */
19070 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19081 /* For Ada, if both the name and the linkage name appear, we prefer
19082 the latter. This lets "catch exception" work better, regardless
19083 of the order in which the name and linkage name were emitted.
19084 Really, though, this is just a workaround for the fact that gdb
19085 doesn't store both the name and the linkage name. */
19086 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19087 name
= linkage_name
;
19089 if (high_pc_relative
)
19092 if (has_low_pc_attr
&& has_high_pc_attr
)
19094 /* When using the GNU linker, .gnu.linkonce. sections are used to
19095 eliminate duplicate copies of functions and vtables and such.
19096 The linker will arbitrarily choose one and discard the others.
19097 The AT_*_pc values for such functions refer to local labels in
19098 these sections. If the section from that file was discarded, the
19099 labels are not in the output, so the relocs get a value of 0.
19100 If this is a discarded function, mark the pc bounds as invalid,
19101 so that GDB will ignore it. */
19102 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
19104 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19105 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19107 complaint (_("DW_AT_low_pc %s is zero "
19108 "for DIE at %s [in module %s]"),
19109 paddress (gdbarch
, lowpc
),
19110 sect_offset_str (sect_off
),
19111 objfile_name (objfile
));
19113 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19114 else if (lowpc
>= highpc
)
19116 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19117 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19119 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19120 "for DIE at %s [in module %s]"),
19121 paddress (gdbarch
, lowpc
),
19122 paddress (gdbarch
, highpc
),
19123 sect_offset_str (sect_off
),
19124 objfile_name (objfile
));
19133 /* Find a cached partial DIE at OFFSET in CU. */
19135 struct partial_die_info
*
19136 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19138 struct partial_die_info
*lookup_die
= NULL
;
19139 struct partial_die_info
part_die (sect_off
);
19141 lookup_die
= ((struct partial_die_info
*)
19142 htab_find_with_hash (partial_dies
, &part_die
,
19143 to_underlying (sect_off
)));
19148 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19149 except in the case of .debug_types DIEs which do not reference
19150 outside their CU (they do however referencing other types via
19151 DW_FORM_ref_sig8). */
19153 static const struct cu_partial_die_info
19154 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19156 struct dwarf2_per_objfile
*dwarf2_per_objfile
19157 = cu
->per_cu
->dwarf2_per_objfile
;
19158 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19159 struct dwarf2_per_cu_data
*per_cu
= NULL
;
19160 struct partial_die_info
*pd
= NULL
;
19162 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19163 && offset_in_cu_p (&cu
->header
, sect_off
))
19165 pd
= cu
->find_partial_die (sect_off
);
19168 /* We missed recording what we needed.
19169 Load all dies and try again. */
19170 per_cu
= cu
->per_cu
;
19174 /* TUs don't reference other CUs/TUs (except via type signatures). */
19175 if (cu
->per_cu
->is_debug_types
)
19177 error (_("Dwarf Error: Type Unit at offset %s contains"
19178 " external reference to offset %s [in module %s].\n"),
19179 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19180 bfd_get_filename (objfile
->obfd
));
19182 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19183 dwarf2_per_objfile
);
19185 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
19186 load_partial_comp_unit (per_cu
);
19188 per_cu
->cu
->last_used
= 0;
19189 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19192 /* If we didn't find it, and not all dies have been loaded,
19193 load them all and try again. */
19195 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
19197 per_cu
->load_all_dies
= 1;
19199 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19200 THIS_CU->cu may already be in use. So we can't just free it and
19201 replace its DIEs with the ones we read in. Instead, we leave those
19202 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19203 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19205 load_partial_comp_unit (per_cu
);
19207 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19211 internal_error (__FILE__
, __LINE__
,
19212 _("could not find partial DIE %s "
19213 "in cache [from module %s]\n"),
19214 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19215 return { per_cu
->cu
, pd
};
19218 /* See if we can figure out if the class lives in a namespace. We do
19219 this by looking for a member function; its demangled name will
19220 contain namespace info, if there is any. */
19223 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19224 struct dwarf2_cu
*cu
)
19226 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19227 what template types look like, because the demangler
19228 frequently doesn't give the same name as the debug info. We
19229 could fix this by only using the demangled name to get the
19230 prefix (but see comment in read_structure_type). */
19232 struct partial_die_info
*real_pdi
;
19233 struct partial_die_info
*child_pdi
;
19235 /* If this DIE (this DIE's specification, if any) has a parent, then
19236 we should not do this. We'll prepend the parent's fully qualified
19237 name when we create the partial symbol. */
19239 real_pdi
= struct_pdi
;
19240 while (real_pdi
->has_specification
)
19242 auto res
= find_partial_die (real_pdi
->spec_offset
,
19243 real_pdi
->spec_is_dwz
, cu
);
19244 real_pdi
= res
.pdi
;
19248 if (real_pdi
->die_parent
!= NULL
)
19251 for (child_pdi
= struct_pdi
->die_child
;
19253 child_pdi
= child_pdi
->die_sibling
)
19255 if (child_pdi
->tag
== DW_TAG_subprogram
19256 && child_pdi
->linkage_name
!= NULL
)
19258 gdb::unique_xmalloc_ptr
<char> actual_class_name
19259 (language_class_name_from_physname (cu
->language_defn
,
19260 child_pdi
->linkage_name
));
19261 if (actual_class_name
!= NULL
)
19263 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19265 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
19266 actual_class_name
.get ());
19274 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19276 /* Once we've fixed up a die, there's no point in doing so again.
19277 This also avoids a memory leak if we were to call
19278 guess_partial_die_structure_name multiple times. */
19282 /* If we found a reference attribute and the DIE has no name, try
19283 to find a name in the referred to DIE. */
19285 if (name
== NULL
&& has_specification
)
19287 struct partial_die_info
*spec_die
;
19289 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19290 spec_die
= res
.pdi
;
19293 spec_die
->fixup (cu
);
19295 if (spec_die
->name
)
19297 name
= spec_die
->name
;
19299 /* Copy DW_AT_external attribute if it is set. */
19300 if (spec_die
->is_external
)
19301 is_external
= spec_die
->is_external
;
19305 /* Set default names for some unnamed DIEs. */
19307 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19308 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19310 /* If there is no parent die to provide a namespace, and there are
19311 children, see if we can determine the namespace from their linkage
19313 if (cu
->language
== language_cplus
19314 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
19315 && die_parent
== NULL
19317 && (tag
== DW_TAG_class_type
19318 || tag
== DW_TAG_structure_type
19319 || tag
== DW_TAG_union_type
))
19320 guess_partial_die_structure_name (this, cu
);
19322 /* GCC might emit a nameless struct or union that has a linkage
19323 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19325 && (tag
== DW_TAG_class_type
19326 || tag
== DW_TAG_interface_type
19327 || tag
== DW_TAG_structure_type
19328 || tag
== DW_TAG_union_type
)
19329 && linkage_name
!= NULL
)
19331 gdb::unique_xmalloc_ptr
<char> demangled
19332 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19333 if (demangled
!= nullptr)
19337 /* Strip any leading namespaces/classes, keep only the base name.
19338 DW_AT_name for named DIEs does not contain the prefixes. */
19339 base
= strrchr (demangled
.get (), ':');
19340 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19343 base
= demangled
.get ();
19345 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19346 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
19353 /* Process the attributes that had to be skipped in the first round. These
19354 attributes are the ones that need str_offsets_base or addr_base attributes.
19355 They could not have been processed in the first round, because at the time
19356 the values of str_offsets_base or addr_base may not have been known. */
19357 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
19358 struct attribute
*attr
)
19360 struct dwarf2_cu
*cu
= reader
->cu
;
19361 switch (attr
->form
)
19363 case DW_FORM_addrx
:
19364 case DW_FORM_GNU_addr_index
:
19365 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19368 case DW_FORM_strx1
:
19369 case DW_FORM_strx2
:
19370 case DW_FORM_strx3
:
19371 case DW_FORM_strx4
:
19372 case DW_FORM_GNU_str_index
:
19374 unsigned int str_index
= DW_UNSND (attr
);
19375 if (reader
->dwo_file
!= NULL
)
19377 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19378 DW_STRING_IS_CANONICAL (attr
) = 0;
19382 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19383 DW_STRING_IS_CANONICAL (attr
) = 0;
19388 gdb_assert_not_reached (_("Unexpected DWARF form."));
19392 /* Read an attribute value described by an attribute form. */
19394 static const gdb_byte
*
19395 read_attribute_value (const struct die_reader_specs
*reader
,
19396 struct attribute
*attr
, unsigned form
,
19397 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19398 bool *need_reprocess
)
19400 struct dwarf2_cu
*cu
= reader
->cu
;
19401 struct dwarf2_per_objfile
*dwarf2_per_objfile
19402 = cu
->per_cu
->dwarf2_per_objfile
;
19403 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19404 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19405 bfd
*abfd
= reader
->abfd
;
19406 struct comp_unit_head
*cu_header
= &cu
->header
;
19407 unsigned int bytes_read
;
19408 struct dwarf_block
*blk
;
19409 *need_reprocess
= false;
19411 attr
->form
= (enum dwarf_form
) form
;
19414 case DW_FORM_ref_addr
:
19415 if (cu
->header
.version
== 2)
19416 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19418 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19419 &cu
->header
, &bytes_read
);
19420 info_ptr
+= bytes_read
;
19422 case DW_FORM_GNU_ref_alt
:
19423 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19424 info_ptr
+= bytes_read
;
19427 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19428 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19429 info_ptr
+= bytes_read
;
19431 case DW_FORM_block2
:
19432 blk
= dwarf_alloc_block (cu
);
19433 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19435 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19436 info_ptr
+= blk
->size
;
19437 DW_BLOCK (attr
) = blk
;
19439 case DW_FORM_block4
:
19440 blk
= dwarf_alloc_block (cu
);
19441 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19443 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19444 info_ptr
+= blk
->size
;
19445 DW_BLOCK (attr
) = blk
;
19447 case DW_FORM_data2
:
19448 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19451 case DW_FORM_data4
:
19452 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19455 case DW_FORM_data8
:
19456 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19459 case DW_FORM_data16
:
19460 blk
= dwarf_alloc_block (cu
);
19462 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19464 DW_BLOCK (attr
) = blk
;
19466 case DW_FORM_sec_offset
:
19467 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19468 info_ptr
+= bytes_read
;
19470 case DW_FORM_string
:
19471 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19472 DW_STRING_IS_CANONICAL (attr
) = 0;
19473 info_ptr
+= bytes_read
;
19476 if (!cu
->per_cu
->is_dwz
)
19478 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19479 abfd
, info_ptr
, cu_header
,
19481 DW_STRING_IS_CANONICAL (attr
) = 0;
19482 info_ptr
+= bytes_read
;
19486 case DW_FORM_line_strp
:
19487 if (!cu
->per_cu
->is_dwz
)
19489 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19491 cu_header
, &bytes_read
);
19492 DW_STRING_IS_CANONICAL (attr
) = 0;
19493 info_ptr
+= bytes_read
;
19497 case DW_FORM_GNU_strp_alt
:
19499 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19500 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19503 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19505 DW_STRING_IS_CANONICAL (attr
) = 0;
19506 info_ptr
+= bytes_read
;
19509 case DW_FORM_exprloc
:
19510 case DW_FORM_block
:
19511 blk
= dwarf_alloc_block (cu
);
19512 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19513 info_ptr
+= bytes_read
;
19514 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19515 info_ptr
+= blk
->size
;
19516 DW_BLOCK (attr
) = blk
;
19518 case DW_FORM_block1
:
19519 blk
= dwarf_alloc_block (cu
);
19520 blk
->size
= read_1_byte (abfd
, info_ptr
);
19522 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19523 info_ptr
+= blk
->size
;
19524 DW_BLOCK (attr
) = blk
;
19526 case DW_FORM_data1
:
19527 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19531 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19534 case DW_FORM_flag_present
:
19535 DW_UNSND (attr
) = 1;
19537 case DW_FORM_sdata
:
19538 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19539 info_ptr
+= bytes_read
;
19541 case DW_FORM_udata
:
19542 case DW_FORM_rnglistx
:
19543 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19544 info_ptr
+= bytes_read
;
19547 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19548 + read_1_byte (abfd
, info_ptr
));
19552 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19553 + read_2_bytes (abfd
, info_ptr
));
19557 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19558 + read_4_bytes (abfd
, info_ptr
));
19562 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19563 + read_8_bytes (abfd
, info_ptr
));
19566 case DW_FORM_ref_sig8
:
19567 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19570 case DW_FORM_ref_udata
:
19571 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19572 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19573 info_ptr
+= bytes_read
;
19575 case DW_FORM_indirect
:
19576 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19577 info_ptr
+= bytes_read
;
19578 if (form
== DW_FORM_implicit_const
)
19580 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19581 info_ptr
+= bytes_read
;
19583 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19584 info_ptr
, need_reprocess
);
19586 case DW_FORM_implicit_const
:
19587 DW_SND (attr
) = implicit_const
;
19589 case DW_FORM_addrx
:
19590 case DW_FORM_GNU_addr_index
:
19591 *need_reprocess
= true;
19592 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19593 info_ptr
+= bytes_read
;
19596 case DW_FORM_strx1
:
19597 case DW_FORM_strx2
:
19598 case DW_FORM_strx3
:
19599 case DW_FORM_strx4
:
19600 case DW_FORM_GNU_str_index
:
19602 ULONGEST str_index
;
19603 if (form
== DW_FORM_strx1
)
19605 str_index
= read_1_byte (abfd
, info_ptr
);
19608 else if (form
== DW_FORM_strx2
)
19610 str_index
= read_2_bytes (abfd
, info_ptr
);
19613 else if (form
== DW_FORM_strx3
)
19615 str_index
= read_3_bytes (abfd
, info_ptr
);
19618 else if (form
== DW_FORM_strx4
)
19620 str_index
= read_4_bytes (abfd
, info_ptr
);
19625 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19626 info_ptr
+= bytes_read
;
19628 *need_reprocess
= true;
19629 DW_UNSND (attr
) = str_index
;
19633 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19634 dwarf_form_name (form
),
19635 bfd_get_filename (abfd
));
19639 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19640 attr
->form
= DW_FORM_GNU_ref_alt
;
19642 /* We have seen instances where the compiler tried to emit a byte
19643 size attribute of -1 which ended up being encoded as an unsigned
19644 0xffffffff. Although 0xffffffff is technically a valid size value,
19645 an object of this size seems pretty unlikely so we can relatively
19646 safely treat these cases as if the size attribute was invalid and
19647 treat them as zero by default. */
19648 if (attr
->name
== DW_AT_byte_size
19649 && form
== DW_FORM_data4
19650 && DW_UNSND (attr
) >= 0xffffffff)
19653 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19654 hex_string (DW_UNSND (attr
)));
19655 DW_UNSND (attr
) = 0;
19661 /* Read an attribute described by an abbreviated attribute. */
19663 static const gdb_byte
*
19664 read_attribute (const struct die_reader_specs
*reader
,
19665 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19666 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19668 attr
->name
= abbrev
->name
;
19669 return read_attribute_value (reader
, attr
, abbrev
->form
,
19670 abbrev
->implicit_const
, info_ptr
,
19675 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19676 unsigned int *bytes_read
)
19678 struct comp_unit_head
*cu_header
= &cu
->header
;
19679 CORE_ADDR retval
= 0;
19681 if (cu_header
->signed_addr_p
)
19683 switch (cu_header
->addr_size
)
19686 retval
= bfd_get_signed_16 (abfd
, buf
);
19689 retval
= bfd_get_signed_32 (abfd
, buf
);
19692 retval
= bfd_get_signed_64 (abfd
, buf
);
19695 internal_error (__FILE__
, __LINE__
,
19696 _("read_address: bad switch, signed [in module %s]"),
19697 bfd_get_filename (abfd
));
19702 switch (cu_header
->addr_size
)
19705 retval
= bfd_get_16 (abfd
, buf
);
19708 retval
= bfd_get_32 (abfd
, buf
);
19711 retval
= bfd_get_64 (abfd
, buf
);
19714 internal_error (__FILE__
, __LINE__
,
19715 _("read_address: bad switch, "
19716 "unsigned [in module %s]"),
19717 bfd_get_filename (abfd
));
19721 *bytes_read
= cu_header
->addr_size
;
19725 /* Read the initial length from a section. The (draft) DWARF 3
19726 specification allows the initial length to take up either 4 bytes
19727 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19728 bytes describe the length and all offsets will be 8 bytes in length
19731 An older, non-standard 64-bit format is also handled by this
19732 function. The older format in question stores the initial length
19733 as an 8-byte quantity without an escape value. Lengths greater
19734 than 2^32 aren't very common which means that the initial 4 bytes
19735 is almost always zero. Since a length value of zero doesn't make
19736 sense for the 32-bit format, this initial zero can be considered to
19737 be an escape value which indicates the presence of the older 64-bit
19738 format. As written, the code can't detect (old format) lengths
19739 greater than 4GB. If it becomes necessary to handle lengths
19740 somewhat larger than 4GB, we could allow other small values (such
19741 as the non-sensical values of 1, 2, and 3) to also be used as
19742 escape values indicating the presence of the old format.
19744 The value returned via bytes_read should be used to increment the
19745 relevant pointer after calling read_initial_length().
19747 [ Note: read_initial_length() and read_offset() are based on the
19748 document entitled "DWARF Debugging Information Format", revision
19749 3, draft 8, dated November 19, 2001. This document was obtained
19752 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19754 This document is only a draft and is subject to change. (So beware.)
19756 Details regarding the older, non-standard 64-bit format were
19757 determined empirically by examining 64-bit ELF files produced by
19758 the SGI toolchain on an IRIX 6.5 machine.
19760 - Kevin, July 16, 2002
19764 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19766 LONGEST length
= bfd_get_32 (abfd
, buf
);
19768 if (length
== 0xffffffff)
19770 length
= bfd_get_64 (abfd
, buf
+ 4);
19773 else if (length
== 0)
19775 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19776 length
= bfd_get_64 (abfd
, buf
);
19787 /* Cover function for read_initial_length.
19788 Returns the length of the object at BUF, and stores the size of the
19789 initial length in *BYTES_READ and stores the size that offsets will be in
19791 If the initial length size is not equivalent to that specified in
19792 CU_HEADER then issue a complaint.
19793 This is useful when reading non-comp-unit headers. */
19796 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19797 const struct comp_unit_head
*cu_header
,
19798 unsigned int *bytes_read
,
19799 unsigned int *offset_size
)
19801 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19803 gdb_assert (cu_header
->initial_length_size
== 4
19804 || cu_header
->initial_length_size
== 8
19805 || cu_header
->initial_length_size
== 12);
19807 if (cu_header
->initial_length_size
!= *bytes_read
)
19808 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19810 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19814 /* Read an offset from the data stream. The size of the offset is
19815 given by cu_header->offset_size. */
19818 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19819 const struct comp_unit_head
*cu_header
,
19820 unsigned int *bytes_read
)
19822 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19824 *bytes_read
= cu_header
->offset_size
;
19828 /* Read an offset from the data stream. */
19831 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19833 LONGEST retval
= 0;
19835 switch (offset_size
)
19838 retval
= bfd_get_32 (abfd
, buf
);
19841 retval
= bfd_get_64 (abfd
, buf
);
19844 internal_error (__FILE__
, __LINE__
,
19845 _("read_offset_1: bad switch [in module %s]"),
19846 bfd_get_filename (abfd
));
19852 static const gdb_byte
*
19853 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19855 /* If the size of a host char is 8 bits, we can return a pointer
19856 to the buffer, otherwise we have to copy the data to a buffer
19857 allocated on the temporary obstack. */
19858 gdb_assert (HOST_CHAR_BIT
== 8);
19862 static const char *
19863 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19864 unsigned int *bytes_read_ptr
)
19866 /* If the size of a host char is 8 bits, we can return a pointer
19867 to the string, otherwise we have to copy the string to a buffer
19868 allocated on the temporary obstack. */
19869 gdb_assert (HOST_CHAR_BIT
== 8);
19872 *bytes_read_ptr
= 1;
19875 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19876 return (const char *) buf
;
19879 /* Return pointer to string at section SECT offset STR_OFFSET with error
19880 reporting strings FORM_NAME and SECT_NAME. */
19882 static const char *
19883 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19884 bfd
*abfd
, LONGEST str_offset
,
19885 struct dwarf2_section_info
*sect
,
19886 const char *form_name
,
19887 const char *sect_name
)
19889 dwarf2_read_section (objfile
, sect
);
19890 if (sect
->buffer
== NULL
)
19891 error (_("%s used without %s section [in module %s]"),
19892 form_name
, sect_name
, bfd_get_filename (abfd
));
19893 if (str_offset
>= sect
->size
)
19894 error (_("%s pointing outside of %s section [in module %s]"),
19895 form_name
, sect_name
, bfd_get_filename (abfd
));
19896 gdb_assert (HOST_CHAR_BIT
== 8);
19897 if (sect
->buffer
[str_offset
] == '\0')
19899 return (const char *) (sect
->buffer
+ str_offset
);
19902 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19904 static const char *
19905 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19906 bfd
*abfd
, LONGEST str_offset
)
19908 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19910 &dwarf2_per_objfile
->str
,
19911 "DW_FORM_strp", ".debug_str");
19914 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19916 static const char *
19917 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19918 bfd
*abfd
, LONGEST str_offset
)
19920 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19922 &dwarf2_per_objfile
->line_str
,
19923 "DW_FORM_line_strp",
19924 ".debug_line_str");
19927 /* Read a string at offset STR_OFFSET in the .debug_str section from
19928 the .dwz file DWZ. Throw an error if the offset is too large. If
19929 the string consists of a single NUL byte, return NULL; otherwise
19930 return a pointer to the string. */
19932 static const char *
19933 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19934 LONGEST str_offset
)
19936 dwarf2_read_section (objfile
, &dwz
->str
);
19938 if (dwz
->str
.buffer
== NULL
)
19939 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19940 "section [in module %s]"),
19941 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19942 if (str_offset
>= dwz
->str
.size
)
19943 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19944 ".debug_str section [in module %s]"),
19945 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19946 gdb_assert (HOST_CHAR_BIT
== 8);
19947 if (dwz
->str
.buffer
[str_offset
] == '\0')
19949 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19952 /* Return pointer to string at .debug_str offset as read from BUF.
19953 BUF is assumed to be in a compilation unit described by CU_HEADER.
19954 Return *BYTES_READ_PTR count of bytes read from BUF. */
19956 static const char *
19957 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19958 const gdb_byte
*buf
,
19959 const struct comp_unit_head
*cu_header
,
19960 unsigned int *bytes_read_ptr
)
19962 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19964 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19967 /* Return pointer to string at .debug_line_str offset as read from BUF.
19968 BUF is assumed to be in a compilation unit described by CU_HEADER.
19969 Return *BYTES_READ_PTR count of bytes read from BUF. */
19971 static const char *
19972 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19973 bfd
*abfd
, const gdb_byte
*buf
,
19974 const struct comp_unit_head
*cu_header
,
19975 unsigned int *bytes_read_ptr
)
19977 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19979 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19983 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19984 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19985 ADDR_SIZE is the size of addresses from the CU header. */
19988 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19989 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
19992 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19993 bfd
*abfd
= objfile
->obfd
;
19994 const gdb_byte
*info_ptr
;
19995 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19997 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
19998 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19999 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20000 objfile_name (objfile
));
20001 if (addr_base_or_zero
+ addr_index
* addr_size
20002 >= dwarf2_per_objfile
->addr
.size
)
20003 error (_("DW_FORM_addr_index pointing outside of "
20004 ".debug_addr section [in module %s]"),
20005 objfile_name (objfile
));
20006 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
20007 + addr_base_or_zero
+ addr_index
* addr_size
);
20008 if (addr_size
== 4)
20009 return bfd_get_32 (abfd
, info_ptr
);
20011 return bfd_get_64 (abfd
, info_ptr
);
20014 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20017 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20019 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
20020 cu
->addr_base
, cu
->header
.addr_size
);
20023 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20026 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20027 unsigned int *bytes_read
)
20029 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
20030 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20032 return read_addr_index (cu
, addr_index
);
20035 /* Given an index in .debug_addr, fetch the value.
20036 NOTE: This can be called during dwarf expression evaluation,
20037 long after the debug information has been read, and thus per_cu->cu
20038 may no longer exist. */
20041 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
20042 unsigned int addr_index
)
20044 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
20045 struct dwarf2_cu
*cu
= per_cu
->cu
;
20046 gdb::optional
<ULONGEST
> addr_base
;
20049 /* We need addr_base and addr_size.
20050 If we don't have PER_CU->cu, we have to get it.
20051 Nasty, but the alternative is storing the needed info in PER_CU,
20052 which at this point doesn't seem justified: it's not clear how frequently
20053 it would get used and it would increase the size of every PER_CU.
20054 Entry points like dwarf2_per_cu_addr_size do a similar thing
20055 so we're not in uncharted territory here.
20056 Alas we need to be a bit more complicated as addr_base is contained
20059 We don't need to read the entire CU(/TU).
20060 We just need the header and top level die.
20062 IWBN to use the aging mechanism to let us lazily later discard the CU.
20063 For now we skip this optimization. */
20067 addr_base
= cu
->addr_base
;
20068 addr_size
= cu
->header
.addr_size
;
20072 cutu_reader
reader (per_cu
, NULL
, 0, 0, false);
20073 addr_base
= reader
.cu
->addr_base
;
20074 addr_size
= reader
.cu
->header
.addr_size
;
20077 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20081 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20082 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20085 static const char *
20086 read_str_index (struct dwarf2_cu
*cu
,
20087 struct dwarf2_section_info
*str_section
,
20088 struct dwarf2_section_info
*str_offsets_section
,
20089 ULONGEST str_offsets_base
, ULONGEST str_index
)
20091 struct dwarf2_per_objfile
*dwarf2_per_objfile
20092 = cu
->per_cu
->dwarf2_per_objfile
;
20093 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20094 const char *objf_name
= objfile_name (objfile
);
20095 bfd
*abfd
= objfile
->obfd
;
20096 const gdb_byte
*info_ptr
;
20097 ULONGEST str_offset
;
20098 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20100 dwarf2_read_section (objfile
, str_section
);
20101 dwarf2_read_section (objfile
, str_offsets_section
);
20102 if (str_section
->buffer
== NULL
)
20103 error (_("%s used without %s section"
20104 " in CU at offset %s [in module %s]"),
20105 form_name
, get_section_name (str_section
),
20106 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20107 if (str_offsets_section
->buffer
== NULL
)
20108 error (_("%s used without %s section"
20109 " in CU at offset %s [in module %s]"),
20110 form_name
, get_section_name (str_section
),
20111 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20112 info_ptr
= (str_offsets_section
->buffer
20114 + str_index
* cu
->header
.offset_size
);
20115 if (cu
->header
.offset_size
== 4)
20116 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20118 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20119 if (str_offset
>= str_section
->size
)
20120 error (_("Offset from %s pointing outside of"
20121 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20122 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20123 return (const char *) (str_section
->buffer
+ str_offset
);
20126 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20128 static const char *
20129 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20131 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20132 ? reader
->cu
->header
.addr_size
: 0;
20133 return read_str_index (reader
->cu
,
20134 &reader
->dwo_file
->sections
.str
,
20135 &reader
->dwo_file
->sections
.str_offsets
,
20136 str_offsets_base
, str_index
);
20139 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20141 static const char *
20142 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20144 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20145 const char *objf_name
= objfile_name (objfile
);
20146 static const char form_name
[] = "DW_FORM_GNU_str_index";
20147 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20149 if (!cu
->str_offsets_base
.has_value ())
20150 error (_("%s used in Fission stub without %s"
20151 " in CU at offset 0x%lx [in module %s]"),
20152 form_name
, str_offsets_attr_name
,
20153 (long) cu
->header
.offset_size
, objf_name
);
20155 return read_str_index (cu
,
20156 &cu
->per_cu
->dwarf2_per_objfile
->str
,
20157 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
20158 *cu
->str_offsets_base
, str_index
);
20161 /* Return the length of an LEB128 number in BUF. */
20164 leb128_size (const gdb_byte
*buf
)
20166 const gdb_byte
*begin
= buf
;
20172 if ((byte
& 128) == 0)
20173 return buf
- begin
;
20178 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20187 cu
->language
= language_c
;
20190 case DW_LANG_C_plus_plus
:
20191 case DW_LANG_C_plus_plus_11
:
20192 case DW_LANG_C_plus_plus_14
:
20193 cu
->language
= language_cplus
;
20196 cu
->language
= language_d
;
20198 case DW_LANG_Fortran77
:
20199 case DW_LANG_Fortran90
:
20200 case DW_LANG_Fortran95
:
20201 case DW_LANG_Fortran03
:
20202 case DW_LANG_Fortran08
:
20203 cu
->language
= language_fortran
;
20206 cu
->language
= language_go
;
20208 case DW_LANG_Mips_Assembler
:
20209 cu
->language
= language_asm
;
20211 case DW_LANG_Ada83
:
20212 case DW_LANG_Ada95
:
20213 cu
->language
= language_ada
;
20215 case DW_LANG_Modula2
:
20216 cu
->language
= language_m2
;
20218 case DW_LANG_Pascal83
:
20219 cu
->language
= language_pascal
;
20222 cu
->language
= language_objc
;
20225 case DW_LANG_Rust_old
:
20226 cu
->language
= language_rust
;
20228 case DW_LANG_Cobol74
:
20229 case DW_LANG_Cobol85
:
20231 cu
->language
= language_minimal
;
20234 cu
->language_defn
= language_def (cu
->language
);
20237 /* Return the named attribute or NULL if not there. */
20239 static struct attribute
*
20240 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20245 struct attribute
*spec
= NULL
;
20247 for (i
= 0; i
< die
->num_attrs
; ++i
)
20249 if (die
->attrs
[i
].name
== name
)
20250 return &die
->attrs
[i
];
20251 if (die
->attrs
[i
].name
== DW_AT_specification
20252 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20253 spec
= &die
->attrs
[i
];
20259 die
= follow_die_ref (die
, spec
, &cu
);
20265 /* Return the named attribute or NULL if not there,
20266 but do not follow DW_AT_specification, etc.
20267 This is for use in contexts where we're reading .debug_types dies.
20268 Following DW_AT_specification, DW_AT_abstract_origin will take us
20269 back up the chain, and we want to go down. */
20271 static struct attribute
*
20272 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20276 for (i
= 0; i
< die
->num_attrs
; ++i
)
20277 if (die
->attrs
[i
].name
== name
)
20278 return &die
->attrs
[i
];
20283 /* Return the string associated with a string-typed attribute, or NULL if it
20284 is either not found or is of an incorrect type. */
20286 static const char *
20287 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20289 struct attribute
*attr
;
20290 const char *str
= NULL
;
20292 attr
= dwarf2_attr (die
, name
, cu
);
20296 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20297 || attr
->form
== DW_FORM_string
20298 || attr
->form
== DW_FORM_strx
20299 || attr
->form
== DW_FORM_strx1
20300 || attr
->form
== DW_FORM_strx2
20301 || attr
->form
== DW_FORM_strx3
20302 || attr
->form
== DW_FORM_strx4
20303 || attr
->form
== DW_FORM_GNU_str_index
20304 || attr
->form
== DW_FORM_GNU_strp_alt
)
20305 str
= DW_STRING (attr
);
20307 complaint (_("string type expected for attribute %s for "
20308 "DIE at %s in module %s"),
20309 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20310 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20316 /* Return the dwo name or NULL if not present. If present, it is in either
20317 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20318 static const char *
20319 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20321 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20322 if (dwo_name
== nullptr)
20323 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20327 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20328 and holds a non-zero value. This function should only be used for
20329 DW_FORM_flag or DW_FORM_flag_present attributes. */
20332 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20334 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20336 return (attr
&& DW_UNSND (attr
));
20340 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20342 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20343 which value is non-zero. However, we have to be careful with
20344 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20345 (via dwarf2_flag_true_p) follows this attribute. So we may
20346 end up accidently finding a declaration attribute that belongs
20347 to a different DIE referenced by the specification attribute,
20348 even though the given DIE does not have a declaration attribute. */
20349 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20350 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20353 /* Return the die giving the specification for DIE, if there is
20354 one. *SPEC_CU is the CU containing DIE on input, and the CU
20355 containing the return value on output. If there is no
20356 specification, but there is an abstract origin, that is
20359 static struct die_info
*
20360 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20362 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20365 if (spec_attr
== NULL
)
20366 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20368 if (spec_attr
== NULL
)
20371 return follow_die_ref (die
, spec_attr
, spec_cu
);
20374 /* Stub for free_line_header to match void * callback types. */
20377 free_line_header_voidp (void *arg
)
20379 struct line_header
*lh
= (struct line_header
*) arg
;
20385 line_header::add_include_dir (const char *include_dir
)
20387 if (dwarf_line_debug
>= 2)
20391 new_size
= m_include_dirs
.size ();
20393 new_size
= m_include_dirs
.size () + 1;
20394 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20395 new_size
, include_dir
);
20397 m_include_dirs
.push_back (include_dir
);
20401 line_header::add_file_name (const char *name
,
20403 unsigned int mod_time
,
20404 unsigned int length
)
20406 if (dwarf_line_debug
>= 2)
20410 new_size
= file_names_size ();
20412 new_size
= file_names_size () + 1;
20413 fprintf_unfiltered (gdb_stdlog
, "Adding file %zu: %s\n",
20416 m_file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20419 /* A convenience function to find the proper .debug_line section for a CU. */
20421 static struct dwarf2_section_info
*
20422 get_debug_line_section (struct dwarf2_cu
*cu
)
20424 struct dwarf2_section_info
*section
;
20425 struct dwarf2_per_objfile
*dwarf2_per_objfile
20426 = cu
->per_cu
->dwarf2_per_objfile
;
20428 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20430 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20431 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20432 else if (cu
->per_cu
->is_dwz
)
20434 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20436 section
= &dwz
->line
;
20439 section
= &dwarf2_per_objfile
->line
;
20444 /* Read directory or file name entry format, starting with byte of
20445 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20446 entries count and the entries themselves in the described entry
20450 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20451 bfd
*abfd
, const gdb_byte
**bufp
,
20452 struct line_header
*lh
,
20453 const struct comp_unit_head
*cu_header
,
20454 void (*callback
) (struct line_header
*lh
,
20457 unsigned int mod_time
,
20458 unsigned int length
))
20460 gdb_byte format_count
, formati
;
20461 ULONGEST data_count
, datai
;
20462 const gdb_byte
*buf
= *bufp
;
20463 const gdb_byte
*format_header_data
;
20464 unsigned int bytes_read
;
20466 format_count
= read_1_byte (abfd
, buf
);
20468 format_header_data
= buf
;
20469 for (formati
= 0; formati
< format_count
; formati
++)
20471 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20473 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20477 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20479 for (datai
= 0; datai
< data_count
; datai
++)
20481 const gdb_byte
*format
= format_header_data
;
20482 struct file_entry fe
;
20484 for (formati
= 0; formati
< format_count
; formati
++)
20486 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20487 format
+= bytes_read
;
20489 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20490 format
+= bytes_read
;
20492 gdb::optional
<const char *> string
;
20493 gdb::optional
<unsigned int> uint
;
20497 case DW_FORM_string
:
20498 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20502 case DW_FORM_line_strp
:
20503 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20510 case DW_FORM_data1
:
20511 uint
.emplace (read_1_byte (abfd
, buf
));
20515 case DW_FORM_data2
:
20516 uint
.emplace (read_2_bytes (abfd
, buf
));
20520 case DW_FORM_data4
:
20521 uint
.emplace (read_4_bytes (abfd
, buf
));
20525 case DW_FORM_data8
:
20526 uint
.emplace (read_8_bytes (abfd
, buf
));
20530 case DW_FORM_data16
:
20531 /* This is used for MD5, but file_entry does not record MD5s. */
20535 case DW_FORM_udata
:
20536 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20540 case DW_FORM_block
:
20541 /* It is valid only for DW_LNCT_timestamp which is ignored by
20546 switch (content_type
)
20549 if (string
.has_value ())
20552 case DW_LNCT_directory_index
:
20553 if (uint
.has_value ())
20554 fe
.d_index
= (dir_index
) *uint
;
20556 case DW_LNCT_timestamp
:
20557 if (uint
.has_value ())
20558 fe
.mod_time
= *uint
;
20561 if (uint
.has_value ())
20567 complaint (_("Unknown format content type %s"),
20568 pulongest (content_type
));
20572 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20578 /* Read the statement program header starting at OFFSET in
20579 .debug_line, or .debug_line.dwo. Return a pointer
20580 to a struct line_header, allocated using xmalloc.
20581 Returns NULL if there is a problem reading the header, e.g., if it
20582 has a version we don't understand.
20584 NOTE: the strings in the include directory and file name tables of
20585 the returned object point into the dwarf line section buffer,
20586 and must not be freed. */
20588 static line_header_up
20589 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20591 const gdb_byte
*line_ptr
;
20592 unsigned int bytes_read
, offset_size
;
20594 const char *cur_dir
, *cur_file
;
20595 struct dwarf2_section_info
*section
;
20597 struct dwarf2_per_objfile
*dwarf2_per_objfile
20598 = cu
->per_cu
->dwarf2_per_objfile
;
20600 section
= get_debug_line_section (cu
);
20601 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20602 if (section
->buffer
== NULL
)
20604 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20605 complaint (_("missing .debug_line.dwo section"));
20607 complaint (_("missing .debug_line section"));
20611 /* We can't do this until we know the section is non-empty.
20612 Only then do we know we have such a section. */
20613 abfd
= get_section_bfd_owner (section
);
20615 /* Make sure that at least there's room for the total_length field.
20616 That could be 12 bytes long, but we're just going to fudge that. */
20617 if (to_underlying (sect_off
) + 4 >= section
->size
)
20619 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20623 line_header_up
lh (new line_header ());
20625 lh
->sect_off
= sect_off
;
20626 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20628 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20630 /* Read in the header. */
20632 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20633 &bytes_read
, &offset_size
);
20634 line_ptr
+= bytes_read
;
20636 const gdb_byte
*start_here
= line_ptr
;
20638 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20640 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20643 lh
->statement_program_end
= start_here
+ lh
->total_length
;
20644 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20646 if (lh
->version
> 5)
20648 /* This is a version we don't understand. The format could have
20649 changed in ways we don't handle properly so just punt. */
20650 complaint (_("unsupported version in .debug_line section"));
20653 if (lh
->version
>= 5)
20655 gdb_byte segment_selector_size
;
20657 /* Skip address size. */
20658 read_1_byte (abfd
, line_ptr
);
20661 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20663 if (segment_selector_size
!= 0)
20665 complaint (_("unsupported segment selector size %u "
20666 "in .debug_line section"),
20667 segment_selector_size
);
20671 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20672 line_ptr
+= offset_size
;
20673 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
20674 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20676 if (lh
->version
>= 4)
20678 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20682 lh
->maximum_ops_per_instruction
= 1;
20684 if (lh
->maximum_ops_per_instruction
== 0)
20686 lh
->maximum_ops_per_instruction
= 1;
20687 complaint (_("invalid maximum_ops_per_instruction "
20688 "in `.debug_line' section"));
20691 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20693 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20695 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20697 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20699 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20701 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20702 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20704 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20708 if (lh
->version
>= 5)
20710 /* Read directory table. */
20711 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20713 [] (struct line_header
*header
, const char *name
,
20714 dir_index d_index
, unsigned int mod_time
,
20715 unsigned int length
)
20717 header
->add_include_dir (name
);
20720 /* Read file name table. */
20721 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20723 [] (struct line_header
*header
, const char *name
,
20724 dir_index d_index
, unsigned int mod_time
,
20725 unsigned int length
)
20727 header
->add_file_name (name
, d_index
, mod_time
, length
);
20732 /* Read directory table. */
20733 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20735 line_ptr
+= bytes_read
;
20736 lh
->add_include_dir (cur_dir
);
20738 line_ptr
+= bytes_read
;
20740 /* Read file name table. */
20741 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20743 unsigned int mod_time
, length
;
20746 line_ptr
+= bytes_read
;
20747 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20748 line_ptr
+= bytes_read
;
20749 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20750 line_ptr
+= bytes_read
;
20751 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20752 line_ptr
+= bytes_read
;
20754 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20756 line_ptr
+= bytes_read
;
20759 if (line_ptr
> (section
->buffer
+ section
->size
))
20760 complaint (_("line number info header doesn't "
20761 "fit in `.debug_line' section"));
20766 /* Subroutine of dwarf_decode_lines to simplify it.
20767 Return the file name of the psymtab for the given file_entry.
20768 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20769 If space for the result is malloc'd, *NAME_HOLDER will be set.
20770 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20772 static const char *
20773 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20774 const dwarf2_psymtab
*pst
,
20775 const char *comp_dir
,
20776 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20778 const char *include_name
= fe
.name
;
20779 const char *include_name_to_compare
= include_name
;
20780 const char *pst_filename
;
20783 const char *dir_name
= fe
.include_dir (lh
);
20785 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20786 if (!IS_ABSOLUTE_PATH (include_name
)
20787 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20789 /* Avoid creating a duplicate psymtab for PST.
20790 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20791 Before we do the comparison, however, we need to account
20792 for DIR_NAME and COMP_DIR.
20793 First prepend dir_name (if non-NULL). If we still don't
20794 have an absolute path prepend comp_dir (if non-NULL).
20795 However, the directory we record in the include-file's
20796 psymtab does not contain COMP_DIR (to match the
20797 corresponding symtab(s)).
20802 bash$ gcc -g ./hello.c
20803 include_name = "hello.c"
20805 DW_AT_comp_dir = comp_dir = "/tmp"
20806 DW_AT_name = "./hello.c"
20810 if (dir_name
!= NULL
)
20812 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20813 include_name
, (char *) NULL
));
20814 include_name
= name_holder
->get ();
20815 include_name_to_compare
= include_name
;
20817 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20819 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20820 include_name
, (char *) NULL
));
20821 include_name_to_compare
= hold_compare
.get ();
20825 pst_filename
= pst
->filename
;
20826 gdb::unique_xmalloc_ptr
<char> copied_name
;
20827 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20829 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20830 pst_filename
, (char *) NULL
));
20831 pst_filename
= copied_name
.get ();
20834 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20838 return include_name
;
20841 /* State machine to track the state of the line number program. */
20843 class lnp_state_machine
20846 /* Initialize a machine state for the start of a line number
20848 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20849 bool record_lines_p
);
20851 file_entry
*current_file ()
20853 /* lh->file_names is 0-based, but the file name numbers in the
20854 statement program are 1-based. */
20855 return m_line_header
->file_name_at (m_file
);
20858 /* Record the line in the state machine. END_SEQUENCE is true if
20859 we're processing the end of a sequence. */
20860 void record_line (bool end_sequence
);
20862 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
20863 nop-out rest of the lines in this sequence. */
20864 void check_line_address (struct dwarf2_cu
*cu
,
20865 const gdb_byte
*line_ptr
,
20866 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20868 void handle_set_discriminator (unsigned int discriminator
)
20870 m_discriminator
= discriminator
;
20871 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20874 /* Handle DW_LNE_set_address. */
20875 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20878 address
+= baseaddr
;
20879 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20882 /* Handle DW_LNS_advance_pc. */
20883 void handle_advance_pc (CORE_ADDR adjust
);
20885 /* Handle a special opcode. */
20886 void handle_special_opcode (unsigned char op_code
);
20888 /* Handle DW_LNS_advance_line. */
20889 void handle_advance_line (int line_delta
)
20891 advance_line (line_delta
);
20894 /* Handle DW_LNS_set_file. */
20895 void handle_set_file (file_name_index file
);
20897 /* Handle DW_LNS_negate_stmt. */
20898 void handle_negate_stmt ()
20900 m_is_stmt
= !m_is_stmt
;
20903 /* Handle DW_LNS_const_add_pc. */
20904 void handle_const_add_pc ();
20906 /* Handle DW_LNS_fixed_advance_pc. */
20907 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20909 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20913 /* Handle DW_LNS_copy. */
20914 void handle_copy ()
20916 record_line (false);
20917 m_discriminator
= 0;
20920 /* Handle DW_LNE_end_sequence. */
20921 void handle_end_sequence ()
20923 m_currently_recording_lines
= true;
20927 /* Advance the line by LINE_DELTA. */
20928 void advance_line (int line_delta
)
20930 m_line
+= line_delta
;
20932 if (line_delta
!= 0)
20933 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20936 struct dwarf2_cu
*m_cu
;
20938 gdbarch
*m_gdbarch
;
20940 /* True if we're recording lines.
20941 Otherwise we're building partial symtabs and are just interested in
20942 finding include files mentioned by the line number program. */
20943 bool m_record_lines_p
;
20945 /* The line number header. */
20946 line_header
*m_line_header
;
20948 /* These are part of the standard DWARF line number state machine,
20949 and initialized according to the DWARF spec. */
20951 unsigned char m_op_index
= 0;
20952 /* The line table index of the current file. */
20953 file_name_index m_file
= 1;
20954 unsigned int m_line
= 1;
20956 /* These are initialized in the constructor. */
20958 CORE_ADDR m_address
;
20960 unsigned int m_discriminator
;
20962 /* Additional bits of state we need to track. */
20964 /* The last file that we called dwarf2_start_subfile for.
20965 This is only used for TLLs. */
20966 unsigned int m_last_file
= 0;
20967 /* The last file a line number was recorded for. */
20968 struct subfile
*m_last_subfile
= NULL
;
20970 /* When true, record the lines we decode. */
20971 bool m_currently_recording_lines
= false;
20973 /* The last line number that was recorded, used to coalesce
20974 consecutive entries for the same line. This can happen, for
20975 example, when discriminators are present. PR 17276. */
20976 unsigned int m_last_line
= 0;
20977 bool m_line_has_non_zero_discriminator
= false;
20981 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20983 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20984 / m_line_header
->maximum_ops_per_instruction
)
20985 * m_line_header
->minimum_instruction_length
);
20986 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20987 m_op_index
= ((m_op_index
+ adjust
)
20988 % m_line_header
->maximum_ops_per_instruction
);
20992 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20994 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20995 CORE_ADDR addr_adj
= (((m_op_index
20996 + (adj_opcode
/ m_line_header
->line_range
))
20997 / m_line_header
->maximum_ops_per_instruction
)
20998 * m_line_header
->minimum_instruction_length
);
20999 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21000 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
21001 % m_line_header
->maximum_ops_per_instruction
);
21003 int line_delta
= (m_line_header
->line_base
21004 + (adj_opcode
% m_line_header
->line_range
));
21005 advance_line (line_delta
);
21006 record_line (false);
21007 m_discriminator
= 0;
21011 lnp_state_machine::handle_set_file (file_name_index file
)
21015 const file_entry
*fe
= current_file ();
21017 dwarf2_debug_line_missing_file_complaint ();
21018 else if (m_record_lines_p
)
21020 const char *dir
= fe
->include_dir (m_line_header
);
21022 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21023 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21024 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21029 lnp_state_machine::handle_const_add_pc ()
21032 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21035 = (((m_op_index
+ adjust
)
21036 / m_line_header
->maximum_ops_per_instruction
)
21037 * m_line_header
->minimum_instruction_length
);
21039 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21040 m_op_index
= ((m_op_index
+ adjust
)
21041 % m_line_header
->maximum_ops_per_instruction
);
21044 /* Return non-zero if we should add LINE to the line number table.
21045 LINE is the line to add, LAST_LINE is the last line that was added,
21046 LAST_SUBFILE is the subfile for LAST_LINE.
21047 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21048 had a non-zero discriminator.
21050 We have to be careful in the presence of discriminators.
21051 E.g., for this line:
21053 for (i = 0; i < 100000; i++);
21055 clang can emit four line number entries for that one line,
21056 each with a different discriminator.
21057 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21059 However, we want gdb to coalesce all four entries into one.
21060 Otherwise the user could stepi into the middle of the line and
21061 gdb would get confused about whether the pc really was in the
21062 middle of the line.
21064 Things are further complicated by the fact that two consecutive
21065 line number entries for the same line is a heuristic used by gcc
21066 to denote the end of the prologue. So we can't just discard duplicate
21067 entries, we have to be selective about it. The heuristic we use is
21068 that we only collapse consecutive entries for the same line if at least
21069 one of those entries has a non-zero discriminator. PR 17276.
21071 Note: Addresses in the line number state machine can never go backwards
21072 within one sequence, thus this coalescing is ok. */
21075 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21076 unsigned int line
, unsigned int last_line
,
21077 int line_has_non_zero_discriminator
,
21078 struct subfile
*last_subfile
)
21080 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21082 if (line
!= last_line
)
21084 /* Same line for the same file that we've seen already.
21085 As a last check, for pr 17276, only record the line if the line
21086 has never had a non-zero discriminator. */
21087 if (!line_has_non_zero_discriminator
)
21092 /* Use the CU's builder to record line number LINE beginning at
21093 address ADDRESS in the line table of subfile SUBFILE. */
21096 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21097 unsigned int line
, CORE_ADDR address
,
21098 struct dwarf2_cu
*cu
)
21100 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21102 if (dwarf_line_debug
)
21104 fprintf_unfiltered (gdb_stdlog
,
21105 "Recording line %u, file %s, address %s\n",
21106 line
, lbasename (subfile
->name
),
21107 paddress (gdbarch
, address
));
21111 cu
->get_builder ()->record_line (subfile
, line
, addr
);
21114 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21115 Mark the end of a set of line number records.
21116 The arguments are the same as for dwarf_record_line_1.
21117 If SUBFILE is NULL the request is ignored. */
21120 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21121 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21123 if (subfile
== NULL
)
21126 if (dwarf_line_debug
)
21128 fprintf_unfiltered (gdb_stdlog
,
21129 "Finishing current line, file %s, address %s\n",
21130 lbasename (subfile
->name
),
21131 paddress (gdbarch
, address
));
21134 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
21138 lnp_state_machine::record_line (bool end_sequence
)
21140 if (dwarf_line_debug
)
21142 fprintf_unfiltered (gdb_stdlog
,
21143 "Processing actual line %u: file %u,"
21144 " address %s, is_stmt %u, discrim %u%s\n",
21146 paddress (m_gdbarch
, m_address
),
21147 m_is_stmt
, m_discriminator
,
21148 (end_sequence
? "\t(end sequence)" : ""));
21151 file_entry
*fe
= current_file ();
21154 dwarf2_debug_line_missing_file_complaint ();
21155 /* For now we ignore lines not starting on an instruction boundary.
21156 But not when processing end_sequence for compatibility with the
21157 previous version of the code. */
21158 else if (m_op_index
== 0 || end_sequence
)
21160 fe
->included_p
= 1;
21161 if (m_record_lines_p
21162 && (producer_is_codewarrior (m_cu
) || m_is_stmt
|| end_sequence
))
21164 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
21167 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21168 m_currently_recording_lines
? m_cu
: nullptr);
21173 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21174 m_line_has_non_zero_discriminator
,
21177 buildsym_compunit
*builder
= m_cu
->get_builder ();
21178 dwarf_record_line_1 (m_gdbarch
,
21179 builder
->get_current_subfile (),
21181 m_currently_recording_lines
? m_cu
: nullptr);
21183 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21184 m_last_line
= m_line
;
21190 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21191 line_header
*lh
, bool record_lines_p
)
21195 m_record_lines_p
= record_lines_p
;
21196 m_line_header
= lh
;
21198 m_currently_recording_lines
= true;
21200 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21201 was a line entry for it so that the backend has a chance to adjust it
21202 and also record it in case it needs it. This is currently used by MIPS
21203 code, cf. `mips_adjust_dwarf2_line'. */
21204 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21205 m_is_stmt
= lh
->default_is_stmt
;
21206 m_discriminator
= 0;
21210 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21211 const gdb_byte
*line_ptr
,
21212 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21214 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
21215 the pc range of the CU. However, we restrict the test to only ADDRESS
21216 values of zero to preserve GDB's previous behaviour which is to handle
21217 the specific case of a function being GC'd by the linker. */
21219 if (address
== 0 && address
< unrelocated_lowpc
)
21221 /* This line table is for a function which has been
21222 GCd by the linker. Ignore it. PR gdb/12528 */
21224 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21225 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21227 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21228 line_offset
, objfile_name (objfile
));
21229 m_currently_recording_lines
= false;
21230 /* Note: m_currently_recording_lines is left as false until we see
21231 DW_LNE_end_sequence. */
21235 /* Subroutine of dwarf_decode_lines to simplify it.
21236 Process the line number information in LH.
21237 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21238 program in order to set included_p for every referenced header. */
21241 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21242 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21244 const gdb_byte
*line_ptr
, *extended_end
;
21245 const gdb_byte
*line_end
;
21246 unsigned int bytes_read
, extended_len
;
21247 unsigned char op_code
, extended_op
;
21248 CORE_ADDR baseaddr
;
21249 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21250 bfd
*abfd
= objfile
->obfd
;
21251 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21252 /* True if we're recording line info (as opposed to building partial
21253 symtabs and just interested in finding include files mentioned by
21254 the line number program). */
21255 bool record_lines_p
= !decode_for_pst_p
;
21257 baseaddr
= objfile
->text_section_offset ();
21259 line_ptr
= lh
->statement_program_start
;
21260 line_end
= lh
->statement_program_end
;
21262 /* Read the statement sequences until there's nothing left. */
21263 while (line_ptr
< line_end
)
21265 /* The DWARF line number program state machine. Reset the state
21266 machine at the start of each sequence. */
21267 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21268 bool end_sequence
= false;
21270 if (record_lines_p
)
21272 /* Start a subfile for the current file of the state
21274 const file_entry
*fe
= state_machine
.current_file ();
21277 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21280 /* Decode the table. */
21281 while (line_ptr
< line_end
&& !end_sequence
)
21283 op_code
= read_1_byte (abfd
, line_ptr
);
21286 if (op_code
>= lh
->opcode_base
)
21288 /* Special opcode. */
21289 state_machine
.handle_special_opcode (op_code
);
21291 else switch (op_code
)
21293 case DW_LNS_extended_op
:
21294 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21296 line_ptr
+= bytes_read
;
21297 extended_end
= line_ptr
+ extended_len
;
21298 extended_op
= read_1_byte (abfd
, line_ptr
);
21300 switch (extended_op
)
21302 case DW_LNE_end_sequence
:
21303 state_machine
.handle_end_sequence ();
21304 end_sequence
= true;
21306 case DW_LNE_set_address
:
21309 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21310 line_ptr
+= bytes_read
;
21312 state_machine
.check_line_address (cu
, line_ptr
,
21313 lowpc
- baseaddr
, address
);
21314 state_machine
.handle_set_address (baseaddr
, address
);
21317 case DW_LNE_define_file
:
21319 const char *cur_file
;
21320 unsigned int mod_time
, length
;
21323 cur_file
= read_direct_string (abfd
, line_ptr
,
21325 line_ptr
+= bytes_read
;
21326 dindex
= (dir_index
)
21327 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21328 line_ptr
+= bytes_read
;
21330 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21331 line_ptr
+= bytes_read
;
21333 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21334 line_ptr
+= bytes_read
;
21335 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21338 case DW_LNE_set_discriminator
:
21340 /* The discriminator is not interesting to the
21341 debugger; just ignore it. We still need to
21342 check its value though:
21343 if there are consecutive entries for the same
21344 (non-prologue) line we want to coalesce them.
21347 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21348 line_ptr
+= bytes_read
;
21350 state_machine
.handle_set_discriminator (discr
);
21354 complaint (_("mangled .debug_line section"));
21357 /* Make sure that we parsed the extended op correctly. If e.g.
21358 we expected a different address size than the producer used,
21359 we may have read the wrong number of bytes. */
21360 if (line_ptr
!= extended_end
)
21362 complaint (_("mangled .debug_line section"));
21367 state_machine
.handle_copy ();
21369 case DW_LNS_advance_pc
:
21372 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21373 line_ptr
+= bytes_read
;
21375 state_machine
.handle_advance_pc (adjust
);
21378 case DW_LNS_advance_line
:
21381 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21382 line_ptr
+= bytes_read
;
21384 state_machine
.handle_advance_line (line_delta
);
21387 case DW_LNS_set_file
:
21389 file_name_index file
21390 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21392 line_ptr
+= bytes_read
;
21394 state_machine
.handle_set_file (file
);
21397 case DW_LNS_set_column
:
21398 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21399 line_ptr
+= bytes_read
;
21401 case DW_LNS_negate_stmt
:
21402 state_machine
.handle_negate_stmt ();
21404 case DW_LNS_set_basic_block
:
21406 /* Add to the address register of the state machine the
21407 address increment value corresponding to special opcode
21408 255. I.e., this value is scaled by the minimum
21409 instruction length since special opcode 255 would have
21410 scaled the increment. */
21411 case DW_LNS_const_add_pc
:
21412 state_machine
.handle_const_add_pc ();
21414 case DW_LNS_fixed_advance_pc
:
21416 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21419 state_machine
.handle_fixed_advance_pc (addr_adj
);
21424 /* Unknown standard opcode, ignore it. */
21427 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21429 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21430 line_ptr
+= bytes_read
;
21437 dwarf2_debug_line_missing_end_sequence_complaint ();
21439 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21440 in which case we still finish recording the last line). */
21441 state_machine
.record_line (true);
21445 /* Decode the Line Number Program (LNP) for the given line_header
21446 structure and CU. The actual information extracted and the type
21447 of structures created from the LNP depends on the value of PST.
21449 1. If PST is NULL, then this procedure uses the data from the program
21450 to create all necessary symbol tables, and their linetables.
21452 2. If PST is not NULL, this procedure reads the program to determine
21453 the list of files included by the unit represented by PST, and
21454 builds all the associated partial symbol tables.
21456 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21457 It is used for relative paths in the line table.
21458 NOTE: When processing partial symtabs (pst != NULL),
21459 comp_dir == pst->dirname.
21461 NOTE: It is important that psymtabs have the same file name (via strcmp)
21462 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21463 symtab we don't use it in the name of the psymtabs we create.
21464 E.g. expand_line_sal requires this when finding psymtabs to expand.
21465 A good testcase for this is mb-inline.exp.
21467 LOWPC is the lowest address in CU (or 0 if not known).
21469 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21470 for its PC<->lines mapping information. Otherwise only the filename
21471 table is read in. */
21474 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21475 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21476 CORE_ADDR lowpc
, int decode_mapping
)
21478 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21479 const int decode_for_pst_p
= (pst
!= NULL
);
21481 if (decode_mapping
)
21482 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21484 if (decode_for_pst_p
)
21486 /* Now that we're done scanning the Line Header Program, we can
21487 create the psymtab of each included file. */
21488 for (auto &file_entry
: lh
->file_names ())
21489 if (file_entry
.included_p
== 1)
21491 gdb::unique_xmalloc_ptr
<char> name_holder
;
21492 const char *include_name
=
21493 psymtab_include_file_name (lh
, file_entry
, pst
,
21494 comp_dir
, &name_holder
);
21495 if (include_name
!= NULL
)
21496 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21501 /* Make sure a symtab is created for every file, even files
21502 which contain only variables (i.e. no code with associated
21504 buildsym_compunit
*builder
= cu
->get_builder ();
21505 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21507 for (auto &fe
: lh
->file_names ())
21509 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21510 if (builder
->get_current_subfile ()->symtab
== NULL
)
21512 builder
->get_current_subfile ()->symtab
21513 = allocate_symtab (cust
,
21514 builder
->get_current_subfile ()->name
);
21516 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21521 /* Start a subfile for DWARF. FILENAME is the name of the file and
21522 DIRNAME the name of the source directory which contains FILENAME
21523 or NULL if not known.
21524 This routine tries to keep line numbers from identical absolute and
21525 relative file names in a common subfile.
21527 Using the `list' example from the GDB testsuite, which resides in
21528 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21529 of /srcdir/list0.c yields the following debugging information for list0.c:
21531 DW_AT_name: /srcdir/list0.c
21532 DW_AT_comp_dir: /compdir
21533 files.files[0].name: list0.h
21534 files.files[0].dir: /srcdir
21535 files.files[1].name: list0.c
21536 files.files[1].dir: /srcdir
21538 The line number information for list0.c has to end up in a single
21539 subfile, so that `break /srcdir/list0.c:1' works as expected.
21540 start_subfile will ensure that this happens provided that we pass the
21541 concatenation of files.files[1].dir and files.files[1].name as the
21545 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21546 const char *dirname
)
21548 gdb::unique_xmalloc_ptr
<char> copy
;
21550 /* In order not to lose the line information directory,
21551 we concatenate it to the filename when it makes sense.
21552 Note that the Dwarf3 standard says (speaking of filenames in line
21553 information): ``The directory index is ignored for file names
21554 that represent full path names''. Thus ignoring dirname in the
21555 `else' branch below isn't an issue. */
21557 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21559 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21560 filename
= copy
.get ();
21563 cu
->get_builder ()->start_subfile (filename
);
21566 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21567 buildsym_compunit constructor. */
21569 struct compunit_symtab
*
21570 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21573 gdb_assert (m_builder
== nullptr);
21575 m_builder
.reset (new struct buildsym_compunit
21576 (per_cu
->dwarf2_per_objfile
->objfile
,
21577 name
, comp_dir
, language
, low_pc
));
21579 list_in_scope
= get_builder ()->get_file_symbols ();
21581 get_builder ()->record_debugformat ("DWARF 2");
21582 get_builder ()->record_producer (producer
);
21584 processing_has_namespace_info
= false;
21586 return get_builder ()->get_compunit_symtab ();
21590 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21591 struct dwarf2_cu
*cu
)
21593 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21594 struct comp_unit_head
*cu_header
= &cu
->header
;
21596 /* NOTE drow/2003-01-30: There used to be a comment and some special
21597 code here to turn a symbol with DW_AT_external and a
21598 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21599 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21600 with some versions of binutils) where shared libraries could have
21601 relocations against symbols in their debug information - the
21602 minimal symbol would have the right address, but the debug info
21603 would not. It's no longer necessary, because we will explicitly
21604 apply relocations when we read in the debug information now. */
21606 /* A DW_AT_location attribute with no contents indicates that a
21607 variable has been optimized away. */
21608 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21610 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21614 /* Handle one degenerate form of location expression specially, to
21615 preserve GDB's previous behavior when section offsets are
21616 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21617 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21619 if (attr_form_is_block (attr
)
21620 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21621 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21622 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21623 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21624 && (DW_BLOCK (attr
)->size
21625 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21627 unsigned int dummy
;
21629 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21630 SET_SYMBOL_VALUE_ADDRESS (sym
,
21631 read_address (objfile
->obfd
,
21632 DW_BLOCK (attr
)->data
+ 1,
21635 SET_SYMBOL_VALUE_ADDRESS
21636 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21638 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21639 fixup_symbol_section (sym
, objfile
);
21640 SET_SYMBOL_VALUE_ADDRESS
21642 SYMBOL_VALUE_ADDRESS (sym
)
21643 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
21647 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21648 expression evaluator, and use LOC_COMPUTED only when necessary
21649 (i.e. when the value of a register or memory location is
21650 referenced, or a thread-local block, etc.). Then again, it might
21651 not be worthwhile. I'm assuming that it isn't unless performance
21652 or memory numbers show me otherwise. */
21654 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21656 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21657 cu
->has_loclist
= true;
21660 /* Given a pointer to a DWARF information entry, figure out if we need
21661 to make a symbol table entry for it, and if so, create a new entry
21662 and return a pointer to it.
21663 If TYPE is NULL, determine symbol type from the die, otherwise
21664 used the passed type.
21665 If SPACE is not NULL, use it to hold the new symbol. If it is
21666 NULL, allocate a new symbol on the objfile's obstack. */
21668 static struct symbol
*
21669 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21670 struct symbol
*space
)
21672 struct dwarf2_per_objfile
*dwarf2_per_objfile
21673 = cu
->per_cu
->dwarf2_per_objfile
;
21674 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21675 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21676 struct symbol
*sym
= NULL
;
21678 struct attribute
*attr
= NULL
;
21679 struct attribute
*attr2
= NULL
;
21680 CORE_ADDR baseaddr
;
21681 struct pending
**list_to_add
= NULL
;
21683 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21685 baseaddr
= objfile
->text_section_offset ();
21687 name
= dwarf2_name (die
, cu
);
21690 const char *linkagename
;
21691 int suppress_add
= 0;
21696 sym
= allocate_symbol (objfile
);
21697 OBJSTAT (objfile
, n_syms
++);
21699 /* Cache this symbol's name and the name's demangled form (if any). */
21700 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21701 linkagename
= dwarf2_physname (name
, die
, cu
);
21702 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
21704 /* Fortran does not have mangling standard and the mangling does differ
21705 between gfortran, iFort etc. */
21706 if (cu
->language
== language_fortran
21707 && symbol_get_demangled_name (sym
) == NULL
)
21708 symbol_set_demangled_name (sym
,
21709 dwarf2_full_name (name
, die
, cu
),
21712 /* Default assumptions.
21713 Use the passed type or decode it from the die. */
21714 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21715 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21717 SYMBOL_TYPE (sym
) = type
;
21719 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21720 attr
= dwarf2_attr (die
,
21721 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21723 if (attr
!= nullptr)
21725 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21728 attr
= dwarf2_attr (die
,
21729 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21731 if (attr
!= nullptr)
21733 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21734 struct file_entry
*fe
;
21736 if (cu
->line_header
!= NULL
)
21737 fe
= cu
->line_header
->file_name_at (file_index
);
21742 complaint (_("file index out of range"));
21744 symbol_set_symtab (sym
, fe
->symtab
);
21750 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21751 if (attr
!= nullptr)
21755 addr
= attr_value_as_address (attr
);
21756 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21757 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21759 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21760 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21761 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21762 add_symbol_to_list (sym
, cu
->list_in_scope
);
21764 case DW_TAG_subprogram
:
21765 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21767 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21768 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21769 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21770 || cu
->language
== language_ada
21771 || cu
->language
== language_fortran
)
21773 /* Subprograms marked external are stored as a global symbol.
21774 Ada and Fortran subprograms, whether marked external or
21775 not, are always stored as a global symbol, because we want
21776 to be able to access them globally. For instance, we want
21777 to be able to break on a nested subprogram without having
21778 to specify the context. */
21779 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21783 list_to_add
= cu
->list_in_scope
;
21786 case DW_TAG_inlined_subroutine
:
21787 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21789 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21790 SYMBOL_INLINED (sym
) = 1;
21791 list_to_add
= cu
->list_in_scope
;
21793 case DW_TAG_template_value_param
:
21795 /* Fall through. */
21796 case DW_TAG_constant
:
21797 case DW_TAG_variable
:
21798 case DW_TAG_member
:
21799 /* Compilation with minimal debug info may result in
21800 variables with missing type entries. Change the
21801 misleading `void' type to something sensible. */
21802 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21803 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21805 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21806 /* In the case of DW_TAG_member, we should only be called for
21807 static const members. */
21808 if (die
->tag
== DW_TAG_member
)
21810 /* dwarf2_add_field uses die_is_declaration,
21811 so we do the same. */
21812 gdb_assert (die_is_declaration (die
, cu
));
21815 if (attr
!= nullptr)
21817 dwarf2_const_value (attr
, sym
, cu
);
21818 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21821 if (attr2
&& (DW_UNSND (attr2
) != 0))
21822 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21824 list_to_add
= cu
->list_in_scope
;
21828 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21829 if (attr
!= nullptr)
21831 var_decode_location (attr
, sym
, cu
);
21832 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21834 /* Fortran explicitly imports any global symbols to the local
21835 scope by DW_TAG_common_block. */
21836 if (cu
->language
== language_fortran
&& die
->parent
21837 && die
->parent
->tag
== DW_TAG_common_block
)
21840 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21841 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21842 && !dwarf2_per_objfile
->has_section_at_zero
)
21844 /* When a static variable is eliminated by the linker,
21845 the corresponding debug information is not stripped
21846 out, but the variable address is set to null;
21847 do not add such variables into symbol table. */
21849 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21851 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21852 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21853 && dwarf2_per_objfile
->can_copy
)
21855 /* A global static variable might be subject to
21856 copy relocation. We first check for a local
21857 minsym, though, because maybe the symbol was
21858 marked hidden, in which case this would not
21860 bound_minimal_symbol found
21861 = (lookup_minimal_symbol_linkage
21862 (sym
->linkage_name (), objfile
));
21863 if (found
.minsym
!= nullptr)
21864 sym
->maybe_copied
= 1;
21867 /* A variable with DW_AT_external is never static,
21868 but it may be block-scoped. */
21870 = ((cu
->list_in_scope
21871 == cu
->get_builder ()->get_file_symbols ())
21872 ? cu
->get_builder ()->get_global_symbols ()
21873 : cu
->list_in_scope
);
21876 list_to_add
= cu
->list_in_scope
;
21880 /* We do not know the address of this symbol.
21881 If it is an external symbol and we have type information
21882 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21883 The address of the variable will then be determined from
21884 the minimal symbol table whenever the variable is
21886 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21888 /* Fortran explicitly imports any global symbols to the local
21889 scope by DW_TAG_common_block. */
21890 if (cu
->language
== language_fortran
&& die
->parent
21891 && die
->parent
->tag
== DW_TAG_common_block
)
21893 /* SYMBOL_CLASS doesn't matter here because
21894 read_common_block is going to reset it. */
21896 list_to_add
= cu
->list_in_scope
;
21898 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21899 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21901 /* A variable with DW_AT_external is never static, but it
21902 may be block-scoped. */
21904 = ((cu
->list_in_scope
21905 == cu
->get_builder ()->get_file_symbols ())
21906 ? cu
->get_builder ()->get_global_symbols ()
21907 : cu
->list_in_scope
);
21909 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21911 else if (!die_is_declaration (die
, cu
))
21913 /* Use the default LOC_OPTIMIZED_OUT class. */
21914 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21916 list_to_add
= cu
->list_in_scope
;
21920 case DW_TAG_formal_parameter
:
21922 /* If we are inside a function, mark this as an argument. If
21923 not, we might be looking at an argument to an inlined function
21924 when we do not have enough information to show inlined frames;
21925 pretend it's a local variable in that case so that the user can
21927 struct context_stack
*curr
21928 = cu
->get_builder ()->get_current_context_stack ();
21929 if (curr
!= nullptr && curr
->name
!= nullptr)
21930 SYMBOL_IS_ARGUMENT (sym
) = 1;
21931 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21932 if (attr
!= nullptr)
21934 var_decode_location (attr
, sym
, cu
);
21936 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21937 if (attr
!= nullptr)
21939 dwarf2_const_value (attr
, sym
, cu
);
21942 list_to_add
= cu
->list_in_scope
;
21945 case DW_TAG_unspecified_parameters
:
21946 /* From varargs functions; gdb doesn't seem to have any
21947 interest in this information, so just ignore it for now.
21950 case DW_TAG_template_type_param
:
21952 /* Fall through. */
21953 case DW_TAG_class_type
:
21954 case DW_TAG_interface_type
:
21955 case DW_TAG_structure_type
:
21956 case DW_TAG_union_type
:
21957 case DW_TAG_set_type
:
21958 case DW_TAG_enumeration_type
:
21959 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21960 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21963 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21964 really ever be static objects: otherwise, if you try
21965 to, say, break of a class's method and you're in a file
21966 which doesn't mention that class, it won't work unless
21967 the check for all static symbols in lookup_symbol_aux
21968 saves you. See the OtherFileClass tests in
21969 gdb.c++/namespace.exp. */
21973 buildsym_compunit
*builder
= cu
->get_builder ();
21975 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21976 && cu
->language
== language_cplus
21977 ? builder
->get_global_symbols ()
21978 : cu
->list_in_scope
);
21980 /* The semantics of C++ state that "struct foo {
21981 ... }" also defines a typedef for "foo". */
21982 if (cu
->language
== language_cplus
21983 || cu
->language
== language_ada
21984 || cu
->language
== language_d
21985 || cu
->language
== language_rust
)
21987 /* The symbol's name is already allocated along
21988 with this objfile, so we don't need to
21989 duplicate it for the type. */
21990 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21991 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
21996 case DW_TAG_typedef
:
21997 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21998 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21999 list_to_add
= cu
->list_in_scope
;
22001 case DW_TAG_base_type
:
22002 case DW_TAG_subrange_type
:
22003 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22004 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22005 list_to_add
= cu
->list_in_scope
;
22007 case DW_TAG_enumerator
:
22008 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22009 if (attr
!= nullptr)
22011 dwarf2_const_value (attr
, sym
, cu
);
22014 /* NOTE: carlton/2003-11-10: See comment above in the
22015 DW_TAG_class_type, etc. block. */
22018 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22019 && cu
->language
== language_cplus
22020 ? cu
->get_builder ()->get_global_symbols ()
22021 : cu
->list_in_scope
);
22024 case DW_TAG_imported_declaration
:
22025 case DW_TAG_namespace
:
22026 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22027 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22029 case DW_TAG_module
:
22030 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22031 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22032 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22034 case DW_TAG_common_block
:
22035 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22036 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22037 add_symbol_to_list (sym
, cu
->list_in_scope
);
22040 /* Not a tag we recognize. Hopefully we aren't processing
22041 trash data, but since we must specifically ignore things
22042 we don't recognize, there is nothing else we should do at
22044 complaint (_("unsupported tag: '%s'"),
22045 dwarf_tag_name (die
->tag
));
22051 sym
->hash_next
= objfile
->template_symbols
;
22052 objfile
->template_symbols
= sym
;
22053 list_to_add
= NULL
;
22056 if (list_to_add
!= NULL
)
22057 add_symbol_to_list (sym
, list_to_add
);
22059 /* For the benefit of old versions of GCC, check for anonymous
22060 namespaces based on the demangled name. */
22061 if (!cu
->processing_has_namespace_info
22062 && cu
->language
== language_cplus
)
22063 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22068 /* Given an attr with a DW_FORM_dataN value in host byte order,
22069 zero-extend it as appropriate for the symbol's type. The DWARF
22070 standard (v4) is not entirely clear about the meaning of using
22071 DW_FORM_dataN for a constant with a signed type, where the type is
22072 wider than the data. The conclusion of a discussion on the DWARF
22073 list was that this is unspecified. We choose to always zero-extend
22074 because that is the interpretation long in use by GCC. */
22077 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22078 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22080 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22081 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22082 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22083 LONGEST l
= DW_UNSND (attr
);
22085 if (bits
< sizeof (*value
) * 8)
22087 l
&= ((LONGEST
) 1 << bits
) - 1;
22090 else if (bits
== sizeof (*value
) * 8)
22094 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22095 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22102 /* Read a constant value from an attribute. Either set *VALUE, or if
22103 the value does not fit in *VALUE, set *BYTES - either already
22104 allocated on the objfile obstack, or newly allocated on OBSTACK,
22105 or, set *BATON, if we translated the constant to a location
22109 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22110 const char *name
, struct obstack
*obstack
,
22111 struct dwarf2_cu
*cu
,
22112 LONGEST
*value
, const gdb_byte
**bytes
,
22113 struct dwarf2_locexpr_baton
**baton
)
22115 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22116 struct comp_unit_head
*cu_header
= &cu
->header
;
22117 struct dwarf_block
*blk
;
22118 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22119 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22125 switch (attr
->form
)
22128 case DW_FORM_addrx
:
22129 case DW_FORM_GNU_addr_index
:
22133 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22134 dwarf2_const_value_length_mismatch_complaint (name
,
22135 cu_header
->addr_size
,
22136 TYPE_LENGTH (type
));
22137 /* Symbols of this form are reasonably rare, so we just
22138 piggyback on the existing location code rather than writing
22139 a new implementation of symbol_computed_ops. */
22140 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22141 (*baton
)->per_cu
= cu
->per_cu
;
22142 gdb_assert ((*baton
)->per_cu
);
22144 (*baton
)->size
= 2 + cu_header
->addr_size
;
22145 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22146 (*baton
)->data
= data
;
22148 data
[0] = DW_OP_addr
;
22149 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22150 byte_order
, DW_ADDR (attr
));
22151 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22154 case DW_FORM_string
:
22157 case DW_FORM_GNU_str_index
:
22158 case DW_FORM_GNU_strp_alt
:
22159 /* DW_STRING is already allocated on the objfile obstack, point
22161 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22163 case DW_FORM_block1
:
22164 case DW_FORM_block2
:
22165 case DW_FORM_block4
:
22166 case DW_FORM_block
:
22167 case DW_FORM_exprloc
:
22168 case DW_FORM_data16
:
22169 blk
= DW_BLOCK (attr
);
22170 if (TYPE_LENGTH (type
) != blk
->size
)
22171 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22172 TYPE_LENGTH (type
));
22173 *bytes
= blk
->data
;
22176 /* The DW_AT_const_value attributes are supposed to carry the
22177 symbol's value "represented as it would be on the target
22178 architecture." By the time we get here, it's already been
22179 converted to host endianness, so we just need to sign- or
22180 zero-extend it as appropriate. */
22181 case DW_FORM_data1
:
22182 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22184 case DW_FORM_data2
:
22185 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22187 case DW_FORM_data4
:
22188 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22190 case DW_FORM_data8
:
22191 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22194 case DW_FORM_sdata
:
22195 case DW_FORM_implicit_const
:
22196 *value
= DW_SND (attr
);
22199 case DW_FORM_udata
:
22200 *value
= DW_UNSND (attr
);
22204 complaint (_("unsupported const value attribute form: '%s'"),
22205 dwarf_form_name (attr
->form
));
22212 /* Copy constant value from an attribute to a symbol. */
22215 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22216 struct dwarf2_cu
*cu
)
22218 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22220 const gdb_byte
*bytes
;
22221 struct dwarf2_locexpr_baton
*baton
;
22223 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22224 sym
->print_name (),
22225 &objfile
->objfile_obstack
, cu
,
22226 &value
, &bytes
, &baton
);
22230 SYMBOL_LOCATION_BATON (sym
) = baton
;
22231 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22233 else if (bytes
!= NULL
)
22235 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22236 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22240 SYMBOL_VALUE (sym
) = value
;
22241 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22245 /* Return the type of the die in question using its DW_AT_type attribute. */
22247 static struct type
*
22248 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22250 struct attribute
*type_attr
;
22252 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22255 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22256 /* A missing DW_AT_type represents a void type. */
22257 return objfile_type (objfile
)->builtin_void
;
22260 return lookup_die_type (die
, type_attr
, cu
);
22263 /* True iff CU's producer generates GNAT Ada auxiliary information
22264 that allows to find parallel types through that information instead
22265 of having to do expensive parallel lookups by type name. */
22268 need_gnat_info (struct dwarf2_cu
*cu
)
22270 /* Assume that the Ada compiler was GNAT, which always produces
22271 the auxiliary information. */
22272 return (cu
->language
== language_ada
);
22275 /* Return the auxiliary type of the die in question using its
22276 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22277 attribute is not present. */
22279 static struct type
*
22280 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22282 struct attribute
*type_attr
;
22284 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22288 return lookup_die_type (die
, type_attr
, cu
);
22291 /* If DIE has a descriptive_type attribute, then set the TYPE's
22292 descriptive type accordingly. */
22295 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22296 struct dwarf2_cu
*cu
)
22298 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22300 if (descriptive_type
)
22302 ALLOCATE_GNAT_AUX_TYPE (type
);
22303 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22307 /* Return the containing type of the die in question using its
22308 DW_AT_containing_type attribute. */
22310 static struct type
*
22311 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22313 struct attribute
*type_attr
;
22314 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22316 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22318 error (_("Dwarf Error: Problem turning containing type into gdb type "
22319 "[in module %s]"), objfile_name (objfile
));
22321 return lookup_die_type (die
, type_attr
, cu
);
22324 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22326 static struct type
*
22327 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22329 struct dwarf2_per_objfile
*dwarf2_per_objfile
22330 = cu
->per_cu
->dwarf2_per_objfile
;
22331 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22334 std::string message
22335 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22336 objfile_name (objfile
),
22337 sect_offset_str (cu
->header
.sect_off
),
22338 sect_offset_str (die
->sect_off
));
22339 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22341 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22344 /* Look up the type of DIE in CU using its type attribute ATTR.
22345 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22346 DW_AT_containing_type.
22347 If there is no type substitute an error marker. */
22349 static struct type
*
22350 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22351 struct dwarf2_cu
*cu
)
22353 struct dwarf2_per_objfile
*dwarf2_per_objfile
22354 = cu
->per_cu
->dwarf2_per_objfile
;
22355 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22356 struct type
*this_type
;
22358 gdb_assert (attr
->name
== DW_AT_type
22359 || attr
->name
== DW_AT_GNAT_descriptive_type
22360 || attr
->name
== DW_AT_containing_type
);
22362 /* First see if we have it cached. */
22364 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22366 struct dwarf2_per_cu_data
*per_cu
;
22367 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22369 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22370 dwarf2_per_objfile
);
22371 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22373 else if (attr_form_is_ref (attr
))
22375 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22377 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22379 else if (attr
->form
== DW_FORM_ref_sig8
)
22381 ULONGEST signature
= DW_SIGNATURE (attr
);
22383 return get_signatured_type (die
, signature
, cu
);
22387 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22388 " at %s [in module %s]"),
22389 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22390 objfile_name (objfile
));
22391 return build_error_marker_type (cu
, die
);
22394 /* If not cached we need to read it in. */
22396 if (this_type
== NULL
)
22398 struct die_info
*type_die
= NULL
;
22399 struct dwarf2_cu
*type_cu
= cu
;
22401 if (attr_form_is_ref (attr
))
22402 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22403 if (type_die
== NULL
)
22404 return build_error_marker_type (cu
, die
);
22405 /* If we find the type now, it's probably because the type came
22406 from an inter-CU reference and the type's CU got expanded before
22408 this_type
= read_type_die (type_die
, type_cu
);
22411 /* If we still don't have a type use an error marker. */
22413 if (this_type
== NULL
)
22414 return build_error_marker_type (cu
, die
);
22419 /* Return the type in DIE, CU.
22420 Returns NULL for invalid types.
22422 This first does a lookup in die_type_hash,
22423 and only reads the die in if necessary.
22425 NOTE: This can be called when reading in partial or full symbols. */
22427 static struct type
*
22428 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22430 struct type
*this_type
;
22432 this_type
= get_die_type (die
, cu
);
22436 return read_type_die_1 (die
, cu
);
22439 /* Read the type in DIE, CU.
22440 Returns NULL for invalid types. */
22442 static struct type
*
22443 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22445 struct type
*this_type
= NULL
;
22449 case DW_TAG_class_type
:
22450 case DW_TAG_interface_type
:
22451 case DW_TAG_structure_type
:
22452 case DW_TAG_union_type
:
22453 this_type
= read_structure_type (die
, cu
);
22455 case DW_TAG_enumeration_type
:
22456 this_type
= read_enumeration_type (die
, cu
);
22458 case DW_TAG_subprogram
:
22459 case DW_TAG_subroutine_type
:
22460 case DW_TAG_inlined_subroutine
:
22461 this_type
= read_subroutine_type (die
, cu
);
22463 case DW_TAG_array_type
:
22464 this_type
= read_array_type (die
, cu
);
22466 case DW_TAG_set_type
:
22467 this_type
= read_set_type (die
, cu
);
22469 case DW_TAG_pointer_type
:
22470 this_type
= read_tag_pointer_type (die
, cu
);
22472 case DW_TAG_ptr_to_member_type
:
22473 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22475 case DW_TAG_reference_type
:
22476 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22478 case DW_TAG_rvalue_reference_type
:
22479 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22481 case DW_TAG_const_type
:
22482 this_type
= read_tag_const_type (die
, cu
);
22484 case DW_TAG_volatile_type
:
22485 this_type
= read_tag_volatile_type (die
, cu
);
22487 case DW_TAG_restrict_type
:
22488 this_type
= read_tag_restrict_type (die
, cu
);
22490 case DW_TAG_string_type
:
22491 this_type
= read_tag_string_type (die
, cu
);
22493 case DW_TAG_typedef
:
22494 this_type
= read_typedef (die
, cu
);
22496 case DW_TAG_subrange_type
:
22497 this_type
= read_subrange_type (die
, cu
);
22499 case DW_TAG_base_type
:
22500 this_type
= read_base_type (die
, cu
);
22502 case DW_TAG_unspecified_type
:
22503 this_type
= read_unspecified_type (die
, cu
);
22505 case DW_TAG_namespace
:
22506 this_type
= read_namespace_type (die
, cu
);
22508 case DW_TAG_module
:
22509 this_type
= read_module_type (die
, cu
);
22511 case DW_TAG_atomic_type
:
22512 this_type
= read_tag_atomic_type (die
, cu
);
22515 complaint (_("unexpected tag in read_type_die: '%s'"),
22516 dwarf_tag_name (die
->tag
));
22523 /* See if we can figure out if the class lives in a namespace. We do
22524 this by looking for a member function; its demangled name will
22525 contain namespace info, if there is any.
22526 Return the computed name or NULL.
22527 Space for the result is allocated on the objfile's obstack.
22528 This is the full-die version of guess_partial_die_structure_name.
22529 In this case we know DIE has no useful parent. */
22531 static const char *
22532 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22534 struct die_info
*spec_die
;
22535 struct dwarf2_cu
*spec_cu
;
22536 struct die_info
*child
;
22537 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22540 spec_die
= die_specification (die
, &spec_cu
);
22541 if (spec_die
!= NULL
)
22547 for (child
= die
->child
;
22549 child
= child
->sibling
)
22551 if (child
->tag
== DW_TAG_subprogram
)
22553 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22555 if (linkage_name
!= NULL
)
22557 gdb::unique_xmalloc_ptr
<char> actual_name
22558 (language_class_name_from_physname (cu
->language_defn
,
22560 const char *name
= NULL
;
22562 if (actual_name
!= NULL
)
22564 const char *die_name
= dwarf2_name (die
, cu
);
22566 if (die_name
!= NULL
22567 && strcmp (die_name
, actual_name
.get ()) != 0)
22569 /* Strip off the class name from the full name.
22570 We want the prefix. */
22571 int die_name_len
= strlen (die_name
);
22572 int actual_name_len
= strlen (actual_name
.get ());
22573 const char *ptr
= actual_name
.get ();
22575 /* Test for '::' as a sanity check. */
22576 if (actual_name_len
> die_name_len
+ 2
22577 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22578 name
= obstack_strndup (
22579 &objfile
->per_bfd
->storage_obstack
,
22580 ptr
, actual_name_len
- die_name_len
- 2);
22591 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22592 prefix part in such case. See
22593 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22595 static const char *
22596 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22598 struct attribute
*attr
;
22601 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22602 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22605 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22608 attr
= dw2_linkage_name_attr (die
, cu
);
22609 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22612 /* dwarf2_name had to be already called. */
22613 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22615 /* Strip the base name, keep any leading namespaces/classes. */
22616 base
= strrchr (DW_STRING (attr
), ':');
22617 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22620 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22621 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22623 &base
[-1] - DW_STRING (attr
));
22626 /* Return the name of the namespace/class that DIE is defined within,
22627 or "" if we can't tell. The caller should not xfree the result.
22629 For example, if we're within the method foo() in the following
22639 then determine_prefix on foo's die will return "N::C". */
22641 static const char *
22642 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22644 struct dwarf2_per_objfile
*dwarf2_per_objfile
22645 = cu
->per_cu
->dwarf2_per_objfile
;
22646 struct die_info
*parent
, *spec_die
;
22647 struct dwarf2_cu
*spec_cu
;
22648 struct type
*parent_type
;
22649 const char *retval
;
22651 if (cu
->language
!= language_cplus
22652 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22653 && cu
->language
!= language_rust
)
22656 retval
= anonymous_struct_prefix (die
, cu
);
22660 /* We have to be careful in the presence of DW_AT_specification.
22661 For example, with GCC 3.4, given the code
22665 // Definition of N::foo.
22669 then we'll have a tree of DIEs like this:
22671 1: DW_TAG_compile_unit
22672 2: DW_TAG_namespace // N
22673 3: DW_TAG_subprogram // declaration of N::foo
22674 4: DW_TAG_subprogram // definition of N::foo
22675 DW_AT_specification // refers to die #3
22677 Thus, when processing die #4, we have to pretend that we're in
22678 the context of its DW_AT_specification, namely the contex of die
22681 spec_die
= die_specification (die
, &spec_cu
);
22682 if (spec_die
== NULL
)
22683 parent
= die
->parent
;
22686 parent
= spec_die
->parent
;
22690 if (parent
== NULL
)
22692 else if (parent
->building_fullname
)
22695 const char *parent_name
;
22697 /* It has been seen on RealView 2.2 built binaries,
22698 DW_TAG_template_type_param types actually _defined_ as
22699 children of the parent class:
22702 template class <class Enum> Class{};
22703 Class<enum E> class_e;
22705 1: DW_TAG_class_type (Class)
22706 2: DW_TAG_enumeration_type (E)
22707 3: DW_TAG_enumerator (enum1:0)
22708 3: DW_TAG_enumerator (enum2:1)
22710 2: DW_TAG_template_type_param
22711 DW_AT_type DW_FORM_ref_udata (E)
22713 Besides being broken debug info, it can put GDB into an
22714 infinite loop. Consider:
22716 When we're building the full name for Class<E>, we'll start
22717 at Class, and go look over its template type parameters,
22718 finding E. We'll then try to build the full name of E, and
22719 reach here. We're now trying to build the full name of E,
22720 and look over the parent DIE for containing scope. In the
22721 broken case, if we followed the parent DIE of E, we'd again
22722 find Class, and once again go look at its template type
22723 arguments, etc., etc. Simply don't consider such parent die
22724 as source-level parent of this die (it can't be, the language
22725 doesn't allow it), and break the loop here. */
22726 name
= dwarf2_name (die
, cu
);
22727 parent_name
= dwarf2_name (parent
, cu
);
22728 complaint (_("template param type '%s' defined within parent '%s'"),
22729 name
? name
: "<unknown>",
22730 parent_name
? parent_name
: "<unknown>");
22734 switch (parent
->tag
)
22736 case DW_TAG_namespace
:
22737 parent_type
= read_type_die (parent
, cu
);
22738 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22739 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22740 Work around this problem here. */
22741 if (cu
->language
== language_cplus
22742 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22744 /* We give a name to even anonymous namespaces. */
22745 return TYPE_NAME (parent_type
);
22746 case DW_TAG_class_type
:
22747 case DW_TAG_interface_type
:
22748 case DW_TAG_structure_type
:
22749 case DW_TAG_union_type
:
22750 case DW_TAG_module
:
22751 parent_type
= read_type_die (parent
, cu
);
22752 if (TYPE_NAME (parent_type
) != NULL
)
22753 return TYPE_NAME (parent_type
);
22755 /* An anonymous structure is only allowed non-static data
22756 members; no typedefs, no member functions, et cetera.
22757 So it does not need a prefix. */
22759 case DW_TAG_compile_unit
:
22760 case DW_TAG_partial_unit
:
22761 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22762 if (cu
->language
== language_cplus
22763 && !dwarf2_per_objfile
->types
.empty ()
22764 && die
->child
!= NULL
22765 && (die
->tag
== DW_TAG_class_type
22766 || die
->tag
== DW_TAG_structure_type
22767 || die
->tag
== DW_TAG_union_type
))
22769 const char *name
= guess_full_die_structure_name (die
, cu
);
22774 case DW_TAG_subprogram
:
22775 /* Nested subroutines in Fortran get a prefix with the name
22776 of the parent's subroutine. */
22777 if (cu
->language
== language_fortran
)
22779 if ((die
->tag
== DW_TAG_subprogram
)
22780 && (dwarf2_name (parent
, cu
) != NULL
))
22781 return dwarf2_name (parent
, cu
);
22783 return determine_prefix (parent
, cu
);
22784 case DW_TAG_enumeration_type
:
22785 parent_type
= read_type_die (parent
, cu
);
22786 if (TYPE_DECLARED_CLASS (parent_type
))
22788 if (TYPE_NAME (parent_type
) != NULL
)
22789 return TYPE_NAME (parent_type
);
22792 /* Fall through. */
22794 return determine_prefix (parent
, cu
);
22798 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22799 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22800 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22801 an obconcat, otherwise allocate storage for the result. The CU argument is
22802 used to determine the language and hence, the appropriate separator. */
22804 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22807 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22808 int physname
, struct dwarf2_cu
*cu
)
22810 const char *lead
= "";
22813 if (suffix
== NULL
|| suffix
[0] == '\0'
22814 || prefix
== NULL
|| prefix
[0] == '\0')
22816 else if (cu
->language
== language_d
)
22818 /* For D, the 'main' function could be defined in any module, but it
22819 should never be prefixed. */
22820 if (strcmp (suffix
, "D main") == 0)
22828 else if (cu
->language
== language_fortran
&& physname
)
22830 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22831 DW_AT_MIPS_linkage_name is preferred and used instead. */
22839 if (prefix
== NULL
)
22841 if (suffix
== NULL
)
22848 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22850 strcpy (retval
, lead
);
22851 strcat (retval
, prefix
);
22852 strcat (retval
, sep
);
22853 strcat (retval
, suffix
);
22858 /* We have an obstack. */
22859 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22863 /* Return sibling of die, NULL if no sibling. */
22865 static struct die_info
*
22866 sibling_die (struct die_info
*die
)
22868 return die
->sibling
;
22871 /* Get name of a die, return NULL if not found. */
22873 static const char *
22874 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22875 struct obstack
*obstack
)
22877 if (name
&& cu
->language
== language_cplus
)
22879 std::string canon_name
= cp_canonicalize_string (name
);
22881 if (!canon_name
.empty ())
22883 if (canon_name
!= name
)
22884 name
= obstack_strdup (obstack
, canon_name
);
22891 /* Get name of a die, return NULL if not found.
22892 Anonymous namespaces are converted to their magic string. */
22894 static const char *
22895 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22897 struct attribute
*attr
;
22898 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22900 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22901 if ((!attr
|| !DW_STRING (attr
))
22902 && die
->tag
!= DW_TAG_namespace
22903 && die
->tag
!= DW_TAG_class_type
22904 && die
->tag
!= DW_TAG_interface_type
22905 && die
->tag
!= DW_TAG_structure_type
22906 && die
->tag
!= DW_TAG_union_type
)
22911 case DW_TAG_compile_unit
:
22912 case DW_TAG_partial_unit
:
22913 /* Compilation units have a DW_AT_name that is a filename, not
22914 a source language identifier. */
22915 case DW_TAG_enumeration_type
:
22916 case DW_TAG_enumerator
:
22917 /* These tags always have simple identifiers already; no need
22918 to canonicalize them. */
22919 return DW_STRING (attr
);
22921 case DW_TAG_namespace
:
22922 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22923 return DW_STRING (attr
);
22924 return CP_ANONYMOUS_NAMESPACE_STR
;
22926 case DW_TAG_class_type
:
22927 case DW_TAG_interface_type
:
22928 case DW_TAG_structure_type
:
22929 case DW_TAG_union_type
:
22930 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22931 structures or unions. These were of the form "._%d" in GCC 4.1,
22932 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22933 and GCC 4.4. We work around this problem by ignoring these. */
22934 if (attr
&& DW_STRING (attr
)
22935 && (startswith (DW_STRING (attr
), "._")
22936 || startswith (DW_STRING (attr
), "<anonymous")))
22939 /* GCC might emit a nameless typedef that has a linkage name. See
22940 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22941 if (!attr
|| DW_STRING (attr
) == NULL
)
22943 attr
= dw2_linkage_name_attr (die
, cu
);
22944 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22947 /* Avoid demangling DW_STRING (attr) the second time on a second
22948 call for the same DIE. */
22949 if (!DW_STRING_IS_CANONICAL (attr
))
22951 gdb::unique_xmalloc_ptr
<char> demangled
22952 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
22956 /* FIXME: we already did this for the partial symbol... */
22958 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
22960 DW_STRING_IS_CANONICAL (attr
) = 1;
22962 /* Strip any leading namespaces/classes, keep only the base name.
22963 DW_AT_name for named DIEs does not contain the prefixes. */
22964 base
= strrchr (DW_STRING (attr
), ':');
22965 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22968 return DW_STRING (attr
);
22977 if (!DW_STRING_IS_CANONICAL (attr
))
22980 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22981 &objfile
->per_bfd
->storage_obstack
);
22982 DW_STRING_IS_CANONICAL (attr
) = 1;
22984 return DW_STRING (attr
);
22987 /* Return the die that this die in an extension of, or NULL if there
22988 is none. *EXT_CU is the CU containing DIE on input, and the CU
22989 containing the return value on output. */
22991 static struct die_info
*
22992 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22994 struct attribute
*attr
;
22996 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23000 return follow_die_ref (die
, attr
, ext_cu
);
23003 /* A convenience function that returns an "unknown" DWARF name,
23004 including the value of V. STR is the name of the entity being
23005 printed, e.g., "TAG". */
23007 static const char *
23008 dwarf_unknown (const char *str
, unsigned v
)
23010 char *cell
= get_print_cell ();
23011 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
23015 /* Convert a DIE tag into its string name. */
23017 static const char *
23018 dwarf_tag_name (unsigned tag
)
23020 const char *name
= get_DW_TAG_name (tag
);
23023 return dwarf_unknown ("TAG", tag
);
23028 /* Convert a DWARF attribute code into its string name. */
23030 static const char *
23031 dwarf_attr_name (unsigned attr
)
23035 #ifdef MIPS /* collides with DW_AT_HP_block_index */
23036 if (attr
== DW_AT_MIPS_fde
)
23037 return "DW_AT_MIPS_fde";
23039 if (attr
== DW_AT_HP_block_index
)
23040 return "DW_AT_HP_block_index";
23043 name
= get_DW_AT_name (attr
);
23046 return dwarf_unknown ("AT", attr
);
23051 /* Convert a unit type to corresponding DW_UT name. */
23053 static const char *
23054 dwarf_unit_type_name (int unit_type
) {
23058 return "DW_UT_compile (0x01)";
23060 return "DW_UT_type (0x02)";
23062 return "DW_UT_partial (0x03)";
23064 return "DW_UT_skeleton (0x04)";
23066 return "DW_UT_split_compile (0x05)";
23068 return "DW_UT_split_type (0x06)";
23070 return "DW_UT_lo_user (0x80)";
23072 return "DW_UT_hi_user (0xff)";
23078 /* Convert a DWARF value form code into its string name. */
23080 static const char *
23081 dwarf_form_name (unsigned form
)
23083 const char *name
= get_DW_FORM_name (form
);
23086 return dwarf_unknown ("FORM", form
);
23091 static const char *
23092 dwarf_bool_name (unsigned mybool
)
23100 /* Convert a DWARF type code into its string name. */
23102 static const char *
23103 dwarf_type_encoding_name (unsigned enc
)
23105 const char *name
= get_DW_ATE_name (enc
);
23108 return dwarf_unknown ("ATE", enc
);
23114 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23118 print_spaces (indent
, f
);
23119 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23120 dwarf_tag_name (die
->tag
), die
->abbrev
,
23121 sect_offset_str (die
->sect_off
));
23123 if (die
->parent
!= NULL
)
23125 print_spaces (indent
, f
);
23126 fprintf_unfiltered (f
, " parent at offset: %s\n",
23127 sect_offset_str (die
->parent
->sect_off
));
23130 print_spaces (indent
, f
);
23131 fprintf_unfiltered (f
, " has children: %s\n",
23132 dwarf_bool_name (die
->child
!= NULL
));
23134 print_spaces (indent
, f
);
23135 fprintf_unfiltered (f
, " attributes:\n");
23137 for (i
= 0; i
< die
->num_attrs
; ++i
)
23139 print_spaces (indent
, f
);
23140 fprintf_unfiltered (f
, " %s (%s) ",
23141 dwarf_attr_name (die
->attrs
[i
].name
),
23142 dwarf_form_name (die
->attrs
[i
].form
));
23144 switch (die
->attrs
[i
].form
)
23147 case DW_FORM_addrx
:
23148 case DW_FORM_GNU_addr_index
:
23149 fprintf_unfiltered (f
, "address: ");
23150 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23152 case DW_FORM_block2
:
23153 case DW_FORM_block4
:
23154 case DW_FORM_block
:
23155 case DW_FORM_block1
:
23156 fprintf_unfiltered (f
, "block: size %s",
23157 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23159 case DW_FORM_exprloc
:
23160 fprintf_unfiltered (f
, "expression: size %s",
23161 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23163 case DW_FORM_data16
:
23164 fprintf_unfiltered (f
, "constant of 16 bytes");
23166 case DW_FORM_ref_addr
:
23167 fprintf_unfiltered (f
, "ref address: ");
23168 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23170 case DW_FORM_GNU_ref_alt
:
23171 fprintf_unfiltered (f
, "alt ref address: ");
23172 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23178 case DW_FORM_ref_udata
:
23179 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23180 (long) (DW_UNSND (&die
->attrs
[i
])));
23182 case DW_FORM_data1
:
23183 case DW_FORM_data2
:
23184 case DW_FORM_data4
:
23185 case DW_FORM_data8
:
23186 case DW_FORM_udata
:
23187 case DW_FORM_sdata
:
23188 fprintf_unfiltered (f
, "constant: %s",
23189 pulongest (DW_UNSND (&die
->attrs
[i
])));
23191 case DW_FORM_sec_offset
:
23192 fprintf_unfiltered (f
, "section offset: %s",
23193 pulongest (DW_UNSND (&die
->attrs
[i
])));
23195 case DW_FORM_ref_sig8
:
23196 fprintf_unfiltered (f
, "signature: %s",
23197 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23199 case DW_FORM_string
:
23201 case DW_FORM_line_strp
:
23203 case DW_FORM_GNU_str_index
:
23204 case DW_FORM_GNU_strp_alt
:
23205 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23206 DW_STRING (&die
->attrs
[i
])
23207 ? DW_STRING (&die
->attrs
[i
]) : "",
23208 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23211 if (DW_UNSND (&die
->attrs
[i
]))
23212 fprintf_unfiltered (f
, "flag: TRUE");
23214 fprintf_unfiltered (f
, "flag: FALSE");
23216 case DW_FORM_flag_present
:
23217 fprintf_unfiltered (f
, "flag: TRUE");
23219 case DW_FORM_indirect
:
23220 /* The reader will have reduced the indirect form to
23221 the "base form" so this form should not occur. */
23222 fprintf_unfiltered (f
,
23223 "unexpected attribute form: DW_FORM_indirect");
23225 case DW_FORM_implicit_const
:
23226 fprintf_unfiltered (f
, "constant: %s",
23227 plongest (DW_SND (&die
->attrs
[i
])));
23230 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23231 die
->attrs
[i
].form
);
23234 fprintf_unfiltered (f
, "\n");
23239 dump_die_for_error (struct die_info
*die
)
23241 dump_die_shallow (gdb_stderr
, 0, die
);
23245 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23247 int indent
= level
* 4;
23249 gdb_assert (die
!= NULL
);
23251 if (level
>= max_level
)
23254 dump_die_shallow (f
, indent
, die
);
23256 if (die
->child
!= NULL
)
23258 print_spaces (indent
, f
);
23259 fprintf_unfiltered (f
, " Children:");
23260 if (level
+ 1 < max_level
)
23262 fprintf_unfiltered (f
, "\n");
23263 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23267 fprintf_unfiltered (f
,
23268 " [not printed, max nesting level reached]\n");
23272 if (die
->sibling
!= NULL
&& level
> 0)
23274 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23278 /* This is called from the pdie macro in gdbinit.in.
23279 It's not static so gcc will keep a copy callable from gdb. */
23282 dump_die (struct die_info
*die
, int max_level
)
23284 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23288 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23292 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23293 to_underlying (die
->sect_off
),
23299 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23303 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23305 if (attr_form_is_ref (attr
))
23306 return (sect_offset
) DW_UNSND (attr
);
23308 complaint (_("unsupported die ref attribute form: '%s'"),
23309 dwarf_form_name (attr
->form
));
23313 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23314 * the value held by the attribute is not constant. */
23317 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23319 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23320 return DW_SND (attr
);
23321 else if (attr
->form
== DW_FORM_udata
23322 || attr
->form
== DW_FORM_data1
23323 || attr
->form
== DW_FORM_data2
23324 || attr
->form
== DW_FORM_data4
23325 || attr
->form
== DW_FORM_data8
)
23326 return DW_UNSND (attr
);
23329 /* For DW_FORM_data16 see attr_form_is_constant. */
23330 complaint (_("Attribute value is not a constant (%s)"),
23331 dwarf_form_name (attr
->form
));
23332 return default_value
;
23336 /* Follow reference or signature attribute ATTR of SRC_DIE.
23337 On entry *REF_CU is the CU of SRC_DIE.
23338 On exit *REF_CU is the CU of the result. */
23340 static struct die_info
*
23341 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23342 struct dwarf2_cu
**ref_cu
)
23344 struct die_info
*die
;
23346 if (attr_form_is_ref (attr
))
23347 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23348 else if (attr
->form
== DW_FORM_ref_sig8
)
23349 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23352 dump_die_for_error (src_die
);
23353 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23354 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23360 /* Follow reference OFFSET.
23361 On entry *REF_CU is the CU of the source die referencing OFFSET.
23362 On exit *REF_CU is the CU of the result.
23363 Returns NULL if OFFSET is invalid. */
23365 static struct die_info
*
23366 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23367 struct dwarf2_cu
**ref_cu
)
23369 struct die_info temp_die
;
23370 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23371 struct dwarf2_per_objfile
*dwarf2_per_objfile
23372 = cu
->per_cu
->dwarf2_per_objfile
;
23374 gdb_assert (cu
->per_cu
!= NULL
);
23378 if (cu
->per_cu
->is_debug_types
)
23380 /* .debug_types CUs cannot reference anything outside their CU.
23381 If they need to, they have to reference a signatured type via
23382 DW_FORM_ref_sig8. */
23383 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23386 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23387 || !offset_in_cu_p (&cu
->header
, sect_off
))
23389 struct dwarf2_per_cu_data
*per_cu
;
23391 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23392 dwarf2_per_objfile
);
23394 /* If necessary, add it to the queue and load its DIEs. */
23395 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23396 load_full_comp_unit (per_cu
, false, cu
->language
);
23398 target_cu
= per_cu
->cu
;
23400 else if (cu
->dies
== NULL
)
23402 /* We're loading full DIEs during partial symbol reading. */
23403 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23404 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23407 *ref_cu
= target_cu
;
23408 temp_die
.sect_off
= sect_off
;
23410 if (target_cu
!= cu
)
23411 target_cu
->ancestor
= cu
;
23413 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23415 to_underlying (sect_off
));
23418 /* Follow reference attribute ATTR of SRC_DIE.
23419 On entry *REF_CU is the CU of SRC_DIE.
23420 On exit *REF_CU is the CU of the result. */
23422 static struct die_info
*
23423 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23424 struct dwarf2_cu
**ref_cu
)
23426 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23427 struct dwarf2_cu
*cu
= *ref_cu
;
23428 struct die_info
*die
;
23430 die
= follow_die_offset (sect_off
,
23431 (attr
->form
== DW_FORM_GNU_ref_alt
23432 || cu
->per_cu
->is_dwz
),
23435 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23436 "at %s [in module %s]"),
23437 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23438 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23443 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23444 Returned value is intended for DW_OP_call*. Returned
23445 dwarf2_locexpr_baton->data has lifetime of
23446 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23448 struct dwarf2_locexpr_baton
23449 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23450 struct dwarf2_per_cu_data
*per_cu
,
23451 CORE_ADDR (*get_frame_pc
) (void *baton
),
23452 void *baton
, bool resolve_abstract_p
)
23454 struct dwarf2_cu
*cu
;
23455 struct die_info
*die
;
23456 struct attribute
*attr
;
23457 struct dwarf2_locexpr_baton retval
;
23458 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23459 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23461 if (per_cu
->cu
== NULL
)
23462 load_cu (per_cu
, false);
23466 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23467 Instead just throw an error, not much else we can do. */
23468 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23469 sect_offset_str (sect_off
), objfile_name (objfile
));
23472 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23474 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23475 sect_offset_str (sect_off
), objfile_name (objfile
));
23477 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23478 if (!attr
&& resolve_abstract_p
23479 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23480 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23482 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23483 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23484 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23486 for (const auto &cand_off
23487 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23489 struct dwarf2_cu
*cand_cu
= cu
;
23490 struct die_info
*cand
23491 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23494 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23497 CORE_ADDR pc_low
, pc_high
;
23498 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23499 if (pc_low
== ((CORE_ADDR
) -1))
23501 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23502 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23503 if (!(pc_low
<= pc
&& pc
< pc_high
))
23507 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23514 /* DWARF: "If there is no such attribute, then there is no effect.".
23515 DATA is ignored if SIZE is 0. */
23517 retval
.data
= NULL
;
23520 else if (attr_form_is_section_offset (attr
))
23522 struct dwarf2_loclist_baton loclist_baton
;
23523 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23526 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23528 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23530 retval
.size
= size
;
23534 if (!attr_form_is_block (attr
))
23535 error (_("Dwarf Error: DIE at %s referenced in module %s "
23536 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23537 sect_offset_str (sect_off
), objfile_name (objfile
));
23539 retval
.data
= DW_BLOCK (attr
)->data
;
23540 retval
.size
= DW_BLOCK (attr
)->size
;
23542 retval
.per_cu
= cu
->per_cu
;
23544 age_cached_comp_units (dwarf2_per_objfile
);
23549 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23552 struct dwarf2_locexpr_baton
23553 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23554 struct dwarf2_per_cu_data
*per_cu
,
23555 CORE_ADDR (*get_frame_pc
) (void *baton
),
23558 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23560 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23563 /* Write a constant of a given type as target-ordered bytes into
23566 static const gdb_byte
*
23567 write_constant_as_bytes (struct obstack
*obstack
,
23568 enum bfd_endian byte_order
,
23575 *len
= TYPE_LENGTH (type
);
23576 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23577 store_unsigned_integer (result
, *len
, byte_order
, value
);
23582 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23583 pointer to the constant bytes and set LEN to the length of the
23584 data. If memory is needed, allocate it on OBSTACK. If the DIE
23585 does not have a DW_AT_const_value, return NULL. */
23588 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23589 struct dwarf2_per_cu_data
*per_cu
,
23590 struct obstack
*obstack
,
23593 struct dwarf2_cu
*cu
;
23594 struct die_info
*die
;
23595 struct attribute
*attr
;
23596 const gdb_byte
*result
= NULL
;
23599 enum bfd_endian byte_order
;
23600 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23602 if (per_cu
->cu
== NULL
)
23603 load_cu (per_cu
, false);
23607 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23608 Instead just throw an error, not much else we can do. */
23609 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23610 sect_offset_str (sect_off
), objfile_name (objfile
));
23613 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23615 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23616 sect_offset_str (sect_off
), objfile_name (objfile
));
23618 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23622 byte_order
= (bfd_big_endian (objfile
->obfd
)
23623 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23625 switch (attr
->form
)
23628 case DW_FORM_addrx
:
23629 case DW_FORM_GNU_addr_index
:
23633 *len
= cu
->header
.addr_size
;
23634 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23635 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23639 case DW_FORM_string
:
23642 case DW_FORM_GNU_str_index
:
23643 case DW_FORM_GNU_strp_alt
:
23644 /* DW_STRING is already allocated on the objfile obstack, point
23646 result
= (const gdb_byte
*) DW_STRING (attr
);
23647 *len
= strlen (DW_STRING (attr
));
23649 case DW_FORM_block1
:
23650 case DW_FORM_block2
:
23651 case DW_FORM_block4
:
23652 case DW_FORM_block
:
23653 case DW_FORM_exprloc
:
23654 case DW_FORM_data16
:
23655 result
= DW_BLOCK (attr
)->data
;
23656 *len
= DW_BLOCK (attr
)->size
;
23659 /* The DW_AT_const_value attributes are supposed to carry the
23660 symbol's value "represented as it would be on the target
23661 architecture." By the time we get here, it's already been
23662 converted to host endianness, so we just need to sign- or
23663 zero-extend it as appropriate. */
23664 case DW_FORM_data1
:
23665 type
= die_type (die
, cu
);
23666 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23667 if (result
== NULL
)
23668 result
= write_constant_as_bytes (obstack
, byte_order
,
23671 case DW_FORM_data2
:
23672 type
= die_type (die
, cu
);
23673 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23674 if (result
== NULL
)
23675 result
= write_constant_as_bytes (obstack
, byte_order
,
23678 case DW_FORM_data4
:
23679 type
= die_type (die
, cu
);
23680 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23681 if (result
== NULL
)
23682 result
= write_constant_as_bytes (obstack
, byte_order
,
23685 case DW_FORM_data8
:
23686 type
= die_type (die
, cu
);
23687 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23688 if (result
== NULL
)
23689 result
= write_constant_as_bytes (obstack
, byte_order
,
23693 case DW_FORM_sdata
:
23694 case DW_FORM_implicit_const
:
23695 type
= die_type (die
, cu
);
23696 result
= write_constant_as_bytes (obstack
, byte_order
,
23697 type
, DW_SND (attr
), len
);
23700 case DW_FORM_udata
:
23701 type
= die_type (die
, cu
);
23702 result
= write_constant_as_bytes (obstack
, byte_order
,
23703 type
, DW_UNSND (attr
), len
);
23707 complaint (_("unsupported const value attribute form: '%s'"),
23708 dwarf_form_name (attr
->form
));
23715 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23716 valid type for this die is found. */
23719 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23720 struct dwarf2_per_cu_data
*per_cu
)
23722 struct dwarf2_cu
*cu
;
23723 struct die_info
*die
;
23725 if (per_cu
->cu
== NULL
)
23726 load_cu (per_cu
, false);
23731 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23735 return die_type (die
, cu
);
23738 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23742 dwarf2_get_die_type (cu_offset die_offset
,
23743 struct dwarf2_per_cu_data
*per_cu
)
23745 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23746 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23749 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23750 On entry *REF_CU is the CU of SRC_DIE.
23751 On exit *REF_CU is the CU of the result.
23752 Returns NULL if the referenced DIE isn't found. */
23754 static struct die_info
*
23755 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23756 struct dwarf2_cu
**ref_cu
)
23758 struct die_info temp_die
;
23759 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23760 struct die_info
*die
;
23762 /* While it might be nice to assert sig_type->type == NULL here,
23763 we can get here for DW_AT_imported_declaration where we need
23764 the DIE not the type. */
23766 /* If necessary, add it to the queue and load its DIEs. */
23768 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23769 read_signatured_type (sig_type
);
23771 sig_cu
= sig_type
->per_cu
.cu
;
23772 gdb_assert (sig_cu
!= NULL
);
23773 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23774 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23775 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23776 to_underlying (temp_die
.sect_off
));
23779 struct dwarf2_per_objfile
*dwarf2_per_objfile
23780 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23782 /* For .gdb_index version 7 keep track of included TUs.
23783 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23784 if (dwarf2_per_objfile
->index_table
!= NULL
23785 && dwarf2_per_objfile
->index_table
->version
<= 7)
23787 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23792 sig_cu
->ancestor
= cu
;
23800 /* Follow signatured type referenced by ATTR in SRC_DIE.
23801 On entry *REF_CU is the CU of SRC_DIE.
23802 On exit *REF_CU is the CU of the result.
23803 The result is the DIE of the type.
23804 If the referenced type cannot be found an error is thrown. */
23806 static struct die_info
*
23807 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23808 struct dwarf2_cu
**ref_cu
)
23810 ULONGEST signature
= DW_SIGNATURE (attr
);
23811 struct signatured_type
*sig_type
;
23812 struct die_info
*die
;
23814 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23816 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23817 /* sig_type will be NULL if the signatured type is missing from
23819 if (sig_type
== NULL
)
23821 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23822 " from DIE at %s [in module %s]"),
23823 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23824 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23827 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23830 dump_die_for_error (src_die
);
23831 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23832 " from DIE at %s [in module %s]"),
23833 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23834 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23840 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23841 reading in and processing the type unit if necessary. */
23843 static struct type
*
23844 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23845 struct dwarf2_cu
*cu
)
23847 struct dwarf2_per_objfile
*dwarf2_per_objfile
23848 = cu
->per_cu
->dwarf2_per_objfile
;
23849 struct signatured_type
*sig_type
;
23850 struct dwarf2_cu
*type_cu
;
23851 struct die_info
*type_die
;
23854 sig_type
= lookup_signatured_type (cu
, signature
);
23855 /* sig_type will be NULL if the signatured type is missing from
23857 if (sig_type
== NULL
)
23859 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23860 " from DIE at %s [in module %s]"),
23861 hex_string (signature
), sect_offset_str (die
->sect_off
),
23862 objfile_name (dwarf2_per_objfile
->objfile
));
23863 return build_error_marker_type (cu
, die
);
23866 /* If we already know the type we're done. */
23867 if (sig_type
->type
!= NULL
)
23868 return sig_type
->type
;
23871 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23872 if (type_die
!= NULL
)
23874 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23875 is created. This is important, for example, because for c++ classes
23876 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23877 type
= read_type_die (type_die
, type_cu
);
23880 complaint (_("Dwarf Error: Cannot build signatured type %s"
23881 " referenced from DIE at %s [in module %s]"),
23882 hex_string (signature
), sect_offset_str (die
->sect_off
),
23883 objfile_name (dwarf2_per_objfile
->objfile
));
23884 type
= build_error_marker_type (cu
, die
);
23889 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23890 " from DIE at %s [in module %s]"),
23891 hex_string (signature
), sect_offset_str (die
->sect_off
),
23892 objfile_name (dwarf2_per_objfile
->objfile
));
23893 type
= build_error_marker_type (cu
, die
);
23895 sig_type
->type
= type
;
23900 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23901 reading in and processing the type unit if necessary. */
23903 static struct type
*
23904 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23905 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23907 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23908 if (attr_form_is_ref (attr
))
23910 struct dwarf2_cu
*type_cu
= cu
;
23911 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23913 return read_type_die (type_die
, type_cu
);
23915 else if (attr
->form
== DW_FORM_ref_sig8
)
23917 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23921 struct dwarf2_per_objfile
*dwarf2_per_objfile
23922 = cu
->per_cu
->dwarf2_per_objfile
;
23924 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23925 " at %s [in module %s]"),
23926 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23927 objfile_name (dwarf2_per_objfile
->objfile
));
23928 return build_error_marker_type (cu
, die
);
23932 /* Load the DIEs associated with type unit PER_CU into memory. */
23935 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23937 struct signatured_type
*sig_type
;
23939 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23940 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23942 /* We have the per_cu, but we need the signatured_type.
23943 Fortunately this is an easy translation. */
23944 gdb_assert (per_cu
->is_debug_types
);
23945 sig_type
= (struct signatured_type
*) per_cu
;
23947 gdb_assert (per_cu
->cu
== NULL
);
23949 read_signatured_type (sig_type
);
23951 gdb_assert (per_cu
->cu
!= NULL
);
23954 /* Read in a signatured type and build its CU and DIEs.
23955 If the type is a stub for the real type in a DWO file,
23956 read in the real type from the DWO file as well. */
23959 read_signatured_type (struct signatured_type
*sig_type
)
23961 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23963 gdb_assert (per_cu
->is_debug_types
);
23964 gdb_assert (per_cu
->cu
== NULL
);
23966 cutu_reader
reader (per_cu
, NULL
, 0, 1, false);
23968 if (!reader
.dummy_p
)
23970 struct dwarf2_cu
*cu
= reader
.cu
;
23971 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23973 gdb_assert (cu
->die_hash
== NULL
);
23975 htab_create_alloc_ex (cu
->header
.length
/ 12,
23979 &cu
->comp_unit_obstack
,
23980 hashtab_obstack_allocate
,
23981 dummy_obstack_deallocate
);
23983 if (reader
.has_children
)
23984 reader
.comp_unit_die
->child
23985 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23986 reader
.comp_unit_die
);
23987 cu
->dies
= reader
.comp_unit_die
;
23988 /* comp_unit_die is not stored in die_hash, no need. */
23990 /* We try not to read any attributes in this function, because
23991 not all CUs needed for references have been loaded yet, and
23992 symbol table processing isn't initialized. But we have to
23993 set the CU language, or we won't be able to build types
23994 correctly. Similarly, if we do not read the producer, we can
23995 not apply producer-specific interpretation. */
23996 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23999 sig_type
->per_cu
.tu_read
= 1;
24002 /* Decode simple location descriptions.
24003 Given a pointer to a dwarf block that defines a location, compute
24004 the location and return the value.
24006 NOTE drow/2003-11-18: This function is called in two situations
24007 now: for the address of static or global variables (partial symbols
24008 only) and for offsets into structures which are expected to be
24009 (more or less) constant. The partial symbol case should go away,
24010 and only the constant case should remain. That will let this
24011 function complain more accurately. A few special modes are allowed
24012 without complaint for global variables (for instance, global
24013 register values and thread-local values).
24015 A location description containing no operations indicates that the
24016 object is optimized out. The return value is 0 for that case.
24017 FIXME drow/2003-11-16: No callers check for this case any more; soon all
24018 callers will only want a very basic result and this can become a
24021 Note that stack[0] is unused except as a default error return. */
24024 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
24026 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
24028 size_t size
= blk
->size
;
24029 const gdb_byte
*data
= blk
->data
;
24030 CORE_ADDR stack
[64];
24032 unsigned int bytes_read
, unsnd
;
24038 stack
[++stacki
] = 0;
24077 stack
[++stacki
] = op
- DW_OP_lit0
;
24112 stack
[++stacki
] = op
- DW_OP_reg0
;
24114 dwarf2_complex_location_expr_complaint ();
24118 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24120 stack
[++stacki
] = unsnd
;
24122 dwarf2_complex_location_expr_complaint ();
24126 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24131 case DW_OP_const1u
:
24132 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24136 case DW_OP_const1s
:
24137 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24141 case DW_OP_const2u
:
24142 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24146 case DW_OP_const2s
:
24147 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24151 case DW_OP_const4u
:
24152 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24156 case DW_OP_const4s
:
24157 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24161 case DW_OP_const8u
:
24162 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24167 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24173 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24178 stack
[stacki
+ 1] = stack
[stacki
];
24183 stack
[stacki
- 1] += stack
[stacki
];
24187 case DW_OP_plus_uconst
:
24188 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24194 stack
[stacki
- 1] -= stack
[stacki
];
24199 /* If we're not the last op, then we definitely can't encode
24200 this using GDB's address_class enum. This is valid for partial
24201 global symbols, although the variable's address will be bogus
24204 dwarf2_complex_location_expr_complaint ();
24207 case DW_OP_GNU_push_tls_address
:
24208 case DW_OP_form_tls_address
:
24209 /* The top of the stack has the offset from the beginning
24210 of the thread control block at which the variable is located. */
24211 /* Nothing should follow this operator, so the top of stack would
24213 /* This is valid for partial global symbols, but the variable's
24214 address will be bogus in the psymtab. Make it always at least
24215 non-zero to not look as a variable garbage collected by linker
24216 which have DW_OP_addr 0. */
24218 dwarf2_complex_location_expr_complaint ();
24222 case DW_OP_GNU_uninit
:
24226 case DW_OP_GNU_addr_index
:
24227 case DW_OP_GNU_const_index
:
24228 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24235 const char *name
= get_DW_OP_name (op
);
24238 complaint (_("unsupported stack op: '%s'"),
24241 complaint (_("unsupported stack op: '%02x'"),
24245 return (stack
[stacki
]);
24248 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24249 outside of the allocated space. Also enforce minimum>0. */
24250 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24252 complaint (_("location description stack overflow"));
24258 complaint (_("location description stack underflow"));
24262 return (stack
[stacki
]);
24265 /* memory allocation interface */
24267 static struct dwarf_block
*
24268 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24270 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24273 static struct die_info
*
24274 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24276 struct die_info
*die
;
24277 size_t size
= sizeof (struct die_info
);
24280 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24282 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24283 memset (die
, 0, sizeof (struct die_info
));
24288 /* Macro support. */
24290 /* Return file name relative to the compilation directory of file number I in
24291 *LH's file name table. The result is allocated using xmalloc; the caller is
24292 responsible for freeing it. */
24295 file_file_name (int file
, struct line_header
*lh
)
24297 /* Is the file number a valid index into the line header's file name
24298 table? Remember that file numbers start with one, not zero. */
24299 if (lh
->is_valid_file_index (file
))
24301 const file_entry
*fe
= lh
->file_name_at (file
);
24303 if (!IS_ABSOLUTE_PATH (fe
->name
))
24305 const char *dir
= fe
->include_dir (lh
);
24307 return concat (dir
, SLASH_STRING
, fe
->name
, (char *) NULL
);
24309 return xstrdup (fe
->name
);
24313 /* The compiler produced a bogus file number. We can at least
24314 record the macro definitions made in the file, even if we
24315 won't be able to find the file by name. */
24316 char fake_name
[80];
24318 xsnprintf (fake_name
, sizeof (fake_name
),
24319 "<bad macro file number %d>", file
);
24321 complaint (_("bad file number in macro information (%d)"),
24324 return xstrdup (fake_name
);
24328 /* Return the full name of file number I in *LH's file name table.
24329 Use COMP_DIR as the name of the current directory of the
24330 compilation. The result is allocated using xmalloc; the caller is
24331 responsible for freeing it. */
24333 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24335 /* Is the file number a valid index into the line header's file name
24336 table? Remember that file numbers start with one, not zero. */
24337 if (lh
->is_valid_file_index (file
))
24339 char *relative
= file_file_name (file
, lh
);
24341 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24343 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24344 relative
, (char *) NULL
);
24347 return file_file_name (file
, lh
);
24351 static struct macro_source_file
*
24352 macro_start_file (struct dwarf2_cu
*cu
,
24353 int file
, int line
,
24354 struct macro_source_file
*current_file
,
24355 struct line_header
*lh
)
24357 /* File name relative to the compilation directory of this source file. */
24358 char *file_name
= file_file_name (file
, lh
);
24360 if (! current_file
)
24362 /* Note: We don't create a macro table for this compilation unit
24363 at all until we actually get a filename. */
24364 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24366 /* If we have no current file, then this must be the start_file
24367 directive for the compilation unit's main source file. */
24368 current_file
= macro_set_main (macro_table
, file_name
);
24369 macro_define_special (macro_table
);
24372 current_file
= macro_include (current_file
, line
, file_name
);
24376 return current_file
;
24379 static const char *
24380 consume_improper_spaces (const char *p
, const char *body
)
24384 complaint (_("macro definition contains spaces "
24385 "in formal argument list:\n`%s'"),
24397 parse_macro_definition (struct macro_source_file
*file
, int line
,
24402 /* The body string takes one of two forms. For object-like macro
24403 definitions, it should be:
24405 <macro name> " " <definition>
24407 For function-like macro definitions, it should be:
24409 <macro name> "() " <definition>
24411 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24413 Spaces may appear only where explicitly indicated, and in the
24416 The Dwarf 2 spec says that an object-like macro's name is always
24417 followed by a space, but versions of GCC around March 2002 omit
24418 the space when the macro's definition is the empty string.
24420 The Dwarf 2 spec says that there should be no spaces between the
24421 formal arguments in a function-like macro's formal argument list,
24422 but versions of GCC around March 2002 include spaces after the
24426 /* Find the extent of the macro name. The macro name is terminated
24427 by either a space or null character (for an object-like macro) or
24428 an opening paren (for a function-like macro). */
24429 for (p
= body
; *p
; p
++)
24430 if (*p
== ' ' || *p
== '(')
24433 if (*p
== ' ' || *p
== '\0')
24435 /* It's an object-like macro. */
24436 int name_len
= p
- body
;
24437 std::string
name (body
, name_len
);
24438 const char *replacement
;
24441 replacement
= body
+ name_len
+ 1;
24444 dwarf2_macro_malformed_definition_complaint (body
);
24445 replacement
= body
+ name_len
;
24448 macro_define_object (file
, line
, name
.c_str (), replacement
);
24450 else if (*p
== '(')
24452 /* It's a function-like macro. */
24453 std::string
name (body
, p
- body
);
24456 char **argv
= XNEWVEC (char *, argv_size
);
24460 p
= consume_improper_spaces (p
, body
);
24462 /* Parse the formal argument list. */
24463 while (*p
&& *p
!= ')')
24465 /* Find the extent of the current argument name. */
24466 const char *arg_start
= p
;
24468 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24471 if (! *p
|| p
== arg_start
)
24472 dwarf2_macro_malformed_definition_complaint (body
);
24475 /* Make sure argv has room for the new argument. */
24476 if (argc
>= argv_size
)
24479 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24482 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24485 p
= consume_improper_spaces (p
, body
);
24487 /* Consume the comma, if present. */
24492 p
= consume_improper_spaces (p
, body
);
24501 /* Perfectly formed definition, no complaints. */
24502 macro_define_function (file
, line
, name
.c_str (),
24503 argc
, (const char **) argv
,
24505 else if (*p
== '\0')
24507 /* Complain, but do define it. */
24508 dwarf2_macro_malformed_definition_complaint (body
);
24509 macro_define_function (file
, line
, name
.c_str (),
24510 argc
, (const char **) argv
,
24514 /* Just complain. */
24515 dwarf2_macro_malformed_definition_complaint (body
);
24518 /* Just complain. */
24519 dwarf2_macro_malformed_definition_complaint (body
);
24524 for (i
= 0; i
< argc
; i
++)
24530 dwarf2_macro_malformed_definition_complaint (body
);
24533 /* Skip some bytes from BYTES according to the form given in FORM.
24534 Returns the new pointer. */
24536 static const gdb_byte
*
24537 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24538 enum dwarf_form form
,
24539 unsigned int offset_size
,
24540 struct dwarf2_section_info
*section
)
24542 unsigned int bytes_read
;
24546 case DW_FORM_data1
:
24551 case DW_FORM_data2
:
24555 case DW_FORM_data4
:
24559 case DW_FORM_data8
:
24563 case DW_FORM_data16
:
24567 case DW_FORM_string
:
24568 read_direct_string (abfd
, bytes
, &bytes_read
);
24569 bytes
+= bytes_read
;
24572 case DW_FORM_sec_offset
:
24574 case DW_FORM_GNU_strp_alt
:
24575 bytes
+= offset_size
;
24578 case DW_FORM_block
:
24579 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24580 bytes
+= bytes_read
;
24583 case DW_FORM_block1
:
24584 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24586 case DW_FORM_block2
:
24587 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24589 case DW_FORM_block4
:
24590 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24593 case DW_FORM_addrx
:
24594 case DW_FORM_sdata
:
24596 case DW_FORM_udata
:
24597 case DW_FORM_GNU_addr_index
:
24598 case DW_FORM_GNU_str_index
:
24599 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24602 dwarf2_section_buffer_overflow_complaint (section
);
24607 case DW_FORM_implicit_const
:
24612 complaint (_("invalid form 0x%x in `%s'"),
24613 form
, get_section_name (section
));
24621 /* A helper for dwarf_decode_macros that handles skipping an unknown
24622 opcode. Returns an updated pointer to the macro data buffer; or,
24623 on error, issues a complaint and returns NULL. */
24625 static const gdb_byte
*
24626 skip_unknown_opcode (unsigned int opcode
,
24627 const gdb_byte
**opcode_definitions
,
24628 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24630 unsigned int offset_size
,
24631 struct dwarf2_section_info
*section
)
24633 unsigned int bytes_read
, i
;
24635 const gdb_byte
*defn
;
24637 if (opcode_definitions
[opcode
] == NULL
)
24639 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24644 defn
= opcode_definitions
[opcode
];
24645 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24646 defn
+= bytes_read
;
24648 for (i
= 0; i
< arg
; ++i
)
24650 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24651 (enum dwarf_form
) defn
[i
], offset_size
,
24653 if (mac_ptr
== NULL
)
24655 /* skip_form_bytes already issued the complaint. */
24663 /* A helper function which parses the header of a macro section.
24664 If the macro section is the extended (for now called "GNU") type,
24665 then this updates *OFFSET_SIZE. Returns a pointer to just after
24666 the header, or issues a complaint and returns NULL on error. */
24668 static const gdb_byte
*
24669 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24671 const gdb_byte
*mac_ptr
,
24672 unsigned int *offset_size
,
24673 int section_is_gnu
)
24675 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24677 if (section_is_gnu
)
24679 unsigned int version
, flags
;
24681 version
= read_2_bytes (abfd
, mac_ptr
);
24682 if (version
!= 4 && version
!= 5)
24684 complaint (_("unrecognized version `%d' in .debug_macro section"),
24690 flags
= read_1_byte (abfd
, mac_ptr
);
24692 *offset_size
= (flags
& 1) ? 8 : 4;
24694 if ((flags
& 2) != 0)
24695 /* We don't need the line table offset. */
24696 mac_ptr
+= *offset_size
;
24698 /* Vendor opcode descriptions. */
24699 if ((flags
& 4) != 0)
24701 unsigned int i
, count
;
24703 count
= read_1_byte (abfd
, mac_ptr
);
24705 for (i
= 0; i
< count
; ++i
)
24707 unsigned int opcode
, bytes_read
;
24710 opcode
= read_1_byte (abfd
, mac_ptr
);
24712 opcode_definitions
[opcode
] = mac_ptr
;
24713 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24714 mac_ptr
+= bytes_read
;
24723 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24724 including DW_MACRO_import. */
24727 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24729 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24730 struct macro_source_file
*current_file
,
24731 struct line_header
*lh
,
24732 struct dwarf2_section_info
*section
,
24733 int section_is_gnu
, int section_is_dwz
,
24734 unsigned int offset_size
,
24735 htab_t include_hash
)
24737 struct dwarf2_per_objfile
*dwarf2_per_objfile
24738 = cu
->per_cu
->dwarf2_per_objfile
;
24739 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24740 enum dwarf_macro_record_type macinfo_type
;
24741 int at_commandline
;
24742 const gdb_byte
*opcode_definitions
[256];
24744 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24745 &offset_size
, section_is_gnu
);
24746 if (mac_ptr
== NULL
)
24748 /* We already issued a complaint. */
24752 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24753 GDB is still reading the definitions from command line. First
24754 DW_MACINFO_start_file will need to be ignored as it was already executed
24755 to create CURRENT_FILE for the main source holding also the command line
24756 definitions. On first met DW_MACINFO_start_file this flag is reset to
24757 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24759 at_commandline
= 1;
24763 /* Do we at least have room for a macinfo type byte? */
24764 if (mac_ptr
>= mac_end
)
24766 dwarf2_section_buffer_overflow_complaint (section
);
24770 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24773 /* Note that we rely on the fact that the corresponding GNU and
24774 DWARF constants are the same. */
24776 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24777 switch (macinfo_type
)
24779 /* A zero macinfo type indicates the end of the macro
24784 case DW_MACRO_define
:
24785 case DW_MACRO_undef
:
24786 case DW_MACRO_define_strp
:
24787 case DW_MACRO_undef_strp
:
24788 case DW_MACRO_define_sup
:
24789 case DW_MACRO_undef_sup
:
24791 unsigned int bytes_read
;
24796 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24797 mac_ptr
+= bytes_read
;
24799 if (macinfo_type
== DW_MACRO_define
24800 || macinfo_type
== DW_MACRO_undef
)
24802 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24803 mac_ptr
+= bytes_read
;
24807 LONGEST str_offset
;
24809 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24810 mac_ptr
+= offset_size
;
24812 if (macinfo_type
== DW_MACRO_define_sup
24813 || macinfo_type
== DW_MACRO_undef_sup
24816 struct dwz_file
*dwz
24817 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24819 body
= read_indirect_string_from_dwz (objfile
,
24823 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24827 is_define
= (macinfo_type
== DW_MACRO_define
24828 || macinfo_type
== DW_MACRO_define_strp
24829 || macinfo_type
== DW_MACRO_define_sup
);
24830 if (! current_file
)
24832 /* DWARF violation as no main source is present. */
24833 complaint (_("debug info with no main source gives macro %s "
24835 is_define
? _("definition") : _("undefinition"),
24839 if ((line
== 0 && !at_commandline
)
24840 || (line
!= 0 && at_commandline
))
24841 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
24842 at_commandline
? _("command-line") : _("in-file"),
24843 is_define
? _("definition") : _("undefinition"),
24844 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24848 /* Fedora's rpm-build's "debugedit" binary
24849 corrupted .debug_macro sections.
24852 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
24853 complaint (_("debug info gives %s invalid macro %s "
24854 "without body (corrupted?) at line %d "
24856 at_commandline
? _("command-line") : _("in-file"),
24857 is_define
? _("definition") : _("undefinition"),
24858 line
, current_file
->filename
);
24860 else if (is_define
)
24861 parse_macro_definition (current_file
, line
, body
);
24864 gdb_assert (macinfo_type
== DW_MACRO_undef
24865 || macinfo_type
== DW_MACRO_undef_strp
24866 || macinfo_type
== DW_MACRO_undef_sup
);
24867 macro_undef (current_file
, line
, body
);
24872 case DW_MACRO_start_file
:
24874 unsigned int bytes_read
;
24877 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24878 mac_ptr
+= bytes_read
;
24879 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24880 mac_ptr
+= bytes_read
;
24882 if ((line
== 0 && !at_commandline
)
24883 || (line
!= 0 && at_commandline
))
24884 complaint (_("debug info gives source %d included "
24885 "from %s at %s line %d"),
24886 file
, at_commandline
? _("command-line") : _("file"),
24887 line
== 0 ? _("zero") : _("non-zero"), line
);
24889 if (at_commandline
)
24891 /* This DW_MACRO_start_file was executed in the
24893 at_commandline
= 0;
24896 current_file
= macro_start_file (cu
, file
, line
, current_file
,
24901 case DW_MACRO_end_file
:
24902 if (! current_file
)
24903 complaint (_("macro debug info has an unmatched "
24904 "`close_file' directive"));
24907 current_file
= current_file
->included_by
;
24908 if (! current_file
)
24910 enum dwarf_macro_record_type next_type
;
24912 /* GCC circa March 2002 doesn't produce the zero
24913 type byte marking the end of the compilation
24914 unit. Complain if it's not there, but exit no
24917 /* Do we at least have room for a macinfo type byte? */
24918 if (mac_ptr
>= mac_end
)
24920 dwarf2_section_buffer_overflow_complaint (section
);
24924 /* We don't increment mac_ptr here, so this is just
24927 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24929 if (next_type
!= 0)
24930 complaint (_("no terminating 0-type entry for "
24931 "macros in `.debug_macinfo' section"));
24938 case DW_MACRO_import
:
24939 case DW_MACRO_import_sup
:
24943 bfd
*include_bfd
= abfd
;
24944 struct dwarf2_section_info
*include_section
= section
;
24945 const gdb_byte
*include_mac_end
= mac_end
;
24946 int is_dwz
= section_is_dwz
;
24947 const gdb_byte
*new_mac_ptr
;
24949 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24950 mac_ptr
+= offset_size
;
24952 if (macinfo_type
== DW_MACRO_import_sup
)
24954 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24956 dwarf2_read_section (objfile
, &dwz
->macro
);
24958 include_section
= &dwz
->macro
;
24959 include_bfd
= get_section_bfd_owner (include_section
);
24960 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24964 new_mac_ptr
= include_section
->buffer
+ offset
;
24965 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24969 /* This has actually happened; see
24970 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24971 complaint (_("recursive DW_MACRO_import in "
24972 ".debug_macro section"));
24976 *slot
= (void *) new_mac_ptr
;
24978 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
24979 include_mac_end
, current_file
, lh
,
24980 section
, section_is_gnu
, is_dwz
,
24981 offset_size
, include_hash
);
24983 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24988 case DW_MACINFO_vendor_ext
:
24989 if (!section_is_gnu
)
24991 unsigned int bytes_read
;
24993 /* This reads the constant, but since we don't recognize
24994 any vendor extensions, we ignore it. */
24995 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24996 mac_ptr
+= bytes_read
;
24997 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24998 mac_ptr
+= bytes_read
;
25000 /* We don't recognize any vendor extensions. */
25006 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25007 mac_ptr
, mac_end
, abfd
, offset_size
,
25009 if (mac_ptr
== NULL
)
25014 } while (macinfo_type
!= 0);
25018 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
25019 int section_is_gnu
)
25021 struct dwarf2_per_objfile
*dwarf2_per_objfile
25022 = cu
->per_cu
->dwarf2_per_objfile
;
25023 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25024 struct line_header
*lh
= cu
->line_header
;
25026 const gdb_byte
*mac_ptr
, *mac_end
;
25027 struct macro_source_file
*current_file
= 0;
25028 enum dwarf_macro_record_type macinfo_type
;
25029 unsigned int offset_size
= cu
->header
.offset_size
;
25030 const gdb_byte
*opcode_definitions
[256];
25032 struct dwarf2_section_info
*section
;
25033 const char *section_name
;
25035 if (cu
->dwo_unit
!= NULL
)
25037 if (section_is_gnu
)
25039 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
25040 section_name
= ".debug_macro.dwo";
25044 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
25045 section_name
= ".debug_macinfo.dwo";
25050 if (section_is_gnu
)
25052 section
= &dwarf2_per_objfile
->macro
;
25053 section_name
= ".debug_macro";
25057 section
= &dwarf2_per_objfile
->macinfo
;
25058 section_name
= ".debug_macinfo";
25062 dwarf2_read_section (objfile
, section
);
25063 if (section
->buffer
== NULL
)
25065 complaint (_("missing %s section"), section_name
);
25068 abfd
= get_section_bfd_owner (section
);
25070 /* First pass: Find the name of the base filename.
25071 This filename is needed in order to process all macros whose definition
25072 (or undefinition) comes from the command line. These macros are defined
25073 before the first DW_MACINFO_start_file entry, and yet still need to be
25074 associated to the base file.
25076 To determine the base file name, we scan the macro definitions until we
25077 reach the first DW_MACINFO_start_file entry. We then initialize
25078 CURRENT_FILE accordingly so that any macro definition found before the
25079 first DW_MACINFO_start_file can still be associated to the base file. */
25081 mac_ptr
= section
->buffer
+ offset
;
25082 mac_end
= section
->buffer
+ section
->size
;
25084 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
25085 &offset_size
, section_is_gnu
);
25086 if (mac_ptr
== NULL
)
25088 /* We already issued a complaint. */
25094 /* Do we at least have room for a macinfo type byte? */
25095 if (mac_ptr
>= mac_end
)
25097 /* Complaint is printed during the second pass as GDB will probably
25098 stop the first pass earlier upon finding
25099 DW_MACINFO_start_file. */
25103 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25106 /* Note that we rely on the fact that the corresponding GNU and
25107 DWARF constants are the same. */
25109 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25110 switch (macinfo_type
)
25112 /* A zero macinfo type indicates the end of the macro
25117 case DW_MACRO_define
:
25118 case DW_MACRO_undef
:
25119 /* Only skip the data by MAC_PTR. */
25121 unsigned int bytes_read
;
25123 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25124 mac_ptr
+= bytes_read
;
25125 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25126 mac_ptr
+= bytes_read
;
25130 case DW_MACRO_start_file
:
25132 unsigned int bytes_read
;
25135 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25136 mac_ptr
+= bytes_read
;
25137 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25138 mac_ptr
+= bytes_read
;
25140 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
25144 case DW_MACRO_end_file
:
25145 /* No data to skip by MAC_PTR. */
25148 case DW_MACRO_define_strp
:
25149 case DW_MACRO_undef_strp
:
25150 case DW_MACRO_define_sup
:
25151 case DW_MACRO_undef_sup
:
25153 unsigned int bytes_read
;
25155 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25156 mac_ptr
+= bytes_read
;
25157 mac_ptr
+= offset_size
;
25161 case DW_MACRO_import
:
25162 case DW_MACRO_import_sup
:
25163 /* Note that, according to the spec, a transparent include
25164 chain cannot call DW_MACRO_start_file. So, we can just
25165 skip this opcode. */
25166 mac_ptr
+= offset_size
;
25169 case DW_MACINFO_vendor_ext
:
25170 /* Only skip the data by MAC_PTR. */
25171 if (!section_is_gnu
)
25173 unsigned int bytes_read
;
25175 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25176 mac_ptr
+= bytes_read
;
25177 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25178 mac_ptr
+= bytes_read
;
25183 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25184 mac_ptr
, mac_end
, abfd
, offset_size
,
25186 if (mac_ptr
== NULL
)
25191 } while (macinfo_type
!= 0 && current_file
== NULL
);
25193 /* Second pass: Process all entries.
25195 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25196 command-line macro definitions/undefinitions. This flag is unset when we
25197 reach the first DW_MACINFO_start_file entry. */
25199 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25201 NULL
, xcalloc
, xfree
));
25202 mac_ptr
= section
->buffer
+ offset
;
25203 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25204 *slot
= (void *) mac_ptr
;
25205 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
25206 current_file
, lh
, section
,
25207 section_is_gnu
, 0, offset_size
,
25208 include_hash
.get ());
25211 /* Check if the attribute's form is a DW_FORM_block*
25212 if so return true else false. */
25215 attr_form_is_block (const struct attribute
*attr
)
25217 return (attr
== NULL
? 0 :
25218 attr
->form
== DW_FORM_block1
25219 || attr
->form
== DW_FORM_block2
25220 || attr
->form
== DW_FORM_block4
25221 || attr
->form
== DW_FORM_block
25222 || attr
->form
== DW_FORM_exprloc
);
25225 /* Return non-zero if ATTR's value is a section offset --- classes
25226 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25227 You may use DW_UNSND (attr) to retrieve such offsets.
25229 Section 7.5.4, "Attribute Encodings", explains that no attribute
25230 may have a value that belongs to more than one of these classes; it
25231 would be ambiguous if we did, because we use the same forms for all
25235 attr_form_is_section_offset (const struct attribute
*attr
)
25237 return (attr
->form
== DW_FORM_data4
25238 || attr
->form
== DW_FORM_data8
25239 || attr
->form
== DW_FORM_sec_offset
);
25242 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25243 zero otherwise. When this function returns true, you can apply
25244 dwarf2_get_attr_constant_value to it.
25246 However, note that for some attributes you must check
25247 attr_form_is_section_offset before using this test. DW_FORM_data4
25248 and DW_FORM_data8 are members of both the constant class, and of
25249 the classes that contain offsets into other debug sections
25250 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25251 that, if an attribute's can be either a constant or one of the
25252 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25253 taken as section offsets, not constants.
25255 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25256 cannot handle that. */
25259 attr_form_is_constant (const struct attribute
*attr
)
25261 switch (attr
->form
)
25263 case DW_FORM_sdata
:
25264 case DW_FORM_udata
:
25265 case DW_FORM_data1
:
25266 case DW_FORM_data2
:
25267 case DW_FORM_data4
:
25268 case DW_FORM_data8
:
25269 case DW_FORM_implicit_const
:
25277 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25278 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25281 attr_form_is_ref (const struct attribute
*attr
)
25283 switch (attr
->form
)
25285 case DW_FORM_ref_addr
:
25290 case DW_FORM_ref_udata
:
25291 case DW_FORM_GNU_ref_alt
:
25298 /* Return the .debug_loc section to use for CU.
25299 For DWO files use .debug_loc.dwo. */
25301 static struct dwarf2_section_info
*
25302 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25304 struct dwarf2_per_objfile
*dwarf2_per_objfile
25305 = cu
->per_cu
->dwarf2_per_objfile
;
25309 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25311 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25313 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25314 : &dwarf2_per_objfile
->loc
);
25317 /* A helper function that fills in a dwarf2_loclist_baton. */
25320 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25321 struct dwarf2_loclist_baton
*baton
,
25322 const struct attribute
*attr
)
25324 struct dwarf2_per_objfile
*dwarf2_per_objfile
25325 = cu
->per_cu
->dwarf2_per_objfile
;
25326 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25328 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25330 baton
->per_cu
= cu
->per_cu
;
25331 gdb_assert (baton
->per_cu
);
25332 /* We don't know how long the location list is, but make sure we
25333 don't run off the edge of the section. */
25334 baton
->size
= section
->size
- DW_UNSND (attr
);
25335 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25336 baton
->base_address
= cu
->base_address
;
25337 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25341 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25342 struct dwarf2_cu
*cu
, int is_block
)
25344 struct dwarf2_per_objfile
*dwarf2_per_objfile
25345 = cu
->per_cu
->dwarf2_per_objfile
;
25346 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25347 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25349 if (attr_form_is_section_offset (attr
)
25350 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25351 the section. If so, fall through to the complaint in the
25353 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25355 struct dwarf2_loclist_baton
*baton
;
25357 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25359 fill_in_loclist_baton (cu
, baton
, attr
);
25361 if (cu
->base_known
== 0)
25362 complaint (_("Location list used without "
25363 "specifying the CU base address."));
25365 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25366 ? dwarf2_loclist_block_index
25367 : dwarf2_loclist_index
);
25368 SYMBOL_LOCATION_BATON (sym
) = baton
;
25372 struct dwarf2_locexpr_baton
*baton
;
25374 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25375 baton
->per_cu
= cu
->per_cu
;
25376 gdb_assert (baton
->per_cu
);
25378 if (attr_form_is_block (attr
))
25380 /* Note that we're just copying the block's data pointer
25381 here, not the actual data. We're still pointing into the
25382 info_buffer for SYM's objfile; right now we never release
25383 that buffer, but when we do clean up properly this may
25385 baton
->size
= DW_BLOCK (attr
)->size
;
25386 baton
->data
= DW_BLOCK (attr
)->data
;
25390 dwarf2_invalid_attrib_class_complaint ("location description",
25391 sym
->natural_name ());
25395 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25396 ? dwarf2_locexpr_block_index
25397 : dwarf2_locexpr_index
);
25398 SYMBOL_LOCATION_BATON (sym
) = baton
;
25402 /* Return the OBJFILE associated with the compilation unit CU. If CU
25403 came from a separate debuginfo file, then the master objfile is
25407 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25409 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25411 /* Return the master objfile, so that we can report and look up the
25412 correct file containing this variable. */
25413 if (objfile
->separate_debug_objfile_backlink
)
25414 objfile
= objfile
->separate_debug_objfile_backlink
;
25419 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25420 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25421 CU_HEADERP first. */
25423 static const struct comp_unit_head
*
25424 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25425 struct dwarf2_per_cu_data
*per_cu
)
25427 const gdb_byte
*info_ptr
;
25430 return &per_cu
->cu
->header
;
25432 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25434 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25435 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25436 rcuh_kind::COMPILE
);
25441 /* Return the address size given in the compilation unit header for CU. */
25444 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25446 struct comp_unit_head cu_header_local
;
25447 const struct comp_unit_head
*cu_headerp
;
25449 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25451 return cu_headerp
->addr_size
;
25454 /* Return the offset size given in the compilation unit header for CU. */
25457 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25459 struct comp_unit_head cu_header_local
;
25460 const struct comp_unit_head
*cu_headerp
;
25462 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25464 return cu_headerp
->offset_size
;
25467 /* See its dwarf2loc.h declaration. */
25470 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25472 struct comp_unit_head cu_header_local
;
25473 const struct comp_unit_head
*cu_headerp
;
25475 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25477 if (cu_headerp
->version
== 2)
25478 return cu_headerp
->addr_size
;
25480 return cu_headerp
->offset_size
;
25483 /* Return the text offset of the CU. The returned offset comes from
25484 this CU's objfile. If this objfile came from a separate debuginfo
25485 file, then the offset may be different from the corresponding
25486 offset in the parent objfile. */
25489 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25491 return per_cu
->dwarf2_per_objfile
->objfile
->text_section_offset ();
25494 /* Return a type that is a generic pointer type, the size of which matches
25495 the address size given in the compilation unit header for PER_CU. */
25496 static struct type
*
25497 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25499 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25500 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25501 struct type
*addr_type
= lookup_pointer_type (void_type
);
25502 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25504 if (TYPE_LENGTH (addr_type
) == addr_size
)
25508 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25512 /* Return DWARF version number of PER_CU. */
25515 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25517 return per_cu
->dwarf_version
;
25520 /* Locate the .debug_info compilation unit from CU's objfile which contains
25521 the DIE at OFFSET. Raises an error on failure. */
25523 static struct dwarf2_per_cu_data
*
25524 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25525 unsigned int offset_in_dwz
,
25526 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25528 struct dwarf2_per_cu_data
*this_cu
;
25532 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25535 struct dwarf2_per_cu_data
*mid_cu
;
25536 int mid
= low
+ (high
- low
) / 2;
25538 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25539 if (mid_cu
->is_dwz
> offset_in_dwz
25540 || (mid_cu
->is_dwz
== offset_in_dwz
25541 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25546 gdb_assert (low
== high
);
25547 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25548 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25550 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25551 error (_("Dwarf Error: could not find partial DIE containing "
25552 "offset %s [in module %s]"),
25553 sect_offset_str (sect_off
),
25554 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25556 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25558 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25562 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25563 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25564 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25565 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25570 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25572 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25573 : per_cu (per_cu_
),
25575 has_loclist (false),
25576 checked_producer (false),
25577 producer_is_gxx_lt_4_6 (false),
25578 producer_is_gcc_lt_4_3 (false),
25579 producer_is_icc (false),
25580 producer_is_icc_lt_14 (false),
25581 producer_is_codewarrior (false),
25582 processing_has_namespace_info (false)
25587 /* Destroy a dwarf2_cu. */
25589 dwarf2_cu::~dwarf2_cu ()
25594 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25597 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25598 enum language pretend_language
)
25600 struct attribute
*attr
;
25602 /* Set the language we're debugging. */
25603 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25604 if (attr
!= nullptr)
25605 set_cu_language (DW_UNSND (attr
), cu
);
25608 cu
->language
= pretend_language
;
25609 cu
->language_defn
= language_def (cu
->language
);
25612 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25615 /* Increase the age counter on each cached compilation unit, and free
25616 any that are too old. */
25619 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25621 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25623 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25624 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25625 while (per_cu
!= NULL
)
25627 per_cu
->cu
->last_used
++;
25628 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25629 dwarf2_mark (per_cu
->cu
);
25630 per_cu
= per_cu
->cu
->read_in_chain
;
25633 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25634 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25635 while (per_cu
!= NULL
)
25637 struct dwarf2_per_cu_data
*next_cu
;
25639 next_cu
= per_cu
->cu
->read_in_chain
;
25641 if (!per_cu
->cu
->mark
)
25644 *last_chain
= next_cu
;
25647 last_chain
= &per_cu
->cu
->read_in_chain
;
25653 /* Remove a single compilation unit from the cache. */
25656 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25658 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25659 struct dwarf2_per_objfile
*dwarf2_per_objfile
25660 = target_per_cu
->dwarf2_per_objfile
;
25662 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25663 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25664 while (per_cu
!= NULL
)
25666 struct dwarf2_per_cu_data
*next_cu
;
25668 next_cu
= per_cu
->cu
->read_in_chain
;
25670 if (per_cu
== target_per_cu
)
25674 *last_chain
= next_cu
;
25678 last_chain
= &per_cu
->cu
->read_in_chain
;
25684 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25685 We store these in a hash table separate from the DIEs, and preserve them
25686 when the DIEs are flushed out of cache.
25688 The CU "per_cu" pointer is needed because offset alone is not enough to
25689 uniquely identify the type. A file may have multiple .debug_types sections,
25690 or the type may come from a DWO file. Furthermore, while it's more logical
25691 to use per_cu->section+offset, with Fission the section with the data is in
25692 the DWO file but we don't know that section at the point we need it.
25693 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25694 because we can enter the lookup routine, get_die_type_at_offset, from
25695 outside this file, and thus won't necessarily have PER_CU->cu.
25696 Fortunately, PER_CU is stable for the life of the objfile. */
25698 struct dwarf2_per_cu_offset_and_type
25700 const struct dwarf2_per_cu_data
*per_cu
;
25701 sect_offset sect_off
;
25705 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25708 per_cu_offset_and_type_hash (const void *item
)
25710 const struct dwarf2_per_cu_offset_and_type
*ofs
25711 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25713 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25716 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25719 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25721 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25722 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25723 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25724 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25726 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25727 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25730 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25731 table if necessary. For convenience, return TYPE.
25733 The DIEs reading must have careful ordering to:
25734 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25735 reading current DIE.
25736 * Not trying to dereference contents of still incompletely read in types
25737 while reading in other DIEs.
25738 * Enable referencing still incompletely read in types just by a pointer to
25739 the type without accessing its fields.
25741 Therefore caller should follow these rules:
25742 * Try to fetch any prerequisite types we may need to build this DIE type
25743 before building the type and calling set_die_type.
25744 * After building type call set_die_type for current DIE as soon as
25745 possible before fetching more types to complete the current type.
25746 * Make the type as complete as possible before fetching more types. */
25748 static struct type
*
25749 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25751 struct dwarf2_per_objfile
*dwarf2_per_objfile
25752 = cu
->per_cu
->dwarf2_per_objfile
;
25753 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25754 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25755 struct attribute
*attr
;
25756 struct dynamic_prop prop
;
25758 /* For Ada types, make sure that the gnat-specific data is always
25759 initialized (if not already set). There are a few types where
25760 we should not be doing so, because the type-specific area is
25761 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25762 where the type-specific area is used to store the floatformat).
25763 But this is not a problem, because the gnat-specific information
25764 is actually not needed for these types. */
25765 if (need_gnat_info (cu
)
25766 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25767 && TYPE_CODE (type
) != TYPE_CODE_FLT
25768 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25769 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25770 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25771 && !HAVE_GNAT_AUX_INFO (type
))
25772 INIT_GNAT_SPECIFIC (type
);
25774 /* Read DW_AT_allocated and set in type. */
25775 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25776 if (attr_form_is_block (attr
))
25778 struct type
*prop_type
25779 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25780 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25781 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25783 else if (attr
!= NULL
)
25785 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25786 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25787 sect_offset_str (die
->sect_off
));
25790 /* Read DW_AT_associated and set in type. */
25791 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25792 if (attr_form_is_block (attr
))
25794 struct type
*prop_type
25795 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25796 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25797 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25799 else if (attr
!= NULL
)
25801 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25802 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25803 sect_offset_str (die
->sect_off
));
25806 /* Read DW_AT_data_location and set in type. */
25807 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25808 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25809 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25810 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25812 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25814 dwarf2_per_objfile
->die_type_hash
=
25815 htab_create_alloc_ex (127,
25816 per_cu_offset_and_type_hash
,
25817 per_cu_offset_and_type_eq
,
25819 &objfile
->objfile_obstack
,
25820 hashtab_obstack_allocate
,
25821 dummy_obstack_deallocate
);
25824 ofs
.per_cu
= cu
->per_cu
;
25825 ofs
.sect_off
= die
->sect_off
;
25827 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25828 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25830 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25831 sect_offset_str (die
->sect_off
));
25832 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25833 struct dwarf2_per_cu_offset_and_type
);
25838 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25839 or return NULL if the die does not have a saved type. */
25841 static struct type
*
25842 get_die_type_at_offset (sect_offset sect_off
,
25843 struct dwarf2_per_cu_data
*per_cu
)
25845 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25846 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25848 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25851 ofs
.per_cu
= per_cu
;
25852 ofs
.sect_off
= sect_off
;
25853 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25854 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25861 /* Look up the type for DIE in CU in die_type_hash,
25862 or return NULL if DIE does not have a saved type. */
25864 static struct type
*
25865 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25867 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25870 /* Add a dependence relationship from CU to REF_PER_CU. */
25873 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25874 struct dwarf2_per_cu_data
*ref_per_cu
)
25878 if (cu
->dependencies
== NULL
)
25880 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25881 NULL
, &cu
->comp_unit_obstack
,
25882 hashtab_obstack_allocate
,
25883 dummy_obstack_deallocate
);
25885 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25887 *slot
= ref_per_cu
;
25890 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25891 Set the mark field in every compilation unit in the
25892 cache that we must keep because we are keeping CU. */
25895 dwarf2_mark_helper (void **slot
, void *data
)
25897 struct dwarf2_per_cu_data
*per_cu
;
25899 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25901 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25902 reading of the chain. As such dependencies remain valid it is not much
25903 useful to track and undo them during QUIT cleanups. */
25904 if (per_cu
->cu
== NULL
)
25907 if (per_cu
->cu
->mark
)
25909 per_cu
->cu
->mark
= true;
25911 if (per_cu
->cu
->dependencies
!= NULL
)
25912 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25917 /* Set the mark field in CU and in every other compilation unit in the
25918 cache that we must keep because we are keeping CU. */
25921 dwarf2_mark (struct dwarf2_cu
*cu
)
25926 if (cu
->dependencies
!= NULL
)
25927 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25931 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25935 per_cu
->cu
->mark
= false;
25936 per_cu
= per_cu
->cu
->read_in_chain
;
25940 /* Trivial hash function for partial_die_info: the hash value of a DIE
25941 is its offset in .debug_info for this objfile. */
25944 partial_die_hash (const void *item
)
25946 const struct partial_die_info
*part_die
25947 = (const struct partial_die_info
*) item
;
25949 return to_underlying (part_die
->sect_off
);
25952 /* Trivial comparison function for partial_die_info structures: two DIEs
25953 are equal if they have the same offset. */
25956 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25958 const struct partial_die_info
*part_die_lhs
25959 = (const struct partial_die_info
*) item_lhs
;
25960 const struct partial_die_info
*part_die_rhs
25961 = (const struct partial_die_info
*) item_rhs
;
25963 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25966 struct cmd_list_element
*set_dwarf_cmdlist
;
25967 struct cmd_list_element
*show_dwarf_cmdlist
;
25970 set_dwarf_cmd (const char *args
, int from_tty
)
25972 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25977 show_dwarf_cmd (const char *args
, int from_tty
)
25979 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25982 bool dwarf_always_disassemble
;
25985 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
25986 struct cmd_list_element
*c
, const char *value
)
25988 fprintf_filtered (file
,
25989 _("Whether to always disassemble "
25990 "DWARF expressions is %s.\n"),
25995 show_check_physname (struct ui_file
*file
, int from_tty
,
25996 struct cmd_list_element
*c
, const char *value
)
25998 fprintf_filtered (file
,
25999 _("Whether to check \"physname\" is %s.\n"),
26003 void _initialize_dwarf2_read ();
26005 _initialize_dwarf2_read ()
26007 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
26008 Set DWARF specific variables.\n\
26009 Configure DWARF variables such as the cache size."),
26010 &set_dwarf_cmdlist
, "maintenance set dwarf ",
26011 0/*allow-unknown*/, &maintenance_set_cmdlist
);
26013 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
26014 Show DWARF specific variables.\n\
26015 Show DWARF variables such as the cache size."),
26016 &show_dwarf_cmdlist
, "maintenance show dwarf ",
26017 0/*allow-unknown*/, &maintenance_show_cmdlist
);
26019 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
26020 &dwarf_max_cache_age
, _("\
26021 Set the upper bound on the age of cached DWARF compilation units."), _("\
26022 Show the upper bound on the age of cached DWARF compilation units."), _("\
26023 A higher limit means that cached compilation units will be stored\n\
26024 in memory longer, and more total memory will be used. Zero disables\n\
26025 caching, which can slow down startup."),
26027 show_dwarf_max_cache_age
,
26028 &set_dwarf_cmdlist
,
26029 &show_dwarf_cmdlist
);
26031 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
26032 &dwarf_always_disassemble
, _("\
26033 Set whether `info address' always disassembles DWARF expressions."), _("\
26034 Show whether `info address' always disassembles DWARF expressions."), _("\
26035 When enabled, DWARF expressions are always printed in an assembly-like\n\
26036 syntax. When disabled, expressions will be printed in a more\n\
26037 conversational style, when possible."),
26039 show_dwarf_always_disassemble
,
26040 &set_dwarf_cmdlist
,
26041 &show_dwarf_cmdlist
);
26043 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
26044 Set debugging of the DWARF reader."), _("\
26045 Show debugging of the DWARF reader."), _("\
26046 When enabled (non-zero), debugging messages are printed during DWARF\n\
26047 reading and symtab expansion. A value of 1 (one) provides basic\n\
26048 information. A value greater than 1 provides more verbose information."),
26051 &setdebuglist
, &showdebuglist
);
26053 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
26054 Set debugging of the DWARF DIE reader."), _("\
26055 Show debugging of the DWARF DIE reader."), _("\
26056 When enabled (non-zero), DIEs are dumped after they are read in.\n\
26057 The value is the maximum depth to print."),
26060 &setdebuglist
, &showdebuglist
);
26062 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
26063 Set debugging of the dwarf line reader."), _("\
26064 Show debugging of the dwarf line reader."), _("\
26065 When enabled (non-zero), line number entries are dumped as they are read in.\n\
26066 A value of 1 (one) provides basic information.\n\
26067 A value greater than 1 provides more verbose information."),
26070 &setdebuglist
, &showdebuglist
);
26072 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
26073 Set cross-checking of \"physname\" code against demangler."), _("\
26074 Show cross-checking of \"physname\" code against demangler."), _("\
26075 When enabled, GDB's internal \"physname\" code is checked against\n\
26077 NULL
, show_check_physname
,
26078 &setdebuglist
, &showdebuglist
);
26080 add_setshow_boolean_cmd ("use-deprecated-index-sections",
26081 no_class
, &use_deprecated_index_sections
, _("\
26082 Set whether to use deprecated gdb_index sections."), _("\
26083 Show whether to use deprecated gdb_index sections."), _("\
26084 When enabled, deprecated .gdb_index sections are used anyway.\n\
26085 Normally they are ignored either because of a missing feature or\n\
26086 performance issue.\n\
26087 Warning: This option must be enabled before gdb reads the file."),
26090 &setlist
, &showlist
);
26092 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26093 &dwarf2_locexpr_funcs
);
26094 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26095 &dwarf2_loclist_funcs
);
26097 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26098 &dwarf2_block_frame_base_locexpr_funcs
);
26099 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26100 &dwarf2_block_frame_base_loclist_funcs
);
26103 selftests::register_test ("dw2_expand_symtabs_matching",
26104 selftests::dw2_expand_symtabs_matching::run_test
);