1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2019 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
33 /* Standard C includes. */
37 #include <sys/types.h>
39 /* Standard C++ includes. */
42 #include <forward_list>
44 #include <unordered_map>
45 #include <unordered_set>
47 /* Local non-gdb includes. */
55 #include "common/byte-vector.h"
56 #include "common/filestuff.h"
57 #include "common/function-view.h"
58 #include "common/gdb_optional.h"
59 #include "common/gdb_unlinker.h"
60 #include "common/hash_enum.h"
61 #include "common/pathstuff.h"
62 #include "common/selftest.h"
63 #include "common/underlying.h"
64 #include "common/vec.h"
65 #include "complaints.h"
66 #include "completer.h"
67 #include "cp-support.h"
69 #include "dwarf-index-cache.h"
70 #include "dwarf-index-common.h"
72 #include "dwarf2expr.h"
73 #include "dwarf2loc.h"
74 #include "dwarf2read.h"
76 #include "expression.h"
78 #include "filename-seen-cache.h"
79 #include "filenames.h"
80 #include "gdb-demangle.h"
81 #include "gdb/gdb-index.h"
90 #include "namespace.h"
94 #include "rust-lang.h"
97 #include "typeprint.h"
100 /* When == 1, print basic high level tracing messages.
101 When > 1, be more verbose.
102 This is in contrast to the low level DIE reading of dwarf_die_debug. */
103 static unsigned int dwarf_read_debug
= 0;
105 /* When non-zero, dump DIEs after they are read in. */
106 static unsigned int dwarf_die_debug
= 0;
108 /* When non-zero, dump line number entries as they are read in. */
109 static unsigned int dwarf_line_debug
= 0;
111 /* When non-zero, cross-check physname against demangler. */
112 static int check_physname
= 0;
114 /* When non-zero, do not reject deprecated .gdb_index sections. */
115 static int use_deprecated_index_sections
= 0;
117 static const struct objfile_data
*dwarf2_objfile_data_key
;
119 /* The "aclass" indices for various kinds of computed DWARF symbols. */
121 static int dwarf2_locexpr_index
;
122 static int dwarf2_loclist_index
;
123 static int dwarf2_locexpr_block_index
;
124 static int dwarf2_loclist_block_index
;
126 /* An index into a (C++) symbol name component in a symbol name as
127 recorded in the mapped_index's symbol table. For each C++ symbol
128 in the symbol table, we record one entry for the start of each
129 component in the symbol in a table of name components, and then
130 sort the table, in order to be able to binary search symbol names,
131 ignoring leading namespaces, both completion and regular look up.
132 For example, for symbol "A::B::C", we'll have an entry that points
133 to "A::B::C", another that points to "B::C", and another for "C".
134 Note that function symbols in GDB index have no parameter
135 information, just the function/method names. You can convert a
136 name_component to a "const char *" using the
137 'mapped_index::symbol_name_at(offset_type)' method. */
139 struct name_component
141 /* Offset in the symbol name where the component starts. Stored as
142 a (32-bit) offset instead of a pointer to save memory and improve
143 locality on 64-bit architectures. */
144 offset_type name_offset
;
146 /* The symbol's index in the symbol and constant pool tables of a
151 /* Base class containing bits shared by both .gdb_index and
152 .debug_name indexes. */
154 struct mapped_index_base
156 mapped_index_base () = default;
157 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
159 /* The name_component table (a sorted vector). See name_component's
160 description above. */
161 std::vector
<name_component
> name_components
;
163 /* How NAME_COMPONENTS is sorted. */
164 enum case_sensitivity name_components_casing
;
166 /* Return the number of names in the symbol table. */
167 virtual size_t symbol_name_count () const = 0;
169 /* Get the name of the symbol at IDX in the symbol table. */
170 virtual const char *symbol_name_at (offset_type idx
) const = 0;
172 /* Return whether the name at IDX in the symbol table should be
174 virtual bool symbol_name_slot_invalid (offset_type idx
) const
179 /* Build the symbol name component sorted vector, if we haven't
181 void build_name_components ();
183 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
184 possible matches for LN_NO_PARAMS in the name component
186 std::pair
<std::vector
<name_component
>::const_iterator
,
187 std::vector
<name_component
>::const_iterator
>
188 find_name_components_bounds (const lookup_name_info
&ln_no_params
) const;
190 /* Prevent deleting/destroying via a base class pointer. */
192 ~mapped_index_base() = default;
195 /* A description of the mapped index. The file format is described in
196 a comment by the code that writes the index. */
197 struct mapped_index final
: public mapped_index_base
199 /* A slot/bucket in the symbol table hash. */
200 struct symbol_table_slot
202 const offset_type name
;
203 const offset_type vec
;
206 /* Index data format version. */
209 /* The address table data. */
210 gdb::array_view
<const gdb_byte
> address_table
;
212 /* The symbol table, implemented as a hash table. */
213 gdb::array_view
<symbol_table_slot
> symbol_table
;
215 /* A pointer to the constant pool. */
216 const char *constant_pool
= nullptr;
218 bool symbol_name_slot_invalid (offset_type idx
) const override
220 const auto &bucket
= this->symbol_table
[idx
];
221 return bucket
.name
== 0 && bucket
.vec
;
224 /* Convenience method to get at the name of the symbol at IDX in the
226 const char *symbol_name_at (offset_type idx
) const override
227 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
229 size_t symbol_name_count () const override
230 { return this->symbol_table
.size (); }
233 /* A description of the mapped .debug_names.
234 Uninitialized map has CU_COUNT 0. */
235 struct mapped_debug_names final
: public mapped_index_base
237 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
238 : dwarf2_per_objfile (dwarf2_per_objfile_
)
241 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
242 bfd_endian dwarf5_byte_order
;
243 bool dwarf5_is_dwarf64
;
244 bool augmentation_is_gdb
;
246 uint32_t cu_count
= 0;
247 uint32_t tu_count
, bucket_count
, name_count
;
248 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
249 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
250 const gdb_byte
*name_table_string_offs_reordered
;
251 const gdb_byte
*name_table_entry_offs_reordered
;
252 const gdb_byte
*entry_pool
;
259 /* Attribute name DW_IDX_*. */
262 /* Attribute form DW_FORM_*. */
265 /* Value if FORM is DW_FORM_implicit_const. */
266 LONGEST implicit_const
;
268 std::vector
<attr
> attr_vec
;
271 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
273 const char *namei_to_name (uint32_t namei
) const;
275 /* Implementation of the mapped_index_base virtual interface, for
276 the name_components cache. */
278 const char *symbol_name_at (offset_type idx
) const override
279 { return namei_to_name (idx
); }
281 size_t symbol_name_count () const override
282 { return this->name_count
; }
285 /* See dwarf2read.h. */
288 get_dwarf2_per_objfile (struct objfile
*objfile
)
290 return ((struct dwarf2_per_objfile
*)
291 objfile_data (objfile
, dwarf2_objfile_data_key
));
294 /* Set the dwarf2_per_objfile associated to OBJFILE. */
297 set_dwarf2_per_objfile (struct objfile
*objfile
,
298 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
300 gdb_assert (get_dwarf2_per_objfile (objfile
) == NULL
);
301 set_objfile_data (objfile
, dwarf2_objfile_data_key
, dwarf2_per_objfile
);
304 /* Default names of the debugging sections. */
306 /* Note that if the debugging section has been compressed, it might
307 have a name like .zdebug_info. */
309 static const struct dwarf2_debug_sections dwarf2_elf_names
=
311 { ".debug_info", ".zdebug_info" },
312 { ".debug_abbrev", ".zdebug_abbrev" },
313 { ".debug_line", ".zdebug_line" },
314 { ".debug_loc", ".zdebug_loc" },
315 { ".debug_loclists", ".zdebug_loclists" },
316 { ".debug_macinfo", ".zdebug_macinfo" },
317 { ".debug_macro", ".zdebug_macro" },
318 { ".debug_str", ".zdebug_str" },
319 { ".debug_line_str", ".zdebug_line_str" },
320 { ".debug_ranges", ".zdebug_ranges" },
321 { ".debug_rnglists", ".zdebug_rnglists" },
322 { ".debug_types", ".zdebug_types" },
323 { ".debug_addr", ".zdebug_addr" },
324 { ".debug_frame", ".zdebug_frame" },
325 { ".eh_frame", NULL
},
326 { ".gdb_index", ".zgdb_index" },
327 { ".debug_names", ".zdebug_names" },
328 { ".debug_aranges", ".zdebug_aranges" },
332 /* List of DWO/DWP sections. */
334 static const struct dwop_section_names
336 struct dwarf2_section_names abbrev_dwo
;
337 struct dwarf2_section_names info_dwo
;
338 struct dwarf2_section_names line_dwo
;
339 struct dwarf2_section_names loc_dwo
;
340 struct dwarf2_section_names loclists_dwo
;
341 struct dwarf2_section_names macinfo_dwo
;
342 struct dwarf2_section_names macro_dwo
;
343 struct dwarf2_section_names str_dwo
;
344 struct dwarf2_section_names str_offsets_dwo
;
345 struct dwarf2_section_names types_dwo
;
346 struct dwarf2_section_names cu_index
;
347 struct dwarf2_section_names tu_index
;
351 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
352 { ".debug_info.dwo", ".zdebug_info.dwo" },
353 { ".debug_line.dwo", ".zdebug_line.dwo" },
354 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
355 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
356 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
357 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
358 { ".debug_str.dwo", ".zdebug_str.dwo" },
359 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
360 { ".debug_types.dwo", ".zdebug_types.dwo" },
361 { ".debug_cu_index", ".zdebug_cu_index" },
362 { ".debug_tu_index", ".zdebug_tu_index" },
365 /* local data types */
367 /* The data in a compilation unit header, after target2host
368 translation, looks like this. */
369 struct comp_unit_head
373 unsigned char addr_size
;
374 unsigned char signed_addr_p
;
375 sect_offset abbrev_sect_off
;
377 /* Size of file offsets; either 4 or 8. */
378 unsigned int offset_size
;
380 /* Size of the length field; either 4 or 12. */
381 unsigned int initial_length_size
;
383 enum dwarf_unit_type unit_type
;
385 /* Offset to the first byte of this compilation unit header in the
386 .debug_info section, for resolving relative reference dies. */
387 sect_offset sect_off
;
389 /* Offset to first die in this cu from the start of the cu.
390 This will be the first byte following the compilation unit header. */
391 cu_offset first_die_cu_offset
;
393 /* 64-bit signature of this type unit - it is valid only for
394 UNIT_TYPE DW_UT_type. */
397 /* For types, offset in the type's DIE of the type defined by this TU. */
398 cu_offset type_cu_offset_in_tu
;
401 /* Type used for delaying computation of method physnames.
402 See comments for compute_delayed_physnames. */
403 struct delayed_method_info
405 /* The type to which the method is attached, i.e., its parent class. */
408 /* The index of the method in the type's function fieldlists. */
411 /* The index of the method in the fieldlist. */
414 /* The name of the DIE. */
417 /* The DIE associated with this method. */
418 struct die_info
*die
;
421 /* Internal state when decoding a particular compilation unit. */
424 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
427 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
429 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
430 Create the set of symtabs used by this TU, or if this TU is sharing
431 symtabs with another TU and the symtabs have already been created
432 then restore those symtabs in the line header.
433 We don't need the pc/line-number mapping for type units. */
434 void setup_type_unit_groups (struct die_info
*die
);
436 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
437 buildsym_compunit constructor. */
438 struct compunit_symtab
*start_symtab (const char *name
,
439 const char *comp_dir
,
442 /* Reset the builder. */
443 void reset_builder () { m_builder
.reset (); }
445 /* The header of the compilation unit. */
446 struct comp_unit_head header
{};
448 /* Base address of this compilation unit. */
449 CORE_ADDR base_address
= 0;
451 /* Non-zero if base_address has been set. */
454 /* The language we are debugging. */
455 enum language language
= language_unknown
;
456 const struct language_defn
*language_defn
= nullptr;
458 const char *producer
= nullptr;
461 /* The symtab builder for this CU. This is only non-NULL when full
462 symbols are being read. */
463 std::unique_ptr
<buildsym_compunit
> m_builder
;
466 /* The generic symbol table building routines have separate lists for
467 file scope symbols and all all other scopes (local scopes). So
468 we need to select the right one to pass to add_symbol_to_list().
469 We do it by keeping a pointer to the correct list in list_in_scope.
471 FIXME: The original dwarf code just treated the file scope as the
472 first local scope, and all other local scopes as nested local
473 scopes, and worked fine. Check to see if we really need to
474 distinguish these in buildsym.c. */
475 struct pending
**list_in_scope
= nullptr;
477 /* Hash table holding all the loaded partial DIEs
478 with partial_die->offset.SECT_OFF as hash. */
479 htab_t partial_dies
= nullptr;
481 /* Storage for things with the same lifetime as this read-in compilation
482 unit, including partial DIEs. */
483 auto_obstack comp_unit_obstack
;
485 /* When multiple dwarf2_cu structures are living in memory, this field
486 chains them all together, so that they can be released efficiently.
487 We will probably also want a generation counter so that most-recently-used
488 compilation units are cached... */
489 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
491 /* Backlink to our per_cu entry. */
492 struct dwarf2_per_cu_data
*per_cu
;
494 /* How many compilation units ago was this CU last referenced? */
497 /* A hash table of DIE cu_offset for following references with
498 die_info->offset.sect_off as hash. */
499 htab_t die_hash
= nullptr;
501 /* Full DIEs if read in. */
502 struct die_info
*dies
= nullptr;
504 /* A set of pointers to dwarf2_per_cu_data objects for compilation
505 units referenced by this one. Only set during full symbol processing;
506 partial symbol tables do not have dependencies. */
507 htab_t dependencies
= nullptr;
509 /* Header data from the line table, during full symbol processing. */
510 struct line_header
*line_header
= nullptr;
511 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
512 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
513 this is the DW_TAG_compile_unit die for this CU. We'll hold on
514 to the line header as long as this DIE is being processed. See
515 process_die_scope. */
516 die_info
*line_header_die_owner
= nullptr;
518 /* A list of methods which need to have physnames computed
519 after all type information has been read. */
520 std::vector
<delayed_method_info
> method_list
;
522 /* To be copied to symtab->call_site_htab. */
523 htab_t call_site_htab
= nullptr;
525 /* Non-NULL if this CU came from a DWO file.
526 There is an invariant here that is important to remember:
527 Except for attributes copied from the top level DIE in the "main"
528 (or "stub") file in preparation for reading the DWO file
529 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
530 Either there isn't a DWO file (in which case this is NULL and the point
531 is moot), or there is and either we're not going to read it (in which
532 case this is NULL) or there is and we are reading it (in which case this
534 struct dwo_unit
*dwo_unit
= nullptr;
536 /* The DW_AT_addr_base attribute if present, zero otherwise
537 (zero is a valid value though).
538 Note this value comes from the Fission stub CU/TU's DIE. */
539 ULONGEST addr_base
= 0;
541 /* The DW_AT_ranges_base attribute if present, zero otherwise
542 (zero is a valid value though).
543 Note this value comes from the Fission stub CU/TU's DIE.
544 Also note that the value is zero in the non-DWO case so this value can
545 be used without needing to know whether DWO files are in use or not.
546 N.B. This does not apply to DW_AT_ranges appearing in
547 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
548 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
549 DW_AT_ranges_base *would* have to be applied, and we'd have to care
550 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
551 ULONGEST ranges_base
= 0;
553 /* When reading debug info generated by older versions of rustc, we
554 have to rewrite some union types to be struct types with a
555 variant part. This rewriting must be done after the CU is fully
556 read in, because otherwise at the point of rewriting some struct
557 type might not have been fully processed. So, we keep a list of
558 all such types here and process them after expansion. */
559 std::vector
<struct type
*> rust_unions
;
561 /* Mark used when releasing cached dies. */
564 /* This CU references .debug_loc. See the symtab->locations_valid field.
565 This test is imperfect as there may exist optimized debug code not using
566 any location list and still facing inlining issues if handled as
567 unoptimized code. For a future better test see GCC PR other/32998. */
568 bool has_loclist
: 1;
570 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
571 if all the producer_is_* fields are valid. This information is cached
572 because profiling CU expansion showed excessive time spent in
573 producer_is_gxx_lt_4_6. */
574 bool checked_producer
: 1;
575 bool producer_is_gxx_lt_4_6
: 1;
576 bool producer_is_gcc_lt_4_3
: 1;
577 bool producer_is_icc
: 1;
578 bool producer_is_icc_lt_14
: 1;
579 bool producer_is_codewarrior
: 1;
581 /* When true, the file that we're processing is known to have
582 debugging info for C++ namespaces. GCC 3.3.x did not produce
583 this information, but later versions do. */
585 bool processing_has_namespace_info
: 1;
587 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
589 /* If this CU was inherited by another CU (via specification,
590 abstract_origin, etc), this is the ancestor CU. */
593 /* Get the buildsym_compunit for this CU. */
594 buildsym_compunit
*get_builder ()
596 /* If this CU has a builder associated with it, use that. */
597 if (m_builder
!= nullptr)
598 return m_builder
.get ();
600 /* Otherwise, search ancestors for a valid builder. */
601 if (ancestor
!= nullptr)
602 return ancestor
->get_builder ();
608 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
609 This includes type_unit_group and quick_file_names. */
611 struct stmt_list_hash
613 /* The DWO unit this table is from or NULL if there is none. */
614 struct dwo_unit
*dwo_unit
;
616 /* Offset in .debug_line or .debug_line.dwo. */
617 sect_offset line_sect_off
;
620 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
621 an object of this type. */
623 struct type_unit_group
625 /* dwarf2read.c's main "handle" on a TU symtab.
626 To simplify things we create an artificial CU that "includes" all the
627 type units using this stmt_list so that the rest of the code still has
628 a "per_cu" handle on the symtab.
629 This PER_CU is recognized by having no section. */
630 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
631 struct dwarf2_per_cu_data per_cu
;
633 /* The TUs that share this DW_AT_stmt_list entry.
634 This is added to while parsing type units to build partial symtabs,
635 and is deleted afterwards and not used again. */
636 VEC (sig_type_ptr
) *tus
;
638 /* The compunit symtab.
639 Type units in a group needn't all be defined in the same source file,
640 so we create an essentially anonymous symtab as the compunit symtab. */
641 struct compunit_symtab
*compunit_symtab
;
643 /* The data used to construct the hash key. */
644 struct stmt_list_hash hash
;
646 /* The number of symtabs from the line header.
647 The value here must match line_header.num_file_names. */
648 unsigned int num_symtabs
;
650 /* The symbol tables for this TU (obtained from the files listed in
652 WARNING: The order of entries here must match the order of entries
653 in the line header. After the first TU using this type_unit_group, the
654 line header for the subsequent TUs is recreated from this. This is done
655 because we need to use the same symtabs for each TU using the same
656 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
657 there's no guarantee the line header doesn't have duplicate entries. */
658 struct symtab
**symtabs
;
661 /* These sections are what may appear in a (real or virtual) DWO file. */
665 struct dwarf2_section_info abbrev
;
666 struct dwarf2_section_info line
;
667 struct dwarf2_section_info loc
;
668 struct dwarf2_section_info loclists
;
669 struct dwarf2_section_info macinfo
;
670 struct dwarf2_section_info macro
;
671 struct dwarf2_section_info str
;
672 struct dwarf2_section_info str_offsets
;
673 /* In the case of a virtual DWO file, these two are unused. */
674 struct dwarf2_section_info info
;
675 VEC (dwarf2_section_info_def
) *types
;
678 /* CUs/TUs in DWP/DWO files. */
682 /* Backlink to the containing struct dwo_file. */
683 struct dwo_file
*dwo_file
;
685 /* The "id" that distinguishes this CU/TU.
686 .debug_info calls this "dwo_id", .debug_types calls this "signature".
687 Since signatures came first, we stick with it for consistency. */
690 /* The section this CU/TU lives in, in the DWO file. */
691 struct dwarf2_section_info
*section
;
693 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
694 sect_offset sect_off
;
697 /* For types, offset in the type's DIE of the type defined by this TU. */
698 cu_offset type_offset_in_tu
;
701 /* include/dwarf2.h defines the DWP section codes.
702 It defines a max value but it doesn't define a min value, which we
703 use for error checking, so provide one. */
705 enum dwp_v2_section_ids
710 /* Data for one DWO file.
712 This includes virtual DWO files (a virtual DWO file is a DWO file as it
713 appears in a DWP file). DWP files don't really have DWO files per se -
714 comdat folding of types "loses" the DWO file they came from, and from
715 a high level view DWP files appear to contain a mass of random types.
716 However, to maintain consistency with the non-DWP case we pretend DWP
717 files contain virtual DWO files, and we assign each TU with one virtual
718 DWO file (generally based on the line and abbrev section offsets -
719 a heuristic that seems to work in practice). */
723 /* The DW_AT_GNU_dwo_name attribute.
724 For virtual DWO files the name is constructed from the section offsets
725 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
726 from related CU+TUs. */
727 const char *dwo_name
;
729 /* The DW_AT_comp_dir attribute. */
730 const char *comp_dir
;
732 /* The bfd, when the file is open. Otherwise this is NULL.
733 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
736 /* The sections that make up this DWO file.
737 Remember that for virtual DWO files in DWP V2, these are virtual
738 sections (for lack of a better name). */
739 struct dwo_sections sections
;
741 /* The CUs in the file.
742 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
743 an extension to handle LLVM's Link Time Optimization output (where
744 multiple source files may be compiled into a single object/dwo pair). */
747 /* Table of TUs in the file.
748 Each element is a struct dwo_unit. */
752 /* These sections are what may appear in a DWP file. */
756 /* These are used by both DWP version 1 and 2. */
757 struct dwarf2_section_info str
;
758 struct dwarf2_section_info cu_index
;
759 struct dwarf2_section_info tu_index
;
761 /* These are only used by DWP version 2 files.
762 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
763 sections are referenced by section number, and are not recorded here.
764 In DWP version 2 there is at most one copy of all these sections, each
765 section being (effectively) comprised of the concatenation of all of the
766 individual sections that exist in the version 1 format.
767 To keep the code simple we treat each of these concatenated pieces as a
768 section itself (a virtual section?). */
769 struct dwarf2_section_info abbrev
;
770 struct dwarf2_section_info info
;
771 struct dwarf2_section_info line
;
772 struct dwarf2_section_info loc
;
773 struct dwarf2_section_info macinfo
;
774 struct dwarf2_section_info macro
;
775 struct dwarf2_section_info str_offsets
;
776 struct dwarf2_section_info types
;
779 /* These sections are what may appear in a virtual DWO file in DWP version 1.
780 A virtual DWO file is a DWO file as it appears in a DWP file. */
782 struct virtual_v1_dwo_sections
784 struct dwarf2_section_info abbrev
;
785 struct dwarf2_section_info line
;
786 struct dwarf2_section_info loc
;
787 struct dwarf2_section_info macinfo
;
788 struct dwarf2_section_info macro
;
789 struct dwarf2_section_info str_offsets
;
790 /* Each DWP hash table entry records one CU or one TU.
791 That is recorded here, and copied to dwo_unit.section. */
792 struct dwarf2_section_info info_or_types
;
795 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
796 In version 2, the sections of the DWO files are concatenated together
797 and stored in one section of that name. Thus each ELF section contains
798 several "virtual" sections. */
800 struct virtual_v2_dwo_sections
802 bfd_size_type abbrev_offset
;
803 bfd_size_type abbrev_size
;
805 bfd_size_type line_offset
;
806 bfd_size_type line_size
;
808 bfd_size_type loc_offset
;
809 bfd_size_type loc_size
;
811 bfd_size_type macinfo_offset
;
812 bfd_size_type macinfo_size
;
814 bfd_size_type macro_offset
;
815 bfd_size_type macro_size
;
817 bfd_size_type str_offsets_offset
;
818 bfd_size_type str_offsets_size
;
820 /* Each DWP hash table entry records one CU or one TU.
821 That is recorded here, and copied to dwo_unit.section. */
822 bfd_size_type info_or_types_offset
;
823 bfd_size_type info_or_types_size
;
826 /* Contents of DWP hash tables. */
828 struct dwp_hash_table
830 uint32_t version
, nr_columns
;
831 uint32_t nr_units
, nr_slots
;
832 const gdb_byte
*hash_table
, *unit_table
;
837 const gdb_byte
*indices
;
841 /* This is indexed by column number and gives the id of the section
843 #define MAX_NR_V2_DWO_SECTIONS \
844 (1 /* .debug_info or .debug_types */ \
845 + 1 /* .debug_abbrev */ \
846 + 1 /* .debug_line */ \
847 + 1 /* .debug_loc */ \
848 + 1 /* .debug_str_offsets */ \
849 + 1 /* .debug_macro or .debug_macinfo */)
850 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
851 const gdb_byte
*offsets
;
852 const gdb_byte
*sizes
;
857 /* Data for one DWP file. */
861 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
863 dbfd (std::move (abfd
))
867 /* Name of the file. */
870 /* File format version. */
874 gdb_bfd_ref_ptr dbfd
;
876 /* Section info for this file. */
877 struct dwp_sections sections
{};
879 /* Table of CUs in the file. */
880 const struct dwp_hash_table
*cus
= nullptr;
882 /* Table of TUs in the file. */
883 const struct dwp_hash_table
*tus
= nullptr;
885 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
886 htab_t loaded_cus
{};
887 htab_t loaded_tus
{};
889 /* Table to map ELF section numbers to their sections.
890 This is only needed for the DWP V1 file format. */
891 unsigned int num_sections
= 0;
892 asection
**elf_sections
= nullptr;
895 /* This represents a '.dwz' file. */
899 dwz_file (gdb_bfd_ref_ptr
&&bfd
)
900 : dwz_bfd (std::move (bfd
))
904 /* A dwz file can only contain a few sections. */
905 struct dwarf2_section_info abbrev
{};
906 struct dwarf2_section_info info
{};
907 struct dwarf2_section_info str
{};
908 struct dwarf2_section_info line
{};
909 struct dwarf2_section_info macro
{};
910 struct dwarf2_section_info gdb_index
{};
911 struct dwarf2_section_info debug_names
{};
914 gdb_bfd_ref_ptr dwz_bfd
;
916 /* If we loaded the index from an external file, this contains the
917 resources associated to the open file, memory mapping, etc. */
918 std::unique_ptr
<index_cache_resource
> index_cache_res
;
921 /* Struct used to pass misc. parameters to read_die_and_children, et
922 al. which are used for both .debug_info and .debug_types dies.
923 All parameters here are unchanging for the life of the call. This
924 struct exists to abstract away the constant parameters of die reading. */
926 struct die_reader_specs
928 /* The bfd of die_section. */
931 /* The CU of the DIE we are parsing. */
932 struct dwarf2_cu
*cu
;
934 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
935 struct dwo_file
*dwo_file
;
937 /* The section the die comes from.
938 This is either .debug_info or .debug_types, or the .dwo variants. */
939 struct dwarf2_section_info
*die_section
;
941 /* die_section->buffer. */
942 const gdb_byte
*buffer
;
944 /* The end of the buffer. */
945 const gdb_byte
*buffer_end
;
947 /* The value of the DW_AT_comp_dir attribute. */
948 const char *comp_dir
;
950 /* The abbreviation table to use when reading the DIEs. */
951 struct abbrev_table
*abbrev_table
;
954 /* Type of function passed to init_cutu_and_read_dies, et.al. */
955 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
956 const gdb_byte
*info_ptr
,
957 struct die_info
*comp_unit_die
,
961 /* A 1-based directory index. This is a strong typedef to prevent
962 accidentally using a directory index as a 0-based index into an
964 enum class dir_index
: unsigned int {};
966 /* Likewise, a 1-based file name index. */
967 enum class file_name_index
: unsigned int {};
971 file_entry () = default;
973 file_entry (const char *name_
, dir_index d_index_
,
974 unsigned int mod_time_
, unsigned int length_
)
977 mod_time (mod_time_
),
981 /* Return the include directory at D_INDEX stored in LH. Returns
982 NULL if D_INDEX is out of bounds. */
983 const char *include_dir (const line_header
*lh
) const;
985 /* The file name. Note this is an observing pointer. The memory is
986 owned by debug_line_buffer. */
989 /* The directory index (1-based). */
990 dir_index d_index
{};
992 unsigned int mod_time
{};
994 unsigned int length
{};
996 /* True if referenced by the Line Number Program. */
999 /* The associated symbol table, if any. */
1000 struct symtab
*symtab
{};
1003 /* The line number information for a compilation unit (found in the
1004 .debug_line section) begins with a "statement program header",
1005 which contains the following information. */
1012 /* Add an entry to the include directory table. */
1013 void add_include_dir (const char *include_dir
);
1015 /* Add an entry to the file name table. */
1016 void add_file_name (const char *name
, dir_index d_index
,
1017 unsigned int mod_time
, unsigned int length
);
1019 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
1020 is out of bounds. */
1021 const char *include_dir_at (dir_index index
) const
1023 /* Convert directory index number (1-based) to vector index
1025 size_t vec_index
= to_underlying (index
) - 1;
1027 if (vec_index
>= include_dirs
.size ())
1029 return include_dirs
[vec_index
];
1032 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
1033 is out of bounds. */
1034 file_entry
*file_name_at (file_name_index index
)
1036 /* Convert file name index number (1-based) to vector index
1038 size_t vec_index
= to_underlying (index
) - 1;
1040 if (vec_index
>= file_names
.size ())
1042 return &file_names
[vec_index
];
1045 /* Const version of the above. */
1046 const file_entry
*file_name_at (unsigned int index
) const
1048 if (index
>= file_names
.size ())
1050 return &file_names
[index
];
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 /* The include_directories table. Note these are observing
1076 pointers. The memory is owned by debug_line_buffer. */
1077 std::vector
<const char *> include_dirs
;
1079 /* The file_names table. */
1080 std::vector
<file_entry
> file_names
;
1082 /* The start and end of the statement program following this
1083 header. These point into dwarf2_per_objfile->line_buffer. */
1084 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1087 typedef std::unique_ptr
<line_header
> line_header_up
;
1090 file_entry::include_dir (const line_header
*lh
) const
1092 return lh
->include_dir_at (d_index
);
1095 /* When we construct a partial symbol table entry we only
1096 need this much information. */
1097 struct partial_die_info
: public allocate_on_obstack
1099 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1101 /* Disable assign but still keep copy ctor, which is needed
1102 load_partial_dies. */
1103 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1105 /* Adjust the partial die before generating a symbol for it. This
1106 function may set the is_external flag or change the DIE's
1108 void fixup (struct dwarf2_cu
*cu
);
1110 /* Read a minimal amount of information into the minimal die
1112 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1113 const struct abbrev_info
&abbrev
,
1114 const gdb_byte
*info_ptr
);
1116 /* Offset of this DIE. */
1117 const sect_offset sect_off
;
1119 /* DWARF-2 tag for this DIE. */
1120 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1122 /* Assorted flags describing the data found in this DIE. */
1123 const unsigned int has_children
: 1;
1125 unsigned int is_external
: 1;
1126 unsigned int is_declaration
: 1;
1127 unsigned int has_type
: 1;
1128 unsigned int has_specification
: 1;
1129 unsigned int has_pc_info
: 1;
1130 unsigned int may_be_inlined
: 1;
1132 /* This DIE has been marked DW_AT_main_subprogram. */
1133 unsigned int main_subprogram
: 1;
1135 /* Flag set if the SCOPE field of this structure has been
1137 unsigned int scope_set
: 1;
1139 /* Flag set if the DIE has a byte_size attribute. */
1140 unsigned int has_byte_size
: 1;
1142 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1143 unsigned int has_const_value
: 1;
1145 /* Flag set if any of the DIE's children are template arguments. */
1146 unsigned int has_template_arguments
: 1;
1148 /* Flag set if fixup has been called on this die. */
1149 unsigned int fixup_called
: 1;
1151 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1152 unsigned int is_dwz
: 1;
1154 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1155 unsigned int spec_is_dwz
: 1;
1157 /* The name of this DIE. Normally the value of DW_AT_name, but
1158 sometimes a default name for unnamed DIEs. */
1159 const char *name
= nullptr;
1161 /* The linkage name, if present. */
1162 const char *linkage_name
= nullptr;
1164 /* The scope to prepend to our children. This is generally
1165 allocated on the comp_unit_obstack, so will disappear
1166 when this compilation unit leaves the cache. */
1167 const char *scope
= nullptr;
1169 /* Some data associated with the partial DIE. The tag determines
1170 which field is live. */
1173 /* The location description associated with this DIE, if any. */
1174 struct dwarf_block
*locdesc
;
1175 /* The offset of an import, for DW_TAG_imported_unit. */
1176 sect_offset sect_off
;
1179 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1180 CORE_ADDR lowpc
= 0;
1181 CORE_ADDR highpc
= 0;
1183 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1184 DW_AT_sibling, if any. */
1185 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1186 could return DW_AT_sibling values to its caller load_partial_dies. */
1187 const gdb_byte
*sibling
= nullptr;
1189 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1190 DW_AT_specification (or DW_AT_abstract_origin or
1191 DW_AT_extension). */
1192 sect_offset spec_offset
{};
1194 /* Pointers to this DIE's parent, first child, and next sibling,
1196 struct partial_die_info
*die_parent
= nullptr;
1197 struct partial_die_info
*die_child
= nullptr;
1198 struct partial_die_info
*die_sibling
= nullptr;
1200 friend struct partial_die_info
*
1201 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1204 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1205 partial_die_info (sect_offset sect_off
)
1206 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1210 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1212 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1217 has_specification
= 0;
1220 main_subprogram
= 0;
1223 has_const_value
= 0;
1224 has_template_arguments
= 0;
1231 /* This data structure holds the information of an abbrev. */
1234 unsigned int number
; /* number identifying abbrev */
1235 enum dwarf_tag tag
; /* dwarf tag */
1236 unsigned short has_children
; /* boolean */
1237 unsigned short num_attrs
; /* number of attributes */
1238 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1239 struct abbrev_info
*next
; /* next in chain */
1244 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1245 ENUM_BITFIELD(dwarf_form
) form
: 16;
1247 /* It is valid only if FORM is DW_FORM_implicit_const. */
1248 LONGEST implicit_const
;
1251 /* Size of abbrev_table.abbrev_hash_table. */
1252 #define ABBREV_HASH_SIZE 121
1254 /* Top level data structure to contain an abbreviation table. */
1258 explicit abbrev_table (sect_offset off
)
1262 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1263 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1266 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1268 /* Allocate space for a struct abbrev_info object in
1270 struct abbrev_info
*alloc_abbrev ();
1272 /* Add an abbreviation to the table. */
1273 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1275 /* Look up an abbrev in the table.
1276 Returns NULL if the abbrev is not found. */
1278 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1281 /* Where the abbrev table came from.
1282 This is used as a sanity check when the table is used. */
1283 const sect_offset sect_off
;
1285 /* Storage for the abbrev table. */
1286 auto_obstack abbrev_obstack
;
1290 /* Hash table of abbrevs.
1291 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1292 It could be statically allocated, but the previous code didn't so we
1294 struct abbrev_info
**m_abbrevs
;
1297 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1299 /* Attributes have a name and a value. */
1302 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1303 ENUM_BITFIELD(dwarf_form
) form
: 15;
1305 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1306 field should be in u.str (existing only for DW_STRING) but it is kept
1307 here for better struct attribute alignment. */
1308 unsigned int string_is_canonical
: 1;
1313 struct dwarf_block
*blk
;
1322 /* This data structure holds a complete die structure. */
1325 /* DWARF-2 tag for this DIE. */
1326 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1328 /* Number of attributes */
1329 unsigned char num_attrs
;
1331 /* True if we're presently building the full type name for the
1332 type derived from this DIE. */
1333 unsigned char building_fullname
: 1;
1335 /* True if this die is in process. PR 16581. */
1336 unsigned char in_process
: 1;
1339 unsigned int abbrev
;
1341 /* Offset in .debug_info or .debug_types section. */
1342 sect_offset sect_off
;
1344 /* The dies in a compilation unit form an n-ary tree. PARENT
1345 points to this die's parent; CHILD points to the first child of
1346 this node; and all the children of a given node are chained
1347 together via their SIBLING fields. */
1348 struct die_info
*child
; /* Its first child, if any. */
1349 struct die_info
*sibling
; /* Its next sibling, if any. */
1350 struct die_info
*parent
; /* Its parent, if any. */
1352 /* An array of attributes, with NUM_ATTRS elements. There may be
1353 zero, but it's not common and zero-sized arrays are not
1354 sufficiently portable C. */
1355 struct attribute attrs
[1];
1358 /* Get at parts of an attribute structure. */
1360 #define DW_STRING(attr) ((attr)->u.str)
1361 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1362 #define DW_UNSND(attr) ((attr)->u.unsnd)
1363 #define DW_BLOCK(attr) ((attr)->u.blk)
1364 #define DW_SND(attr) ((attr)->u.snd)
1365 #define DW_ADDR(attr) ((attr)->u.addr)
1366 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1368 /* Blocks are a bunch of untyped bytes. */
1373 /* Valid only if SIZE is not zero. */
1374 const gdb_byte
*data
;
1377 #ifndef ATTR_ALLOC_CHUNK
1378 #define ATTR_ALLOC_CHUNK 4
1381 /* Allocate fields for structs, unions and enums in this size. */
1382 #ifndef DW_FIELD_ALLOC_CHUNK
1383 #define DW_FIELD_ALLOC_CHUNK 4
1386 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1387 but this would require a corresponding change in unpack_field_as_long
1389 static int bits_per_byte
= 8;
1391 /* When reading a variant or variant part, we track a bit more
1392 information about the field, and store it in an object of this
1395 struct variant_field
1397 /* If we see a DW_TAG_variant, then this will be the discriminant
1399 ULONGEST discriminant_value
;
1400 /* If we see a DW_TAG_variant, then this will be set if this is the
1402 bool default_branch
;
1403 /* While reading a DW_TAG_variant_part, this will be set if this
1404 field is the discriminant. */
1405 bool is_discriminant
;
1410 int accessibility
= 0;
1412 /* Extra information to describe a variant or variant part. */
1413 struct variant_field variant
{};
1414 struct field field
{};
1419 const char *name
= nullptr;
1420 std::vector
<struct fn_field
> fnfields
;
1423 /* The routines that read and process dies for a C struct or C++ class
1424 pass lists of data member fields and lists of member function fields
1425 in an instance of a field_info structure, as defined below. */
1428 /* List of data member and baseclasses fields. */
1429 std::vector
<struct nextfield
> fields
;
1430 std::vector
<struct nextfield
> baseclasses
;
1432 /* Number of fields (including baseclasses). */
1435 /* Set if the accesibility of one of the fields is not public. */
1436 int non_public_fields
= 0;
1438 /* Member function fieldlist array, contains name of possibly overloaded
1439 member function, number of overloaded member functions and a pointer
1440 to the head of the member function field chain. */
1441 std::vector
<struct fnfieldlist
> fnfieldlists
;
1443 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1444 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1445 std::vector
<struct decl_field
> typedef_field_list
;
1447 /* Nested types defined by this class and the number of elements in this
1449 std::vector
<struct decl_field
> nested_types_list
;
1452 /* One item on the queue of compilation units to read in full symbols
1454 struct dwarf2_queue_item
1456 struct dwarf2_per_cu_data
*per_cu
;
1457 enum language pretend_language
;
1458 struct dwarf2_queue_item
*next
;
1461 /* The current queue. */
1462 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1464 /* Loaded secondary compilation units are kept in memory until they
1465 have not been referenced for the processing of this many
1466 compilation units. Set this to zero to disable caching. Cache
1467 sizes of up to at least twenty will improve startup time for
1468 typical inter-CU-reference binaries, at an obvious memory cost. */
1469 static int dwarf_max_cache_age
= 5;
1471 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1472 struct cmd_list_element
*c
, const char *value
)
1474 fprintf_filtered (file
, _("The upper bound on the age of cached "
1475 "DWARF compilation units is %s.\n"),
1479 /* local function prototypes */
1481 static const char *get_section_name (const struct dwarf2_section_info
*);
1483 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1485 static void dwarf2_find_base_address (struct die_info
*die
,
1486 struct dwarf2_cu
*cu
);
1488 static struct partial_symtab
*create_partial_symtab
1489 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1491 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1492 const gdb_byte
*info_ptr
,
1493 struct die_info
*type_unit_die
,
1494 int has_children
, void *data
);
1496 static void dwarf2_build_psymtabs_hard
1497 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1499 static void scan_partial_symbols (struct partial_die_info
*,
1500 CORE_ADDR
*, CORE_ADDR
*,
1501 int, struct dwarf2_cu
*);
1503 static void add_partial_symbol (struct partial_die_info
*,
1504 struct dwarf2_cu
*);
1506 static void add_partial_namespace (struct partial_die_info
*pdi
,
1507 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1508 int set_addrmap
, struct dwarf2_cu
*cu
);
1510 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1511 CORE_ADDR
*highpc
, int set_addrmap
,
1512 struct dwarf2_cu
*cu
);
1514 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1515 struct dwarf2_cu
*cu
);
1517 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1518 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1519 int need_pc
, struct dwarf2_cu
*cu
);
1521 static void dwarf2_read_symtab (struct partial_symtab
*,
1524 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1526 static abbrev_table_up abbrev_table_read_table
1527 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1530 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1532 static struct partial_die_info
*load_partial_dies
1533 (const struct die_reader_specs
*, const gdb_byte
*, int);
1535 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1536 struct dwarf2_cu
*);
1538 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1539 struct attribute
*, struct attr_abbrev
*,
1542 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1544 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1546 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1548 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1550 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1552 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1555 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1557 static LONGEST read_checked_initial_length_and_offset
1558 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1559 unsigned int *, unsigned int *);
1561 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1562 const struct comp_unit_head
*,
1565 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1567 static sect_offset read_abbrev_offset
1568 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1569 struct dwarf2_section_info
*, sect_offset
);
1571 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1573 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1575 static const char *read_indirect_string
1576 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1577 const struct comp_unit_head
*, unsigned int *);
1579 static const char *read_indirect_line_string
1580 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1581 const struct comp_unit_head
*, unsigned int *);
1583 static const char *read_indirect_string_at_offset
1584 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1585 LONGEST str_offset
);
1587 static const char *read_indirect_string_from_dwz
1588 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1590 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1592 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1596 static const char *read_str_index (const struct die_reader_specs
*reader
,
1597 ULONGEST str_index
);
1599 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1601 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1602 struct dwarf2_cu
*);
1604 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1607 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1608 struct dwarf2_cu
*cu
);
1610 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1611 struct dwarf2_cu
*cu
);
1613 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1615 static struct die_info
*die_specification (struct die_info
*die
,
1616 struct dwarf2_cu
**);
1618 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1619 struct dwarf2_cu
*cu
);
1621 static void dwarf_decode_lines (struct line_header
*, const char *,
1622 struct dwarf2_cu
*, struct partial_symtab
*,
1623 CORE_ADDR
, int decode_mapping
);
1625 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1628 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1629 struct dwarf2_cu
*, struct symbol
* = NULL
);
1631 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1632 struct dwarf2_cu
*);
1634 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1637 struct obstack
*obstack
,
1638 struct dwarf2_cu
*cu
, LONGEST
*value
,
1639 const gdb_byte
**bytes
,
1640 struct dwarf2_locexpr_baton
**baton
);
1642 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1644 static int need_gnat_info (struct dwarf2_cu
*);
1646 static struct type
*die_descriptive_type (struct die_info
*,
1647 struct dwarf2_cu
*);
1649 static void set_descriptive_type (struct type
*, struct die_info
*,
1650 struct dwarf2_cu
*);
1652 static struct type
*die_containing_type (struct die_info
*,
1653 struct dwarf2_cu
*);
1655 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1656 struct dwarf2_cu
*);
1658 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1660 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1662 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1664 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1665 const char *suffix
, int physname
,
1666 struct dwarf2_cu
*cu
);
1668 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1670 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1672 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1674 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1676 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1678 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1680 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1681 struct dwarf2_cu
*, struct partial_symtab
*);
1683 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1684 values. Keep the items ordered with increasing constraints compliance. */
1687 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1688 PC_BOUNDS_NOT_PRESENT
,
1690 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1691 were present but they do not form a valid range of PC addresses. */
1694 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1697 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1701 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1702 CORE_ADDR
*, CORE_ADDR
*,
1704 struct partial_symtab
*);
1706 static void get_scope_pc_bounds (struct die_info
*,
1707 CORE_ADDR
*, CORE_ADDR
*,
1708 struct dwarf2_cu
*);
1710 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1711 CORE_ADDR
, struct dwarf2_cu
*);
1713 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1714 struct dwarf2_cu
*);
1716 static void dwarf2_attach_fields_to_type (struct field_info
*,
1717 struct type
*, struct dwarf2_cu
*);
1719 static void dwarf2_add_member_fn (struct field_info
*,
1720 struct die_info
*, struct type
*,
1721 struct dwarf2_cu
*);
1723 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1725 struct dwarf2_cu
*);
1727 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1729 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1731 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1733 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1735 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1737 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1739 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1741 static struct type
*read_module_type (struct die_info
*die
,
1742 struct dwarf2_cu
*cu
);
1744 static const char *namespace_name (struct die_info
*die
,
1745 int *is_anonymous
, struct dwarf2_cu
*);
1747 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1749 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1751 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1752 struct dwarf2_cu
*);
1754 static struct die_info
*read_die_and_siblings_1
1755 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1758 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1759 const gdb_byte
*info_ptr
,
1760 const gdb_byte
**new_info_ptr
,
1761 struct die_info
*parent
);
1763 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1764 struct die_info
**, const gdb_byte
*,
1767 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1768 struct die_info
**, const gdb_byte
*,
1771 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1773 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1776 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1778 static const char *dwarf2_full_name (const char *name
,
1779 struct die_info
*die
,
1780 struct dwarf2_cu
*cu
);
1782 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1783 struct dwarf2_cu
*cu
);
1785 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1786 struct dwarf2_cu
**);
1788 static const char *dwarf_tag_name (unsigned int);
1790 static const char *dwarf_attr_name (unsigned int);
1792 static const char *dwarf_form_name (unsigned int);
1794 static const char *dwarf_bool_name (unsigned int);
1796 static const char *dwarf_type_encoding_name (unsigned int);
1798 static struct die_info
*sibling_die (struct die_info
*);
1800 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1802 static void dump_die_for_error (struct die_info
*);
1804 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1807 /*static*/ void dump_die (struct die_info
*, int max_level
);
1809 static void store_in_ref_table (struct die_info
*,
1810 struct dwarf2_cu
*);
1812 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1814 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1816 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1817 const struct attribute
*,
1818 struct dwarf2_cu
**);
1820 static struct die_info
*follow_die_ref (struct die_info
*,
1821 const struct attribute
*,
1822 struct dwarf2_cu
**);
1824 static struct die_info
*follow_die_sig (struct die_info
*,
1825 const struct attribute
*,
1826 struct dwarf2_cu
**);
1828 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1829 struct dwarf2_cu
*);
1831 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1832 const struct attribute
*,
1833 struct dwarf2_cu
*);
1835 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1837 static void read_signatured_type (struct signatured_type
*);
1839 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1840 struct die_info
*die
, struct dwarf2_cu
*cu
,
1841 struct dynamic_prop
*prop
);
1843 /* memory allocation interface */
1845 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1847 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1849 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1851 static int attr_form_is_block (const struct attribute
*);
1853 static int attr_form_is_section_offset (const struct attribute
*);
1855 static int attr_form_is_constant (const struct attribute
*);
1857 static int attr_form_is_ref (const struct attribute
*);
1859 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1860 struct dwarf2_loclist_baton
*baton
,
1861 const struct attribute
*attr
);
1863 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1865 struct dwarf2_cu
*cu
,
1868 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1869 const gdb_byte
*info_ptr
,
1870 struct abbrev_info
*abbrev
);
1872 static hashval_t
partial_die_hash (const void *item
);
1874 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1876 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1877 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1878 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1880 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1881 struct die_info
*comp_unit_die
,
1882 enum language pretend_language
);
1884 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1886 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1888 static struct type
*set_die_type (struct die_info
*, struct type
*,
1889 struct dwarf2_cu
*);
1891 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1893 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1895 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1898 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1901 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1904 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1905 struct dwarf2_per_cu_data
*);
1907 static void dwarf2_mark (struct dwarf2_cu
*);
1909 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1911 static struct type
*get_die_type_at_offset (sect_offset
,
1912 struct dwarf2_per_cu_data
*);
1914 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1916 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1917 enum language pretend_language
);
1919 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1921 /* Class, the destructor of which frees all allocated queue entries. This
1922 will only have work to do if an error was thrown while processing the
1923 dwarf. If no error was thrown then the queue entries should have all
1924 been processed, and freed, as we went along. */
1926 class dwarf2_queue_guard
1929 dwarf2_queue_guard () = default;
1931 /* Free any entries remaining on the queue. There should only be
1932 entries left if we hit an error while processing the dwarf. */
1933 ~dwarf2_queue_guard ()
1935 struct dwarf2_queue_item
*item
, *last
;
1937 item
= dwarf2_queue
;
1940 /* Anything still marked queued is likely to be in an
1941 inconsistent state, so discard it. */
1942 if (item
->per_cu
->queued
)
1944 if (item
->per_cu
->cu
!= NULL
)
1945 free_one_cached_comp_unit (item
->per_cu
);
1946 item
->per_cu
->queued
= 0;
1954 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1958 /* The return type of find_file_and_directory. Note, the enclosed
1959 string pointers are only valid while this object is valid. */
1961 struct file_and_directory
1963 /* The filename. This is never NULL. */
1966 /* The compilation directory. NULL if not known. If we needed to
1967 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1968 points directly to the DW_AT_comp_dir string attribute owned by
1969 the obstack that owns the DIE. */
1970 const char *comp_dir
;
1972 /* If we needed to build a new string for comp_dir, this is what
1973 owns the storage. */
1974 std::string comp_dir_storage
;
1977 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1978 struct dwarf2_cu
*cu
);
1980 static char *file_full_name (int file
, struct line_header
*lh
,
1981 const char *comp_dir
);
1983 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1984 enum class rcuh_kind
{ COMPILE
, TYPE
};
1986 static const gdb_byte
*read_and_check_comp_unit_head
1987 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1988 struct comp_unit_head
*header
,
1989 struct dwarf2_section_info
*section
,
1990 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1991 rcuh_kind section_kind
);
1993 static void init_cutu_and_read_dies
1994 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1995 int use_existing_cu
, int keep
, bool skip_partial
,
1996 die_reader_func_ftype
*die_reader_func
, void *data
);
1998 static void init_cutu_and_read_dies_simple
1999 (struct dwarf2_per_cu_data
*this_cu
,
2000 die_reader_func_ftype
*die_reader_func
, void *data
);
2002 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2004 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2006 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2007 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2008 struct dwp_file
*dwp_file
, const char *comp_dir
,
2009 ULONGEST signature
, int is_debug_types
);
2011 static struct dwp_file
*get_dwp_file
2012 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2014 static struct dwo_unit
*lookup_dwo_comp_unit
2015 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2017 static struct dwo_unit
*lookup_dwo_type_unit
2018 (struct signatured_type
*, const char *, const char *);
2020 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2022 static void free_dwo_file (struct dwo_file
*);
2024 /* A unique_ptr helper to free a dwo_file. */
2026 struct dwo_file_deleter
2028 void operator() (struct dwo_file
*df
) const
2034 /* A unique pointer to a dwo_file. */
2036 typedef std::unique_ptr
<struct dwo_file
, dwo_file_deleter
> dwo_file_up
;
2038 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2040 static void check_producer (struct dwarf2_cu
*cu
);
2042 static void free_line_header_voidp (void *arg
);
2044 /* Various complaints about symbol reading that don't abort the process. */
2047 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2049 complaint (_("statement list doesn't fit in .debug_line section"));
2053 dwarf2_debug_line_missing_file_complaint (void)
2055 complaint (_(".debug_line section has line data without a file"));
2059 dwarf2_debug_line_missing_end_sequence_complaint (void)
2061 complaint (_(".debug_line section has line "
2062 "program sequence without an end"));
2066 dwarf2_complex_location_expr_complaint (void)
2068 complaint (_("location expression too complex"));
2072 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2075 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
2080 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2082 complaint (_("debug info runs off end of %s section"
2084 get_section_name (section
),
2085 get_section_file_name (section
));
2089 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2091 complaint (_("macro debug info contains a "
2092 "malformed macro definition:\n`%s'"),
2097 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2099 complaint (_("invalid attribute class or form for '%s' in '%s'"),
2103 /* Hash function for line_header_hash. */
2106 line_header_hash (const struct line_header
*ofs
)
2108 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2111 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2114 line_header_hash_voidp (const void *item
)
2116 const struct line_header
*ofs
= (const struct line_header
*) item
;
2118 return line_header_hash (ofs
);
2121 /* Equality function for line_header_hash. */
2124 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2126 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2127 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2129 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2130 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2135 /* Read the given attribute value as an address, taking the attribute's
2136 form into account. */
2139 attr_value_as_address (struct attribute
*attr
)
2143 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2145 /* Aside from a few clearly defined exceptions, attributes that
2146 contain an address must always be in DW_FORM_addr form.
2147 Unfortunately, some compilers happen to be violating this
2148 requirement by encoding addresses using other forms, such
2149 as DW_FORM_data4 for example. For those broken compilers,
2150 we try to do our best, without any guarantee of success,
2151 to interpret the address correctly. It would also be nice
2152 to generate a complaint, but that would require us to maintain
2153 a list of legitimate cases where a non-address form is allowed,
2154 as well as update callers to pass in at least the CU's DWARF
2155 version. This is more overhead than what we're willing to
2156 expand for a pretty rare case. */
2157 addr
= DW_UNSND (attr
);
2160 addr
= DW_ADDR (attr
);
2165 /* See declaration. */
2167 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2168 const dwarf2_debug_sections
*names
)
2169 : objfile (objfile_
)
2172 names
= &dwarf2_elf_names
;
2174 bfd
*obfd
= objfile
->obfd
;
2176 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2177 locate_sections (obfd
, sec
, *names
);
2180 static void free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
);
2182 dwarf2_per_objfile::~dwarf2_per_objfile ()
2184 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2185 free_cached_comp_units ();
2187 if (quick_file_names_table
)
2188 htab_delete (quick_file_names_table
);
2190 if (line_header_hash
)
2191 htab_delete (line_header_hash
);
2193 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2194 VEC_free (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
);
2196 for (signatured_type
*sig_type
: all_type_units
)
2197 VEC_free (dwarf2_per_cu_ptr
, sig_type
->per_cu
.imported_symtabs
);
2199 VEC_free (dwarf2_section_info_def
, types
);
2201 if (dwo_files
!= NULL
)
2202 free_dwo_files (dwo_files
, objfile
);
2204 /* Everything else should be on the objfile obstack. */
2207 /* See declaration. */
2210 dwarf2_per_objfile::free_cached_comp_units ()
2212 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2213 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2214 while (per_cu
!= NULL
)
2216 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2219 *last_chain
= next_cu
;
2224 /* A helper class that calls free_cached_comp_units on
2227 class free_cached_comp_units
2231 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2232 : m_per_objfile (per_objfile
)
2236 ~free_cached_comp_units ()
2238 m_per_objfile
->free_cached_comp_units ();
2241 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2245 dwarf2_per_objfile
*m_per_objfile
;
2248 /* Try to locate the sections we need for DWARF 2 debugging
2249 information and return true if we have enough to do something.
2250 NAMES points to the dwarf2 section names, or is NULL if the standard
2251 ELF names are used. */
2254 dwarf2_has_info (struct objfile
*objfile
,
2255 const struct dwarf2_debug_sections
*names
)
2257 if (objfile
->flags
& OBJF_READNEVER
)
2260 struct dwarf2_per_objfile
*dwarf2_per_objfile
2261 = get_dwarf2_per_objfile (objfile
);
2263 if (dwarf2_per_objfile
== NULL
)
2265 /* Initialize per-objfile state. */
2267 = new (&objfile
->objfile_obstack
) struct dwarf2_per_objfile (objfile
,
2269 set_dwarf2_per_objfile (objfile
, dwarf2_per_objfile
);
2271 return (!dwarf2_per_objfile
->info
.is_virtual
2272 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2273 && !dwarf2_per_objfile
->abbrev
.is_virtual
2274 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2277 /* Return the containing section of virtual section SECTION. */
2279 static struct dwarf2_section_info
*
2280 get_containing_section (const struct dwarf2_section_info
*section
)
2282 gdb_assert (section
->is_virtual
);
2283 return section
->s
.containing_section
;
2286 /* Return the bfd owner of SECTION. */
2289 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2291 if (section
->is_virtual
)
2293 section
= get_containing_section (section
);
2294 gdb_assert (!section
->is_virtual
);
2296 return section
->s
.section
->owner
;
2299 /* Return the bfd section of SECTION.
2300 Returns NULL if the section is not present. */
2303 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2305 if (section
->is_virtual
)
2307 section
= get_containing_section (section
);
2308 gdb_assert (!section
->is_virtual
);
2310 return section
->s
.section
;
2313 /* Return the name of SECTION. */
2316 get_section_name (const struct dwarf2_section_info
*section
)
2318 asection
*sectp
= get_section_bfd_section (section
);
2320 gdb_assert (sectp
!= NULL
);
2321 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2324 /* Return the name of the file SECTION is in. */
2327 get_section_file_name (const struct dwarf2_section_info
*section
)
2329 bfd
*abfd
= get_section_bfd_owner (section
);
2331 return bfd_get_filename (abfd
);
2334 /* Return the id of SECTION.
2335 Returns 0 if SECTION doesn't exist. */
2338 get_section_id (const struct dwarf2_section_info
*section
)
2340 asection
*sectp
= get_section_bfd_section (section
);
2347 /* Return the flags of SECTION.
2348 SECTION (or containing section if this is a virtual section) must exist. */
2351 get_section_flags (const struct dwarf2_section_info
*section
)
2353 asection
*sectp
= get_section_bfd_section (section
);
2355 gdb_assert (sectp
!= NULL
);
2356 return bfd_get_section_flags (sectp
->owner
, sectp
);
2359 /* When loading sections, we look either for uncompressed section or for
2360 compressed section names. */
2363 section_is_p (const char *section_name
,
2364 const struct dwarf2_section_names
*names
)
2366 if (names
->normal
!= NULL
2367 && strcmp (section_name
, names
->normal
) == 0)
2369 if (names
->compressed
!= NULL
2370 && strcmp (section_name
, names
->compressed
) == 0)
2375 /* See declaration. */
2378 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2379 const dwarf2_debug_sections
&names
)
2381 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2383 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2386 else if (section_is_p (sectp
->name
, &names
.info
))
2388 this->info
.s
.section
= sectp
;
2389 this->info
.size
= bfd_get_section_size (sectp
);
2391 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2393 this->abbrev
.s
.section
= sectp
;
2394 this->abbrev
.size
= bfd_get_section_size (sectp
);
2396 else if (section_is_p (sectp
->name
, &names
.line
))
2398 this->line
.s
.section
= sectp
;
2399 this->line
.size
= bfd_get_section_size (sectp
);
2401 else if (section_is_p (sectp
->name
, &names
.loc
))
2403 this->loc
.s
.section
= sectp
;
2404 this->loc
.size
= bfd_get_section_size (sectp
);
2406 else if (section_is_p (sectp
->name
, &names
.loclists
))
2408 this->loclists
.s
.section
= sectp
;
2409 this->loclists
.size
= bfd_get_section_size (sectp
);
2411 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2413 this->macinfo
.s
.section
= sectp
;
2414 this->macinfo
.size
= bfd_get_section_size (sectp
);
2416 else if (section_is_p (sectp
->name
, &names
.macro
))
2418 this->macro
.s
.section
= sectp
;
2419 this->macro
.size
= bfd_get_section_size (sectp
);
2421 else if (section_is_p (sectp
->name
, &names
.str
))
2423 this->str
.s
.section
= sectp
;
2424 this->str
.size
= bfd_get_section_size (sectp
);
2426 else if (section_is_p (sectp
->name
, &names
.line_str
))
2428 this->line_str
.s
.section
= sectp
;
2429 this->line_str
.size
= bfd_get_section_size (sectp
);
2431 else if (section_is_p (sectp
->name
, &names
.addr
))
2433 this->addr
.s
.section
= sectp
;
2434 this->addr
.size
= bfd_get_section_size (sectp
);
2436 else if (section_is_p (sectp
->name
, &names
.frame
))
2438 this->frame
.s
.section
= sectp
;
2439 this->frame
.size
= bfd_get_section_size (sectp
);
2441 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2443 this->eh_frame
.s
.section
= sectp
;
2444 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2446 else if (section_is_p (sectp
->name
, &names
.ranges
))
2448 this->ranges
.s
.section
= sectp
;
2449 this->ranges
.size
= bfd_get_section_size (sectp
);
2451 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2453 this->rnglists
.s
.section
= sectp
;
2454 this->rnglists
.size
= bfd_get_section_size (sectp
);
2456 else if (section_is_p (sectp
->name
, &names
.types
))
2458 struct dwarf2_section_info type_section
;
2460 memset (&type_section
, 0, sizeof (type_section
));
2461 type_section
.s
.section
= sectp
;
2462 type_section
.size
= bfd_get_section_size (sectp
);
2464 VEC_safe_push (dwarf2_section_info_def
, this->types
,
2467 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2469 this->gdb_index
.s
.section
= sectp
;
2470 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2472 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2474 this->debug_names
.s
.section
= sectp
;
2475 this->debug_names
.size
= bfd_get_section_size (sectp
);
2477 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2479 this->debug_aranges
.s
.section
= sectp
;
2480 this->debug_aranges
.size
= bfd_get_section_size (sectp
);
2483 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2484 && bfd_section_vma (abfd
, sectp
) == 0)
2485 this->has_section_at_zero
= true;
2488 /* A helper function that decides whether a section is empty,
2492 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2494 if (section
->is_virtual
)
2495 return section
->size
== 0;
2496 return section
->s
.section
== NULL
|| section
->size
== 0;
2499 /* See dwarf2read.h. */
2502 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2506 gdb_byte
*buf
, *retbuf
;
2510 info
->buffer
= NULL
;
2513 if (dwarf2_section_empty_p (info
))
2516 sectp
= get_section_bfd_section (info
);
2518 /* If this is a virtual section we need to read in the real one first. */
2519 if (info
->is_virtual
)
2521 struct dwarf2_section_info
*containing_section
=
2522 get_containing_section (info
);
2524 gdb_assert (sectp
!= NULL
);
2525 if ((sectp
->flags
& SEC_RELOC
) != 0)
2527 error (_("Dwarf Error: DWP format V2 with relocations is not"
2528 " supported in section %s [in module %s]"),
2529 get_section_name (info
), get_section_file_name (info
));
2531 dwarf2_read_section (objfile
, containing_section
);
2532 /* Other code should have already caught virtual sections that don't
2534 gdb_assert (info
->virtual_offset
+ info
->size
2535 <= containing_section
->size
);
2536 /* If the real section is empty or there was a problem reading the
2537 section we shouldn't get here. */
2538 gdb_assert (containing_section
->buffer
!= NULL
);
2539 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2543 /* If the section has relocations, we must read it ourselves.
2544 Otherwise we attach it to the BFD. */
2545 if ((sectp
->flags
& SEC_RELOC
) == 0)
2547 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2551 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2554 /* When debugging .o files, we may need to apply relocations; see
2555 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2556 We never compress sections in .o files, so we only need to
2557 try this when the section is not compressed. */
2558 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2561 info
->buffer
= retbuf
;
2565 abfd
= get_section_bfd_owner (info
);
2566 gdb_assert (abfd
!= NULL
);
2568 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2569 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2571 error (_("Dwarf Error: Can't read DWARF data"
2572 " in section %s [in module %s]"),
2573 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2577 /* A helper function that returns the size of a section in a safe way.
2578 If you are positive that the section has been read before using the
2579 size, then it is safe to refer to the dwarf2_section_info object's
2580 "size" field directly. In other cases, you must call this
2581 function, because for compressed sections the size field is not set
2582 correctly until the section has been read. */
2584 static bfd_size_type
2585 dwarf2_section_size (struct objfile
*objfile
,
2586 struct dwarf2_section_info
*info
)
2589 dwarf2_read_section (objfile
, info
);
2593 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2597 dwarf2_get_section_info (struct objfile
*objfile
,
2598 enum dwarf2_section_enum sect
,
2599 asection
**sectp
, const gdb_byte
**bufp
,
2600 bfd_size_type
*sizep
)
2602 struct dwarf2_per_objfile
*data
2603 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2604 dwarf2_objfile_data_key
);
2605 struct dwarf2_section_info
*info
;
2607 /* We may see an objfile without any DWARF, in which case we just
2618 case DWARF2_DEBUG_FRAME
:
2619 info
= &data
->frame
;
2621 case DWARF2_EH_FRAME
:
2622 info
= &data
->eh_frame
;
2625 gdb_assert_not_reached ("unexpected section");
2628 dwarf2_read_section (objfile
, info
);
2630 *sectp
= get_section_bfd_section (info
);
2631 *bufp
= info
->buffer
;
2632 *sizep
= info
->size
;
2635 /* A helper function to find the sections for a .dwz file. */
2638 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2640 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2642 /* Note that we only support the standard ELF names, because .dwz
2643 is ELF-only (at the time of writing). */
2644 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2646 dwz_file
->abbrev
.s
.section
= sectp
;
2647 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2649 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2651 dwz_file
->info
.s
.section
= sectp
;
2652 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2654 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2656 dwz_file
->str
.s
.section
= sectp
;
2657 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2659 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2661 dwz_file
->line
.s
.section
= sectp
;
2662 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2664 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2666 dwz_file
->macro
.s
.section
= sectp
;
2667 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2669 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2671 dwz_file
->gdb_index
.s
.section
= sectp
;
2672 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2674 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2676 dwz_file
->debug_names
.s
.section
= sectp
;
2677 dwz_file
->debug_names
.size
= bfd_get_section_size (sectp
);
2681 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2682 there is no .gnu_debugaltlink section in the file. Error if there
2683 is such a section but the file cannot be found. */
2685 static struct dwz_file
*
2686 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2688 const char *filename
;
2689 bfd_size_type buildid_len_arg
;
2693 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2694 return dwarf2_per_objfile
->dwz_file
.get ();
2696 bfd_set_error (bfd_error_no_error
);
2697 gdb::unique_xmalloc_ptr
<char> data
2698 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2699 &buildid_len_arg
, &buildid
));
2702 if (bfd_get_error () == bfd_error_no_error
)
2704 error (_("could not read '.gnu_debugaltlink' section: %s"),
2705 bfd_errmsg (bfd_get_error ()));
2708 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2710 buildid_len
= (size_t) buildid_len_arg
;
2712 filename
= data
.get ();
2714 std::string abs_storage
;
2715 if (!IS_ABSOLUTE_PATH (filename
))
2717 gdb::unique_xmalloc_ptr
<char> abs
2718 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2720 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2721 filename
= abs_storage
.c_str ();
2724 /* First try the file name given in the section. If that doesn't
2725 work, try to use the build-id instead. */
2726 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2727 if (dwz_bfd
!= NULL
)
2729 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2730 dwz_bfd
.reset (nullptr);
2733 if (dwz_bfd
== NULL
)
2734 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2736 if (dwz_bfd
== NULL
)
2737 error (_("could not find '.gnu_debugaltlink' file for %s"),
2738 objfile_name (dwarf2_per_objfile
->objfile
));
2740 std::unique_ptr
<struct dwz_file
> result
2741 (new struct dwz_file (std::move (dwz_bfd
)));
2743 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2746 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2747 result
->dwz_bfd
.get ());
2748 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2749 return dwarf2_per_objfile
->dwz_file
.get ();
2752 /* DWARF quick_symbols_functions support. */
2754 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2755 unique line tables, so we maintain a separate table of all .debug_line
2756 derived entries to support the sharing.
2757 All the quick functions need is the list of file names. We discard the
2758 line_header when we're done and don't need to record it here. */
2759 struct quick_file_names
2761 /* The data used to construct the hash key. */
2762 struct stmt_list_hash hash
;
2764 /* The number of entries in file_names, real_names. */
2765 unsigned int num_file_names
;
2767 /* The file names from the line table, after being run through
2769 const char **file_names
;
2771 /* The file names from the line table after being run through
2772 gdb_realpath. These are computed lazily. */
2773 const char **real_names
;
2776 /* When using the index (and thus not using psymtabs), each CU has an
2777 object of this type. This is used to hold information needed by
2778 the various "quick" methods. */
2779 struct dwarf2_per_cu_quick_data
2781 /* The file table. This can be NULL if there was no file table
2782 or it's currently not read in.
2783 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2784 struct quick_file_names
*file_names
;
2786 /* The corresponding symbol table. This is NULL if symbols for this
2787 CU have not yet been read. */
2788 struct compunit_symtab
*compunit_symtab
;
2790 /* A temporary mark bit used when iterating over all CUs in
2791 expand_symtabs_matching. */
2792 unsigned int mark
: 1;
2794 /* True if we've tried to read the file table and found there isn't one.
2795 There will be no point in trying to read it again next time. */
2796 unsigned int no_file_data
: 1;
2799 /* Utility hash function for a stmt_list_hash. */
2802 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2806 if (stmt_list_hash
->dwo_unit
!= NULL
)
2807 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2808 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2812 /* Utility equality function for a stmt_list_hash. */
2815 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2816 const struct stmt_list_hash
*rhs
)
2818 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2820 if (lhs
->dwo_unit
!= NULL
2821 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2824 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2827 /* Hash function for a quick_file_names. */
2830 hash_file_name_entry (const void *e
)
2832 const struct quick_file_names
*file_data
2833 = (const struct quick_file_names
*) e
;
2835 return hash_stmt_list_entry (&file_data
->hash
);
2838 /* Equality function for a quick_file_names. */
2841 eq_file_name_entry (const void *a
, const void *b
)
2843 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2844 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2846 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2849 /* Delete function for a quick_file_names. */
2852 delete_file_name_entry (void *e
)
2854 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2857 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2859 xfree ((void*) file_data
->file_names
[i
]);
2860 if (file_data
->real_names
)
2861 xfree ((void*) file_data
->real_names
[i
]);
2864 /* The space for the struct itself lives on objfile_obstack,
2865 so we don't free it here. */
2868 /* Create a quick_file_names hash table. */
2871 create_quick_file_names_table (unsigned int nr_initial_entries
)
2873 return htab_create_alloc (nr_initial_entries
,
2874 hash_file_name_entry
, eq_file_name_entry
,
2875 delete_file_name_entry
, xcalloc
, xfree
);
2878 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2879 have to be created afterwards. You should call age_cached_comp_units after
2880 processing PER_CU->CU. dw2_setup must have been already called. */
2883 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2885 if (per_cu
->is_debug_types
)
2886 load_full_type_unit (per_cu
);
2888 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2890 if (per_cu
->cu
== NULL
)
2891 return; /* Dummy CU. */
2893 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2896 /* Read in the symbols for PER_CU. */
2899 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2901 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2903 /* Skip type_unit_groups, reading the type units they contain
2904 is handled elsewhere. */
2905 if (IS_TYPE_UNIT_GROUP (per_cu
))
2908 /* The destructor of dwarf2_queue_guard frees any entries left on
2909 the queue. After this point we're guaranteed to leave this function
2910 with the dwarf queue empty. */
2911 dwarf2_queue_guard q_guard
;
2913 if (dwarf2_per_objfile
->using_index
2914 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2915 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2917 queue_comp_unit (per_cu
, language_minimal
);
2918 load_cu (per_cu
, skip_partial
);
2920 /* If we just loaded a CU from a DWO, and we're working with an index
2921 that may badly handle TUs, load all the TUs in that DWO as well.
2922 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2923 if (!per_cu
->is_debug_types
2924 && per_cu
->cu
!= NULL
2925 && per_cu
->cu
->dwo_unit
!= NULL
2926 && dwarf2_per_objfile
->index_table
!= NULL
2927 && dwarf2_per_objfile
->index_table
->version
<= 7
2928 /* DWP files aren't supported yet. */
2929 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2930 queue_and_load_all_dwo_tus (per_cu
);
2933 process_queue (dwarf2_per_objfile
);
2935 /* Age the cache, releasing compilation units that have not
2936 been used recently. */
2937 age_cached_comp_units (dwarf2_per_objfile
);
2940 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2941 the objfile from which this CU came. Returns the resulting symbol
2944 static struct compunit_symtab
*
2945 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2947 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2949 gdb_assert (dwarf2_per_objfile
->using_index
);
2950 if (!per_cu
->v
.quick
->compunit_symtab
)
2952 free_cached_comp_units
freer (dwarf2_per_objfile
);
2953 scoped_restore decrementer
= increment_reading_symtab ();
2954 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2955 process_cu_includes (dwarf2_per_objfile
);
2958 return per_cu
->v
.quick
->compunit_symtab
;
2961 /* See declaration. */
2963 dwarf2_per_cu_data
*
2964 dwarf2_per_objfile::get_cutu (int index
)
2966 if (index
>= this->all_comp_units
.size ())
2968 index
-= this->all_comp_units
.size ();
2969 gdb_assert (index
< this->all_type_units
.size ());
2970 return &this->all_type_units
[index
]->per_cu
;
2973 return this->all_comp_units
[index
];
2976 /* See declaration. */
2978 dwarf2_per_cu_data
*
2979 dwarf2_per_objfile::get_cu (int index
)
2981 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2983 return this->all_comp_units
[index
];
2986 /* See declaration. */
2989 dwarf2_per_objfile::get_tu (int index
)
2991 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2993 return this->all_type_units
[index
];
2996 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2997 objfile_obstack, and constructed with the specified field
3000 static dwarf2_per_cu_data
*
3001 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3002 struct dwarf2_section_info
*section
,
3004 sect_offset sect_off
, ULONGEST length
)
3006 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3007 dwarf2_per_cu_data
*the_cu
3008 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3009 struct dwarf2_per_cu_data
);
3010 the_cu
->sect_off
= sect_off
;
3011 the_cu
->length
= length
;
3012 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3013 the_cu
->section
= section
;
3014 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3015 struct dwarf2_per_cu_quick_data
);
3016 the_cu
->is_dwz
= is_dwz
;
3020 /* A helper for create_cus_from_index that handles a given list of
3024 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3025 const gdb_byte
*cu_list
, offset_type n_elements
,
3026 struct dwarf2_section_info
*section
,
3029 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
3031 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3033 sect_offset sect_off
3034 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3035 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3038 dwarf2_per_cu_data
*per_cu
3039 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3041 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
3045 /* Read the CU list from the mapped index, and use it to create all
3046 the CU objects for this objfile. */
3049 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3050 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3051 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3053 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3054 dwarf2_per_objfile
->all_comp_units
.reserve
3055 ((cu_list_elements
+ dwz_elements
) / 2);
3057 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3058 &dwarf2_per_objfile
->info
, 0);
3060 if (dwz_elements
== 0)
3063 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3064 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3068 /* Create the signatured type hash table from the index. */
3071 create_signatured_type_table_from_index
3072 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3073 struct dwarf2_section_info
*section
,
3074 const gdb_byte
*bytes
,
3075 offset_type elements
)
3077 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3079 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3080 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3082 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3084 for (offset_type i
= 0; i
< elements
; i
+= 3)
3086 struct signatured_type
*sig_type
;
3089 cu_offset type_offset_in_tu
;
3091 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3092 sect_offset sect_off
3093 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3095 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3097 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3100 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3101 struct signatured_type
);
3102 sig_type
->signature
= signature
;
3103 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3104 sig_type
->per_cu
.is_debug_types
= 1;
3105 sig_type
->per_cu
.section
= section
;
3106 sig_type
->per_cu
.sect_off
= sect_off
;
3107 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3108 sig_type
->per_cu
.v
.quick
3109 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3110 struct dwarf2_per_cu_quick_data
);
3112 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3115 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3118 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3121 /* Create the signatured type hash table from .debug_names. */
3124 create_signatured_type_table_from_debug_names
3125 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3126 const mapped_debug_names
&map
,
3127 struct dwarf2_section_info
*section
,
3128 struct dwarf2_section_info
*abbrev_section
)
3130 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3132 dwarf2_read_section (objfile
, section
);
3133 dwarf2_read_section (objfile
, abbrev_section
);
3135 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3136 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3138 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3140 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3142 struct signatured_type
*sig_type
;
3145 sect_offset sect_off
3146 = (sect_offset
) (extract_unsigned_integer
3147 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3149 map
.dwarf5_byte_order
));
3151 comp_unit_head cu_header
;
3152 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3154 section
->buffer
+ to_underlying (sect_off
),
3157 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3158 struct signatured_type
);
3159 sig_type
->signature
= cu_header
.signature
;
3160 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3161 sig_type
->per_cu
.is_debug_types
= 1;
3162 sig_type
->per_cu
.section
= section
;
3163 sig_type
->per_cu
.sect_off
= sect_off
;
3164 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3165 sig_type
->per_cu
.v
.quick
3166 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3167 struct dwarf2_per_cu_quick_data
);
3169 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3172 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3175 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3178 /* Read the address map data from the mapped index, and use it to
3179 populate the objfile's psymtabs_addrmap. */
3182 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3183 struct mapped_index
*index
)
3185 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3186 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3187 const gdb_byte
*iter
, *end
;
3188 struct addrmap
*mutable_map
;
3191 auto_obstack temp_obstack
;
3193 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3195 iter
= index
->address_table
.data ();
3196 end
= iter
+ index
->address_table
.size ();
3198 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3202 ULONGEST hi
, lo
, cu_index
;
3203 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3205 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3207 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3212 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
3213 hex_string (lo
), hex_string (hi
));
3217 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3219 complaint (_(".gdb_index address table has invalid CU number %u"),
3220 (unsigned) cu_index
);
3224 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
3225 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
3226 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3227 dwarf2_per_objfile
->get_cu (cu_index
));
3230 objfile
->partial_symtabs
->psymtabs_addrmap
3231 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3234 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3235 populate the objfile's psymtabs_addrmap. */
3238 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3239 struct dwarf2_section_info
*section
)
3241 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3242 bfd
*abfd
= objfile
->obfd
;
3243 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3244 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3245 SECT_OFF_TEXT (objfile
));
3247 auto_obstack temp_obstack
;
3248 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3250 std::unordered_map
<sect_offset
,
3251 dwarf2_per_cu_data
*,
3252 gdb::hash_enum
<sect_offset
>>
3253 debug_info_offset_to_per_cu
;
3254 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3256 const auto insertpair
3257 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3258 if (!insertpair
.second
)
3260 warning (_("Section .debug_aranges in %s has duplicate "
3261 "debug_info_offset %s, ignoring .debug_aranges."),
3262 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3267 dwarf2_read_section (objfile
, section
);
3269 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3271 const gdb_byte
*addr
= section
->buffer
;
3273 while (addr
< section
->buffer
+ section
->size
)
3275 const gdb_byte
*const entry_addr
= addr
;
3276 unsigned int bytes_read
;
3278 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3282 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3283 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3284 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3285 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3287 warning (_("Section .debug_aranges in %s entry at offset %zu "
3288 "length %s exceeds section length %s, "
3289 "ignoring .debug_aranges."),
3290 objfile_name (objfile
), entry_addr
- section
->buffer
,
3291 plongest (bytes_read
+ entry_length
),
3292 pulongest (section
->size
));
3296 /* The version number. */
3297 const uint16_t version
= read_2_bytes (abfd
, addr
);
3301 warning (_("Section .debug_aranges in %s entry at offset %zu "
3302 "has unsupported version %d, ignoring .debug_aranges."),
3303 objfile_name (objfile
), entry_addr
- section
->buffer
,
3308 const uint64_t debug_info_offset
3309 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3310 addr
+= offset_size
;
3311 const auto per_cu_it
3312 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3313 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3315 warning (_("Section .debug_aranges in %s entry at offset %zu "
3316 "debug_info_offset %s does not exists, "
3317 "ignoring .debug_aranges."),
3318 objfile_name (objfile
), 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 %zu "
3328 "address_size %u is invalid, ignoring .debug_aranges."),
3329 objfile_name (objfile
), entry_addr
- section
->buffer
,
3334 const uint8_t segment_selector_size
= *addr
++;
3335 if (segment_selector_size
!= 0)
3337 warning (_("Section .debug_aranges in %s entry at offset %zu "
3338 "segment_selector_size %u is not supported, "
3339 "ignoring .debug_aranges."),
3340 objfile_name (objfile
), entry_addr
- section
->buffer
,
3341 segment_selector_size
);
3345 /* Must pad to an alignment boundary that is twice the address
3346 size. It is undocumented by the DWARF standard but GCC does
3348 for (size_t padding
= ((-(addr
- section
->buffer
))
3349 & (2 * address_size
- 1));
3350 padding
> 0; padding
--)
3353 warning (_("Section .debug_aranges in %s entry at offset %zu "
3354 "padding is not zero, ignoring .debug_aranges."),
3355 objfile_name (objfile
), entry_addr
- section
->buffer
);
3361 if (addr
+ 2 * address_size
> entry_end
)
3363 warning (_("Section .debug_aranges in %s entry at offset %zu "
3364 "address list is not properly terminated, "
3365 "ignoring .debug_aranges."),
3366 objfile_name (objfile
), entry_addr
- section
->buffer
);
3369 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3371 addr
+= address_size
;
3372 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3374 addr
+= address_size
;
3375 if (start
== 0 && length
== 0)
3377 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3379 /* Symbol was eliminated due to a COMDAT group. */
3382 ULONGEST end
= start
+ length
;
3383 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3385 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3387 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3391 objfile
->partial_symtabs
->psymtabs_addrmap
3392 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3395 /* Find a slot in the mapped index INDEX for the object named NAME.
3396 If NAME is found, set *VEC_OUT to point to the CU vector in the
3397 constant pool and return true. If NAME cannot be found, return
3401 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3402 offset_type
**vec_out
)
3405 offset_type slot
, step
;
3406 int (*cmp
) (const char *, const char *);
3408 gdb::unique_xmalloc_ptr
<char> without_params
;
3409 if (current_language
->la_language
== language_cplus
3410 || current_language
->la_language
== language_fortran
3411 || current_language
->la_language
== language_d
)
3413 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3416 if (strchr (name
, '(') != NULL
)
3418 without_params
= cp_remove_params (name
);
3420 if (without_params
!= NULL
)
3421 name
= without_params
.get ();
3425 /* Index version 4 did not support case insensitive searches. But the
3426 indices for case insensitive languages are built in lowercase, therefore
3427 simulate our NAME being searched is also lowercased. */
3428 hash
= mapped_index_string_hash ((index
->version
== 4
3429 && case_sensitivity
== case_sensitive_off
3430 ? 5 : index
->version
),
3433 slot
= hash
& (index
->symbol_table
.size () - 1);
3434 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3435 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3441 const auto &bucket
= index
->symbol_table
[slot
];
3442 if (bucket
.name
== 0 && bucket
.vec
== 0)
3445 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3446 if (!cmp (name
, str
))
3448 *vec_out
= (offset_type
*) (index
->constant_pool
3449 + MAYBE_SWAP (bucket
.vec
));
3453 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3457 /* A helper function that reads the .gdb_index from BUFFER and fills
3458 in MAP. FILENAME is the name of the file containing the data;
3459 it is used for error reporting. DEPRECATED_OK is true if it is
3460 ok to use deprecated sections.
3462 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3463 out parameters that are filled in with information about the CU and
3464 TU lists in the section.
3466 Returns true if all went well, false otherwise. */
3469 read_gdb_index_from_buffer (struct objfile
*objfile
,
3470 const char *filename
,
3472 gdb::array_view
<const gdb_byte
> buffer
,
3473 struct mapped_index
*map
,
3474 const gdb_byte
**cu_list
,
3475 offset_type
*cu_list_elements
,
3476 const gdb_byte
**types_list
,
3477 offset_type
*types_list_elements
)
3479 const gdb_byte
*addr
= &buffer
[0];
3481 /* Version check. */
3482 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3483 /* Versions earlier than 3 emitted every copy of a psymbol. This
3484 causes the index to behave very poorly for certain requests. Version 3
3485 contained incomplete addrmap. So, it seems better to just ignore such
3489 static int warning_printed
= 0;
3490 if (!warning_printed
)
3492 warning (_("Skipping obsolete .gdb_index section in %s."),
3494 warning_printed
= 1;
3498 /* Index version 4 uses a different hash function than index version
3501 Versions earlier than 6 did not emit psymbols for inlined
3502 functions. Using these files will cause GDB not to be able to
3503 set breakpoints on inlined functions by name, so we ignore these
3504 indices unless the user has done
3505 "set use-deprecated-index-sections on". */
3506 if (version
< 6 && !deprecated_ok
)
3508 static int warning_printed
= 0;
3509 if (!warning_printed
)
3512 Skipping deprecated .gdb_index section in %s.\n\
3513 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3514 to use the section anyway."),
3516 warning_printed
= 1;
3520 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3521 of the TU (for symbols coming from TUs),
3522 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3523 Plus gold-generated indices can have duplicate entries for global symbols,
3524 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3525 These are just performance bugs, and we can't distinguish gdb-generated
3526 indices from gold-generated ones, so issue no warning here. */
3528 /* Indexes with higher version than the one supported by GDB may be no
3529 longer backward compatible. */
3533 map
->version
= version
;
3535 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3538 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3539 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3543 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3544 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3545 - MAYBE_SWAP (metadata
[i
]))
3549 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3550 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3552 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3555 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3556 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3558 = gdb::array_view
<mapped_index::symbol_table_slot
>
3559 ((mapped_index::symbol_table_slot
*) symbol_table
,
3560 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3563 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3568 /* Callback types for dwarf2_read_gdb_index. */
3570 typedef gdb::function_view
3571 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3572 get_gdb_index_contents_ftype
;
3573 typedef gdb::function_view
3574 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3575 get_gdb_index_contents_dwz_ftype
;
3577 /* Read .gdb_index. If everything went ok, initialize the "quick"
3578 elements of all the CUs and return 1. Otherwise, return 0. */
3581 dwarf2_read_gdb_index
3582 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3583 get_gdb_index_contents_ftype get_gdb_index_contents
,
3584 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3586 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3587 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3588 struct dwz_file
*dwz
;
3589 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3591 gdb::array_view
<const gdb_byte
> main_index_contents
3592 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3594 if (main_index_contents
.empty ())
3597 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3598 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3599 use_deprecated_index_sections
,
3600 main_index_contents
, map
.get (), &cu_list
,
3601 &cu_list_elements
, &types_list
,
3602 &types_list_elements
))
3605 /* Don't use the index if it's empty. */
3606 if (map
->symbol_table
.empty ())
3609 /* If there is a .dwz file, read it so we can get its CU list as
3611 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3614 struct mapped_index dwz_map
;
3615 const gdb_byte
*dwz_types_ignore
;
3616 offset_type dwz_types_elements_ignore
;
3618 gdb::array_view
<const gdb_byte
> dwz_index_content
3619 = get_gdb_index_contents_dwz (objfile
, dwz
);
3621 if (dwz_index_content
.empty ())
3624 if (!read_gdb_index_from_buffer (objfile
,
3625 bfd_get_filename (dwz
->dwz_bfd
), 1,
3626 dwz_index_content
, &dwz_map
,
3627 &dwz_list
, &dwz_list_elements
,
3629 &dwz_types_elements_ignore
))
3631 warning (_("could not read '.gdb_index' section from %s; skipping"),
3632 bfd_get_filename (dwz
->dwz_bfd
));
3637 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3638 dwz_list
, dwz_list_elements
);
3640 if (types_list_elements
)
3642 struct dwarf2_section_info
*section
;
3644 /* We can only handle a single .debug_types when we have an
3646 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3649 section
= VEC_index (dwarf2_section_info_def
,
3650 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
,
3675 struct dwarf2_cu
*cu
= reader
->cu
;
3676 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3677 struct dwarf2_per_objfile
*dwarf2_per_objfile
3678 = cu
->per_cu
->dwarf2_per_objfile
;
3679 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3680 struct dwarf2_per_cu_data
*lh_cu
;
3681 struct attribute
*attr
;
3684 struct quick_file_names
*qfn
;
3686 gdb_assert (! this_cu
->is_debug_types
);
3688 /* Our callers never want to match partial units -- instead they
3689 will match the enclosing full CU. */
3690 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3692 this_cu
->v
.quick
->no_file_data
= 1;
3700 sect_offset line_offset
{};
3702 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3705 struct quick_file_names find_entry
;
3707 line_offset
= (sect_offset
) DW_UNSND (attr
);
3709 /* We may have already read in this line header (TU line header sharing).
3710 If we have we're done. */
3711 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3712 find_entry
.hash
.line_sect_off
= line_offset
;
3713 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3714 &find_entry
, INSERT
);
3717 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3721 lh
= dwarf_decode_line_header (line_offset
, cu
);
3725 lh_cu
->v
.quick
->no_file_data
= 1;
3729 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3730 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3731 qfn
->hash
.line_sect_off
= line_offset
;
3732 gdb_assert (slot
!= NULL
);
3735 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3737 qfn
->num_file_names
= lh
->file_names
.size ();
3739 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
3740 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3741 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3742 qfn
->real_names
= NULL
;
3744 lh_cu
->v
.quick
->file_names
= qfn
;
3747 /* A helper for the "quick" functions which attempts to read the line
3748 table for THIS_CU. */
3750 static struct quick_file_names
*
3751 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3753 /* This should never be called for TUs. */
3754 gdb_assert (! this_cu
->is_debug_types
);
3755 /* Nor type unit groups. */
3756 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3758 if (this_cu
->v
.quick
->file_names
!= NULL
)
3759 return this_cu
->v
.quick
->file_names
;
3760 /* If we know there is no line data, no point in looking again. */
3761 if (this_cu
->v
.quick
->no_file_data
)
3764 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3766 if (this_cu
->v
.quick
->no_file_data
)
3768 return this_cu
->v
.quick
->file_names
;
3771 /* A helper for the "quick" functions which computes and caches the
3772 real path for a given file name from the line table. */
3775 dw2_get_real_path (struct objfile
*objfile
,
3776 struct quick_file_names
*qfn
, int index
)
3778 if (qfn
->real_names
== NULL
)
3779 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3780 qfn
->num_file_names
, const char *);
3782 if (qfn
->real_names
[index
] == NULL
)
3783 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3785 return qfn
->real_names
[index
];
3788 static struct symtab
*
3789 dw2_find_last_source_symtab (struct objfile
*objfile
)
3791 struct dwarf2_per_objfile
*dwarf2_per_objfile
3792 = get_dwarf2_per_objfile (objfile
);
3793 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3794 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3799 return compunit_primary_filetab (cust
);
3802 /* Traversal function for dw2_forget_cached_source_info. */
3805 dw2_free_cached_file_names (void **slot
, void *info
)
3807 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3809 if (file_data
->real_names
)
3813 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3815 xfree ((void*) file_data
->real_names
[i
]);
3816 file_data
->real_names
[i
] = NULL
;
3824 dw2_forget_cached_source_info (struct objfile
*objfile
)
3826 struct dwarf2_per_objfile
*dwarf2_per_objfile
3827 = get_dwarf2_per_objfile (objfile
);
3829 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3830 dw2_free_cached_file_names
, NULL
);
3833 /* Helper function for dw2_map_symtabs_matching_filename that expands
3834 the symtabs and calls the iterator. */
3837 dw2_map_expand_apply (struct objfile
*objfile
,
3838 struct dwarf2_per_cu_data
*per_cu
,
3839 const char *name
, const char *real_path
,
3840 gdb::function_view
<bool (symtab
*)> callback
)
3842 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3844 /* Don't visit already-expanded CUs. */
3845 if (per_cu
->v
.quick
->compunit_symtab
)
3848 /* This may expand more than one symtab, and we want to iterate over
3850 dw2_instantiate_symtab (per_cu
, false);
3852 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3853 last_made
, callback
);
3856 /* Implementation of the map_symtabs_matching_filename method. */
3859 dw2_map_symtabs_matching_filename
3860 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3861 gdb::function_view
<bool (symtab
*)> callback
)
3863 const char *name_basename
= lbasename (name
);
3864 struct dwarf2_per_objfile
*dwarf2_per_objfile
3865 = get_dwarf2_per_objfile (objfile
);
3867 /* The rule is CUs specify all the files, including those used by
3868 any TU, so there's no need to scan TUs here. */
3870 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3872 /* We only need to look at symtabs not already expanded. */
3873 if (per_cu
->v
.quick
->compunit_symtab
)
3876 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3877 if (file_data
== NULL
)
3880 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3882 const char *this_name
= file_data
->file_names
[j
];
3883 const char *this_real_name
;
3885 if (compare_filenames_for_search (this_name
, name
))
3887 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3893 /* Before we invoke realpath, which can get expensive when many
3894 files are involved, do a quick comparison of the basenames. */
3895 if (! basenames_may_differ
3896 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3899 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3900 if (compare_filenames_for_search (this_real_name
, name
))
3902 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3908 if (real_path
!= NULL
)
3910 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3911 gdb_assert (IS_ABSOLUTE_PATH (name
));
3912 if (this_real_name
!= NULL
3913 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3915 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3927 /* Struct used to manage iterating over all CUs looking for a symbol. */
3929 struct dw2_symtab_iterator
3931 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3932 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3933 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3934 int want_specific_block
;
3935 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3936 Unused if !WANT_SPECIFIC_BLOCK. */
3938 /* The kind of symbol we're looking for. */
3940 /* The list of CUs from the index entry of the symbol,
3941 or NULL if not found. */
3943 /* The next element in VEC to look at. */
3945 /* The number of elements in VEC, or zero if there is no match. */
3947 /* Have we seen a global version of the symbol?
3948 If so we can ignore all further global instances.
3949 This is to work around gold/15646, inefficient gold-generated
3954 /* Initialize the index symtab iterator ITER.
3955 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3956 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3959 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3960 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3961 int want_specific_block
,
3966 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3967 iter
->want_specific_block
= want_specific_block
;
3968 iter
->block_index
= block_index
;
3969 iter
->domain
= domain
;
3971 iter
->global_seen
= 0;
3973 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3975 /* index is NULL if OBJF_READNOW. */
3976 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3977 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3985 /* Return the next matching CU or NULL if there are no more. */
3987 static struct dwarf2_per_cu_data
*
3988 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3990 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3992 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3994 offset_type cu_index_and_attrs
=
3995 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3996 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3997 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3998 /* This value is only valid for index versions >= 7. */
3999 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4000 gdb_index_symbol_kind symbol_kind
=
4001 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4002 /* Only check the symbol attributes if they're present.
4003 Indices prior to version 7 don't record them,
4004 and indices >= 7 may elide them for certain symbols
4005 (gold does this). */
4007 (dwarf2_per_objfile
->index_table
->version
>= 7
4008 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4010 /* Don't crash on bad data. */
4011 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4012 + dwarf2_per_objfile
->all_type_units
.size ()))
4014 complaint (_(".gdb_index entry has bad CU index"
4016 objfile_name (dwarf2_per_objfile
->objfile
));
4020 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4022 /* Skip if already read in. */
4023 if (per_cu
->v
.quick
->compunit_symtab
)
4026 /* Check static vs global. */
4029 if (iter
->want_specific_block
4030 && want_static
!= is_static
)
4032 /* Work around gold/15646. */
4033 if (!is_static
&& iter
->global_seen
)
4036 iter
->global_seen
= 1;
4039 /* Only check the symbol's kind if it has one. */
4042 switch (iter
->domain
)
4045 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4046 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4047 /* Some types are also in VAR_DOMAIN. */
4048 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4052 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4056 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4071 static struct compunit_symtab
*
4072 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
4073 const char *name
, domain_enum domain
)
4075 struct compunit_symtab
*stab_best
= NULL
;
4076 struct dwarf2_per_objfile
*dwarf2_per_objfile
4077 = get_dwarf2_per_objfile (objfile
);
4079 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4081 struct dw2_symtab_iterator iter
;
4082 struct dwarf2_per_cu_data
*per_cu
;
4084 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 1, block_index
, domain
, name
);
4086 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4088 struct symbol
*sym
, *with_opaque
= NULL
;
4089 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4090 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4091 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4093 sym
= block_find_symbol (block
, name
, domain
,
4094 block_find_non_opaque_type_preferred
,
4097 /* Some caution must be observed with overloaded functions
4098 and methods, since the index will not contain any overload
4099 information (but NAME might contain it). */
4102 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4104 if (with_opaque
!= NULL
4105 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4108 /* Keep looking through other CUs. */
4115 dw2_print_stats (struct objfile
*objfile
)
4117 struct dwarf2_per_objfile
*dwarf2_per_objfile
4118 = get_dwarf2_per_objfile (objfile
);
4119 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4120 + dwarf2_per_objfile
->all_type_units
.size ());
4123 for (int i
= 0; i
< total
; ++i
)
4125 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4127 if (!per_cu
->v
.quick
->compunit_symtab
)
4130 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4131 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4134 /* This dumps minimal information about the index.
4135 It is called via "mt print objfiles".
4136 One use is to verify .gdb_index has been loaded by the
4137 gdb.dwarf2/gdb-index.exp testcase. */
4140 dw2_dump (struct objfile
*objfile
)
4142 struct dwarf2_per_objfile
*dwarf2_per_objfile
4143 = get_dwarf2_per_objfile (objfile
);
4145 gdb_assert (dwarf2_per_objfile
->using_index
);
4146 printf_filtered (".gdb_index:");
4147 if (dwarf2_per_objfile
->index_table
!= NULL
)
4149 printf_filtered (" version %d\n",
4150 dwarf2_per_objfile
->index_table
->version
);
4153 printf_filtered (" faked for \"readnow\"\n");
4154 printf_filtered ("\n");
4158 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4159 const char *func_name
)
4161 struct dwarf2_per_objfile
*dwarf2_per_objfile
4162 = get_dwarf2_per_objfile (objfile
);
4164 struct dw2_symtab_iterator iter
;
4165 struct dwarf2_per_cu_data
*per_cu
;
4167 /* Note: It doesn't matter what we pass for block_index here. */
4168 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
4171 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4172 dw2_instantiate_symtab (per_cu
, false);
4177 dw2_expand_all_symtabs (struct objfile
*objfile
)
4179 struct dwarf2_per_objfile
*dwarf2_per_objfile
4180 = get_dwarf2_per_objfile (objfile
);
4181 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4182 + dwarf2_per_objfile
->all_type_units
.size ());
4184 for (int i
= 0; i
< total_units
; ++i
)
4186 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4188 /* We don't want to directly expand a partial CU, because if we
4189 read it with the wrong language, then assertion failures can
4190 be triggered later on. See PR symtab/23010. So, tell
4191 dw2_instantiate_symtab to skip partial CUs -- any important
4192 partial CU will be read via DW_TAG_imported_unit anyway. */
4193 dw2_instantiate_symtab (per_cu
, true);
4198 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4199 const char *fullname
)
4201 struct dwarf2_per_objfile
*dwarf2_per_objfile
4202 = get_dwarf2_per_objfile (objfile
);
4204 /* We don't need to consider type units here.
4205 This is only called for examining code, e.g. expand_line_sal.
4206 There can be an order of magnitude (or more) more type units
4207 than comp units, and we avoid them if we can. */
4209 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4211 /* We only need to look at symtabs not already expanded. */
4212 if (per_cu
->v
.quick
->compunit_symtab
)
4215 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4216 if (file_data
== NULL
)
4219 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4221 const char *this_fullname
= file_data
->file_names
[j
];
4223 if (filename_cmp (this_fullname
, fullname
) == 0)
4225 dw2_instantiate_symtab (per_cu
, false);
4233 dw2_map_matching_symbols (struct objfile
*objfile
,
4234 const char * name
, domain_enum domain
,
4236 int (*callback
) (const struct block
*,
4237 struct symbol
*, void *),
4238 void *data
, symbol_name_match_type match
,
4239 symbol_compare_ftype
*ordered_compare
)
4241 /* Currently unimplemented; used for Ada. The function can be called if the
4242 current language is Ada for a non-Ada objfile using GNU index. As Ada
4243 does not look for non-Ada symbols this function should just return. */
4246 /* Symbol name matcher for .gdb_index names.
4248 Symbol names in .gdb_index have a few particularities:
4250 - There's no indication of which is the language of each symbol.
4252 Since each language has its own symbol name matching algorithm,
4253 and we don't know which language is the right one, we must match
4254 each symbol against all languages. This would be a potential
4255 performance problem if it were not mitigated by the
4256 mapped_index::name_components lookup table, which significantly
4257 reduces the number of times we need to call into this matcher,
4258 making it a non-issue.
4260 - Symbol names in the index have no overload (parameter)
4261 information. I.e., in C++, "foo(int)" and "foo(long)" both
4262 appear as "foo" in the index, for example.
4264 This means that the lookup names passed to the symbol name
4265 matcher functions must have no parameter information either
4266 because (e.g.) symbol search name "foo" does not match
4267 lookup-name "foo(int)" [while swapping search name for lookup
4270 class gdb_index_symbol_name_matcher
4273 /* Prepares the vector of comparison functions for LOOKUP_NAME. */
4274 gdb_index_symbol_name_matcher (const lookup_name_info
&lookup_name
);
4276 /* Walk all the matcher routines and match SYMBOL_NAME against them.
4277 Returns true if any matcher matches. */
4278 bool matches (const char *symbol_name
);
4281 /* A reference to the lookup name we're matching against. */
4282 const lookup_name_info
&m_lookup_name
;
4284 /* A vector holding all the different symbol name matchers, for all
4286 std::vector
<symbol_name_matcher_ftype
*> m_symbol_name_matcher_funcs
;
4289 gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
4290 (const lookup_name_info
&lookup_name
)
4291 : m_lookup_name (lookup_name
)
4293 /* Prepare the vector of comparison functions upfront, to avoid
4294 doing the same work for each symbol. Care is taken to avoid
4295 matching with the same matcher more than once if/when multiple
4296 languages use the same matcher function. */
4297 auto &matchers
= m_symbol_name_matcher_funcs
;
4298 matchers
.reserve (nr_languages
);
4300 matchers
.push_back (default_symbol_name_matcher
);
4302 for (int i
= 0; i
< nr_languages
; i
++)
4304 const language_defn
*lang
= language_def ((enum language
) i
);
4305 symbol_name_matcher_ftype
*name_matcher
4306 = get_symbol_name_matcher (lang
, m_lookup_name
);
4308 /* Don't insert the same comparison routine more than once.
4309 Note that we do this linear walk instead of a seemingly
4310 cheaper sorted insert, or use a std::set or something like
4311 that, because relative order of function addresses is not
4312 stable. This is not a problem in practice because the number
4313 of supported languages is low, and the cost here is tiny
4314 compared to the number of searches we'll do afterwards using
4316 if (name_matcher
!= default_symbol_name_matcher
4317 && (std::find (matchers
.begin (), matchers
.end (), name_matcher
)
4318 == matchers
.end ()))
4319 matchers
.push_back (name_matcher
);
4324 gdb_index_symbol_name_matcher::matches (const char *symbol_name
)
4326 for (auto matches_name
: m_symbol_name_matcher_funcs
)
4327 if (matches_name (symbol_name
, m_lookup_name
, NULL
))
4333 /* Starting from a search name, return the string that finds the upper
4334 bound of all strings that start with SEARCH_NAME in a sorted name
4335 list. Returns the empty string to indicate that the upper bound is
4336 the end of the list. */
4339 make_sort_after_prefix_name (const char *search_name
)
4341 /* When looking to complete "func", we find the upper bound of all
4342 symbols that start with "func" by looking for where we'd insert
4343 the closest string that would follow "func" in lexicographical
4344 order. Usually, that's "func"-with-last-character-incremented,
4345 i.e. "fund". Mind non-ASCII characters, though. Usually those
4346 will be UTF-8 multi-byte sequences, but we can't be certain.
4347 Especially mind the 0xff character, which is a valid character in
4348 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4349 rule out compilers allowing it in identifiers. Note that
4350 conveniently, strcmp/strcasecmp are specified to compare
4351 characters interpreted as unsigned char. So what we do is treat
4352 the whole string as a base 256 number composed of a sequence of
4353 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4354 to 0, and carries 1 to the following more-significant position.
4355 If the very first character in SEARCH_NAME ends up incremented
4356 and carries/overflows, then the upper bound is the end of the
4357 list. The string after the empty string is also the empty
4360 Some examples of this operation:
4362 SEARCH_NAME => "+1" RESULT
4366 "\xff" "a" "\xff" => "\xff" "b"
4371 Then, with these symbols for example:
4377 completing "func" looks for symbols between "func" and
4378 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4379 which finds "func" and "func1", but not "fund".
4383 funcÿ (Latin1 'ÿ' [0xff])
4387 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4388 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4392 ÿÿ (Latin1 'ÿ' [0xff])
4395 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4396 the end of the list.
4398 std::string after
= search_name
;
4399 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4401 if (!after
.empty ())
4402 after
.back () = (unsigned char) after
.back () + 1;
4406 /* See declaration. */
4408 std::pair
<std::vector
<name_component
>::const_iterator
,
4409 std::vector
<name_component
>::const_iterator
>
4410 mapped_index_base::find_name_components_bounds
4411 (const lookup_name_info
&lookup_name_without_params
) const
4414 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4417 = lookup_name_without_params
.cplus ().lookup_name ().c_str ();
4419 /* Comparison function object for lower_bound that matches against a
4420 given symbol name. */
4421 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4424 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4425 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4426 return name_cmp (elem_name
, name
) < 0;
4429 /* Comparison function object for upper_bound that matches against a
4430 given symbol name. */
4431 auto lookup_compare_upper
= [&] (const char *name
,
4432 const name_component
&elem
)
4434 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4435 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4436 return name_cmp (name
, elem_name
) < 0;
4439 auto begin
= this->name_components
.begin ();
4440 auto end
= this->name_components
.end ();
4442 /* Find the lower bound. */
4445 if (lookup_name_without_params
.completion_mode () && cplus
[0] == '\0')
4448 return std::lower_bound (begin
, end
, cplus
, lookup_compare_lower
);
4451 /* Find the upper bound. */
4454 if (lookup_name_without_params
.completion_mode ())
4456 /* In completion mode, we want UPPER to point past all
4457 symbols names that have the same prefix. I.e., with
4458 these symbols, and completing "func":
4460 function << lower bound
4462 other_function << upper bound
4464 We find the upper bound by looking for the insertion
4465 point of "func"-with-last-character-incremented,
4467 std::string after
= make_sort_after_prefix_name (cplus
);
4470 return std::lower_bound (lower
, end
, after
.c_str (),
4471 lookup_compare_lower
);
4474 return std::upper_bound (lower
, end
, cplus
, lookup_compare_upper
);
4477 return {lower
, upper
};
4480 /* See declaration. */
4483 mapped_index_base::build_name_components ()
4485 if (!this->name_components
.empty ())
4488 this->name_components_casing
= case_sensitivity
;
4490 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4492 /* The code below only knows how to break apart components of C++
4493 symbol names (and other languages that use '::' as
4494 namespace/module separator). If we add support for wild matching
4495 to some language that uses some other operator (E.g., Ada, Go and
4496 D use '.'), then we'll need to try splitting the symbol name
4497 according to that language too. Note that Ada does support wild
4498 matching, but doesn't currently support .gdb_index. */
4499 auto count
= this->symbol_name_count ();
4500 for (offset_type idx
= 0; idx
< count
; idx
++)
4502 if (this->symbol_name_slot_invalid (idx
))
4505 const char *name
= this->symbol_name_at (idx
);
4507 /* Add each name component to the name component table. */
4508 unsigned int previous_len
= 0;
4509 for (unsigned int current_len
= cp_find_first_component (name
);
4510 name
[current_len
] != '\0';
4511 current_len
+= cp_find_first_component (name
+ current_len
))
4513 gdb_assert (name
[current_len
] == ':');
4514 this->name_components
.push_back ({previous_len
, idx
});
4515 /* Skip the '::'. */
4517 previous_len
= current_len
;
4519 this->name_components
.push_back ({previous_len
, idx
});
4522 /* Sort name_components elements by name. */
4523 auto name_comp_compare
= [&] (const name_component
&left
,
4524 const name_component
&right
)
4526 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4527 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4529 const char *left_name
= left_qualified
+ left
.name_offset
;
4530 const char *right_name
= right_qualified
+ right
.name_offset
;
4532 return name_cmp (left_name
, right_name
) < 0;
4535 std::sort (this->name_components
.begin (),
4536 this->name_components
.end (),
4540 /* Helper for dw2_expand_symtabs_matching that works with a
4541 mapped_index_base instead of the containing objfile. This is split
4542 to a separate function in order to be able to unit test the
4543 name_components matching using a mock mapped_index_base. For each
4544 symbol name that matches, calls MATCH_CALLBACK, passing it the
4545 symbol's index in the mapped_index_base symbol table. */
4548 dw2_expand_symtabs_matching_symbol
4549 (mapped_index_base
&index
,
4550 const lookup_name_info
&lookup_name_in
,
4551 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4552 enum search_domain kind
,
4553 gdb::function_view
<void (offset_type
)> match_callback
)
4555 lookup_name_info lookup_name_without_params
4556 = lookup_name_in
.make_ignore_params ();
4557 gdb_index_symbol_name_matcher lookup_name_matcher
4558 (lookup_name_without_params
);
4560 /* Build the symbol name component sorted vector, if we haven't
4562 index
.build_name_components ();
4564 auto bounds
= index
.find_name_components_bounds (lookup_name_without_params
);
4566 /* Now for each symbol name in range, check to see if we have a name
4567 match, and if so, call the MATCH_CALLBACK callback. */
4569 /* The same symbol may appear more than once in the range though.
4570 E.g., if we're looking for symbols that complete "w", and we have
4571 a symbol named "w1::w2", we'll find the two name components for
4572 that same symbol in the range. To be sure we only call the
4573 callback once per symbol, we first collect the symbol name
4574 indexes that matched in a temporary vector and ignore
4576 std::vector
<offset_type
> matches
;
4577 matches
.reserve (std::distance (bounds
.first
, bounds
.second
));
4579 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4581 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4583 if (!lookup_name_matcher
.matches (qualified
)
4584 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4587 matches
.push_back (bounds
.first
->idx
);
4590 std::sort (matches
.begin (), matches
.end ());
4592 /* Finally call the callback, once per match. */
4594 for (offset_type idx
: matches
)
4598 match_callback (idx
);
4603 /* Above we use a type wider than idx's for 'prev', since 0 and
4604 (offset_type)-1 are both possible values. */
4605 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4610 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4612 /* A mock .gdb_index/.debug_names-like name index table, enough to
4613 exercise dw2_expand_symtabs_matching_symbol, which works with the
4614 mapped_index_base interface. Builds an index from the symbol list
4615 passed as parameter to the constructor. */
4616 class mock_mapped_index
: public mapped_index_base
4619 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4620 : m_symbol_table (symbols
)
4623 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4625 /* Return the number of names in the symbol table. */
4626 size_t symbol_name_count () const override
4628 return m_symbol_table
.size ();
4631 /* Get the name of the symbol at IDX in the symbol table. */
4632 const char *symbol_name_at (offset_type idx
) const override
4634 return m_symbol_table
[idx
];
4638 gdb::array_view
<const char *> m_symbol_table
;
4641 /* Convenience function that converts a NULL pointer to a "<null>"
4642 string, to pass to print routines. */
4645 string_or_null (const char *str
)
4647 return str
!= NULL
? str
: "<null>";
4650 /* Check if a lookup_name_info built from
4651 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4652 index. EXPECTED_LIST is the list of expected matches, in expected
4653 matching order. If no match expected, then an empty list is
4654 specified. Returns true on success. On failure prints a warning
4655 indicating the file:line that failed, and returns false. */
4658 check_match (const char *file
, int line
,
4659 mock_mapped_index
&mock_index
,
4660 const char *name
, symbol_name_match_type match_type
,
4661 bool completion_mode
,
4662 std::initializer_list
<const char *> expected_list
)
4664 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4666 bool matched
= true;
4668 auto mismatch
= [&] (const char *expected_str
,
4671 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4672 "expected=\"%s\", got=\"%s\"\n"),
4674 (match_type
== symbol_name_match_type::FULL
4676 name
, string_or_null (expected_str
), string_or_null (got
));
4680 auto expected_it
= expected_list
.begin ();
4681 auto expected_end
= expected_list
.end ();
4683 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4685 [&] (offset_type idx
)
4687 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4688 const char *expected_str
4689 = expected_it
== expected_end
? NULL
: *expected_it
++;
4691 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4692 mismatch (expected_str
, matched_name
);
4695 const char *expected_str
4696 = expected_it
== expected_end
? NULL
: *expected_it
++;
4697 if (expected_str
!= NULL
)
4698 mismatch (expected_str
, NULL
);
4703 /* The symbols added to the mock mapped_index for testing (in
4705 static const char *test_symbols
[] = {
4714 "ns2::tmpl<int>::foo2",
4715 "(anonymous namespace)::A::B::C",
4717 /* These are used to check that the increment-last-char in the
4718 matching algorithm for completion doesn't match "t1_fund" when
4719 completing "t1_func". */
4725 /* A UTF-8 name with multi-byte sequences to make sure that
4726 cp-name-parser understands this as a single identifier ("função"
4727 is "function" in PT). */
4730 /* \377 (0xff) is Latin1 'ÿ'. */
4733 /* \377 (0xff) is Latin1 'ÿ'. */
4737 /* A name with all sorts of complications. Starts with "z" to make
4738 it easier for the completion tests below. */
4739 #define Z_SYM_NAME \
4740 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4741 "::tuple<(anonymous namespace)::ui*, " \
4742 "std::default_delete<(anonymous namespace)::ui>, void>"
4747 /* Returns true if the mapped_index_base::find_name_component_bounds
4748 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4749 in completion mode. */
4752 check_find_bounds_finds (mapped_index_base
&index
,
4753 const char *search_name
,
4754 gdb::array_view
<const char *> expected_syms
)
4756 lookup_name_info
lookup_name (search_name
,
4757 symbol_name_match_type::FULL
, true);
4759 auto bounds
= index
.find_name_components_bounds (lookup_name
);
4761 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4762 if (distance
!= expected_syms
.size ())
4765 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4767 auto nc_elem
= bounds
.first
+ exp_elem
;
4768 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4769 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4776 /* Test the lower-level mapped_index::find_name_component_bounds
4780 test_mapped_index_find_name_component_bounds ()
4782 mock_mapped_index
mock_index (test_symbols
);
4784 mock_index
.build_name_components ();
4786 /* Test the lower-level mapped_index::find_name_component_bounds
4787 method in completion mode. */
4789 static const char *expected_syms
[] = {
4794 SELF_CHECK (check_find_bounds_finds (mock_index
,
4795 "t1_func", expected_syms
));
4798 /* Check that the increment-last-char in the name matching algorithm
4799 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4801 static const char *expected_syms1
[] = {
4805 SELF_CHECK (check_find_bounds_finds (mock_index
,
4806 "\377", expected_syms1
));
4808 static const char *expected_syms2
[] = {
4811 SELF_CHECK (check_find_bounds_finds (mock_index
,
4812 "\377\377", expected_syms2
));
4816 /* Test dw2_expand_symtabs_matching_symbol. */
4819 test_dw2_expand_symtabs_matching_symbol ()
4821 mock_mapped_index
mock_index (test_symbols
);
4823 /* We let all tests run until the end even if some fails, for debug
4825 bool any_mismatch
= false;
4827 /* Create the expected symbols list (an initializer_list). Needed
4828 because lists have commas, and we need to pass them to CHECK,
4829 which is a macro. */
4830 #define EXPECT(...) { __VA_ARGS__ }
4832 /* Wrapper for check_match that passes down the current
4833 __FILE__/__LINE__. */
4834 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4835 any_mismatch |= !check_match (__FILE__, __LINE__, \
4837 NAME, MATCH_TYPE, COMPLETION_MODE, \
4840 /* Identity checks. */
4841 for (const char *sym
: test_symbols
)
4843 /* Should be able to match all existing symbols. */
4844 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4847 /* Should be able to match all existing symbols with
4849 std::string with_params
= std::string (sym
) + "(int)";
4850 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4853 /* Should be able to match all existing symbols with
4854 parameters and qualifiers. */
4855 with_params
= std::string (sym
) + " ( int ) const";
4856 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4859 /* This should really find sym, but cp-name-parser.y doesn't
4860 know about lvalue/rvalue qualifiers yet. */
4861 with_params
= std::string (sym
) + " ( int ) &&";
4862 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4866 /* Check that the name matching algorithm for completion doesn't get
4867 confused with Latin1 'ÿ' / 0xff. */
4869 static const char str
[] = "\377";
4870 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4871 EXPECT ("\377", "\377\377123"));
4874 /* Check that the increment-last-char in the matching algorithm for
4875 completion doesn't match "t1_fund" when completing "t1_func". */
4877 static const char str
[] = "t1_func";
4878 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4879 EXPECT ("t1_func", "t1_func1"));
4882 /* Check that completion mode works at each prefix of the expected
4885 static const char str
[] = "function(int)";
4886 size_t len
= strlen (str
);
4889 for (size_t i
= 1; i
< len
; i
++)
4891 lookup
.assign (str
, i
);
4892 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4893 EXPECT ("function"));
4897 /* While "w" is a prefix of both components, the match function
4898 should still only be called once. */
4900 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4902 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4906 /* Same, with a "complicated" symbol. */
4908 static const char str
[] = Z_SYM_NAME
;
4909 size_t len
= strlen (str
);
4912 for (size_t i
= 1; i
< len
; i
++)
4914 lookup
.assign (str
, i
);
4915 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4916 EXPECT (Z_SYM_NAME
));
4920 /* In FULL mode, an incomplete symbol doesn't match. */
4922 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4926 /* A complete symbol with parameters matches any overload, since the
4927 index has no overload info. */
4929 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4930 EXPECT ("std::zfunction", "std::zfunction2"));
4931 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4932 EXPECT ("std::zfunction", "std::zfunction2"));
4933 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4934 EXPECT ("std::zfunction", "std::zfunction2"));
4937 /* Check that whitespace is ignored appropriately. A symbol with a
4938 template argument list. */
4940 static const char expected
[] = "ns::foo<int>";
4941 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4943 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4947 /* Check that whitespace is ignored appropriately. A symbol with a
4948 template argument list that includes a pointer. */
4950 static const char expected
[] = "ns::foo<char*>";
4951 /* Try both completion and non-completion modes. */
4952 static const bool completion_mode
[2] = {false, true};
4953 for (size_t i
= 0; i
< 2; i
++)
4955 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4956 completion_mode
[i
], EXPECT (expected
));
4957 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4958 completion_mode
[i
], EXPECT (expected
));
4960 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4961 completion_mode
[i
], EXPECT (expected
));
4962 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4963 completion_mode
[i
], EXPECT (expected
));
4968 /* Check method qualifiers are ignored. */
4969 static const char expected
[] = "ns::foo<char*>";
4970 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4971 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4972 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4973 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4974 CHECK_MATCH ("foo < char * > ( int ) const",
4975 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4976 CHECK_MATCH ("foo < char * > ( int ) &&",
4977 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4980 /* Test lookup names that don't match anything. */
4982 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4985 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4989 /* Some wild matching tests, exercising "(anonymous namespace)",
4990 which should not be confused with a parameter list. */
4992 static const char *syms
[] = {
4996 "A :: B :: C ( int )",
5001 for (const char *s
: syms
)
5003 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
5004 EXPECT ("(anonymous namespace)::A::B::C"));
5009 static const char expected
[] = "ns2::tmpl<int>::foo2";
5010 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
5012 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
5016 SELF_CHECK (!any_mismatch
);
5025 test_mapped_index_find_name_component_bounds ();
5026 test_dw2_expand_symtabs_matching_symbol ();
5029 }} // namespace selftests::dw2_expand_symtabs_matching
5031 #endif /* GDB_SELF_TEST */
5033 /* If FILE_MATCHER is NULL or if PER_CU has
5034 dwarf2_per_cu_quick_data::MARK set (see
5035 dw_expand_symtabs_matching_file_matcher), expand the CU and call
5036 EXPANSION_NOTIFY on it. */
5039 dw2_expand_symtabs_matching_one
5040 (struct dwarf2_per_cu_data
*per_cu
,
5041 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5042 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5044 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5046 bool symtab_was_null
5047 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5049 dw2_instantiate_symtab (per_cu
, false);
5051 if (expansion_notify
!= NULL
5053 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5054 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5058 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5059 matched, to expand corresponding CUs that were marked. IDX is the
5060 index of the symbol name that matched. */
5063 dw2_expand_marked_cus
5064 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5065 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5066 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5069 offset_type
*vec
, vec_len
, vec_idx
;
5070 bool global_seen
= false;
5071 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5073 vec
= (offset_type
*) (index
.constant_pool
5074 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5075 vec_len
= MAYBE_SWAP (vec
[0]);
5076 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5078 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5079 /* This value is only valid for index versions >= 7. */
5080 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5081 gdb_index_symbol_kind symbol_kind
=
5082 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5083 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5084 /* Only check the symbol attributes if they're present.
5085 Indices prior to version 7 don't record them,
5086 and indices >= 7 may elide them for certain symbols
5087 (gold does this). */
5090 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5092 /* Work around gold/15646. */
5095 if (!is_static
&& global_seen
)
5101 /* Only check the symbol's kind if it has one. */
5106 case VARIABLES_DOMAIN
:
5107 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5110 case FUNCTIONS_DOMAIN
:
5111 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5115 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5123 /* Don't crash on bad data. */
5124 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5125 + dwarf2_per_objfile
->all_type_units
.size ()))
5127 complaint (_(".gdb_index entry has bad CU index"
5129 objfile_name (dwarf2_per_objfile
->objfile
));
5133 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5134 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5139 /* If FILE_MATCHER is non-NULL, set all the
5140 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5141 that match FILE_MATCHER. */
5144 dw_expand_symtabs_matching_file_matcher
5145 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5146 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5148 if (file_matcher
== NULL
)
5151 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5153 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5155 NULL
, xcalloc
, xfree
));
5156 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5158 NULL
, xcalloc
, xfree
));
5160 /* The rule is CUs specify all the files, including those used by
5161 any TU, so there's no need to scan TUs here. */
5163 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5167 per_cu
->v
.quick
->mark
= 0;
5169 /* We only need to look at symtabs not already expanded. */
5170 if (per_cu
->v
.quick
->compunit_symtab
)
5173 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5174 if (file_data
== NULL
)
5177 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5179 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5181 per_cu
->v
.quick
->mark
= 1;
5185 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5187 const char *this_real_name
;
5189 if (file_matcher (file_data
->file_names
[j
], false))
5191 per_cu
->v
.quick
->mark
= 1;
5195 /* Before we invoke realpath, which can get expensive when many
5196 files are involved, do a quick comparison of the basenames. */
5197 if (!basenames_may_differ
5198 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5202 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5203 if (file_matcher (this_real_name
, false))
5205 per_cu
->v
.quick
->mark
= 1;
5210 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5211 ? visited_found
.get ()
5212 : visited_not_found
.get (),
5219 dw2_expand_symtabs_matching
5220 (struct objfile
*objfile
,
5221 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5222 const lookup_name_info
&lookup_name
,
5223 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5224 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5225 enum search_domain kind
)
5227 struct dwarf2_per_objfile
*dwarf2_per_objfile
5228 = get_dwarf2_per_objfile (objfile
);
5230 /* index_table is NULL if OBJF_READNOW. */
5231 if (!dwarf2_per_objfile
->index_table
)
5234 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5236 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5238 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5240 kind
, [&] (offset_type idx
)
5242 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5243 expansion_notify
, kind
);
5247 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5250 static struct compunit_symtab
*
5251 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5256 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5257 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5260 if (cust
->includes
== NULL
)
5263 for (i
= 0; cust
->includes
[i
]; ++i
)
5265 struct compunit_symtab
*s
= cust
->includes
[i
];
5267 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5275 static struct compunit_symtab
*
5276 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5277 struct bound_minimal_symbol msymbol
,
5279 struct obj_section
*section
,
5282 struct dwarf2_per_cu_data
*data
;
5283 struct compunit_symtab
*result
;
5285 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5288 CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
5289 SECT_OFF_TEXT (objfile
));
5290 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5291 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5295 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5296 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5297 paddress (get_objfile_arch (objfile
), pc
));
5300 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5303 gdb_assert (result
!= NULL
);
5308 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5309 void *data
, int need_fullname
)
5311 struct dwarf2_per_objfile
*dwarf2_per_objfile
5312 = get_dwarf2_per_objfile (objfile
);
5314 if (!dwarf2_per_objfile
->filenames_cache
)
5316 dwarf2_per_objfile
->filenames_cache
.emplace ();
5318 htab_up
visited (htab_create_alloc (10,
5319 htab_hash_pointer
, htab_eq_pointer
,
5320 NULL
, xcalloc
, xfree
));
5322 /* The rule is CUs specify all the files, including those used
5323 by any TU, so there's no need to scan TUs here. We can
5324 ignore file names coming from already-expanded CUs. */
5326 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5328 if (per_cu
->v
.quick
->compunit_symtab
)
5330 void **slot
= htab_find_slot (visited
.get (),
5331 per_cu
->v
.quick
->file_names
,
5334 *slot
= per_cu
->v
.quick
->file_names
;
5338 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5340 /* We only need to look at symtabs not already expanded. */
5341 if (per_cu
->v
.quick
->compunit_symtab
)
5344 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5345 if (file_data
== NULL
)
5348 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5351 /* Already visited. */
5356 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5358 const char *filename
= file_data
->file_names
[j
];
5359 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5364 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5366 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5369 this_real_name
= gdb_realpath (filename
);
5370 (*fun
) (filename
, this_real_name
.get (), data
);
5375 dw2_has_symbols (struct objfile
*objfile
)
5380 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5383 dw2_find_last_source_symtab
,
5384 dw2_forget_cached_source_info
,
5385 dw2_map_symtabs_matching_filename
,
5389 dw2_expand_symtabs_for_function
,
5390 dw2_expand_all_symtabs
,
5391 dw2_expand_symtabs_with_fullname
,
5392 dw2_map_matching_symbols
,
5393 dw2_expand_symtabs_matching
,
5394 dw2_find_pc_sect_compunit_symtab
,
5396 dw2_map_symbol_filenames
5399 /* DWARF-5 debug_names reader. */
5401 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5402 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5404 /* A helper function that reads the .debug_names section in SECTION
5405 and fills in MAP. FILENAME is the name of the file containing the
5406 section; it is used for error reporting.
5408 Returns true if all went well, false otherwise. */
5411 read_debug_names_from_section (struct objfile
*objfile
,
5412 const char *filename
,
5413 struct dwarf2_section_info
*section
,
5414 mapped_debug_names
&map
)
5416 if (dwarf2_section_empty_p (section
))
5419 /* Older elfutils strip versions could keep the section in the main
5420 executable while splitting it for the separate debug info file. */
5421 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5424 dwarf2_read_section (objfile
, section
);
5426 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5428 const gdb_byte
*addr
= section
->buffer
;
5430 bfd
*const abfd
= get_section_bfd_owner (section
);
5432 unsigned int bytes_read
;
5433 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5436 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5437 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5438 if (bytes_read
+ length
!= section
->size
)
5440 /* There may be multiple per-CU indices. */
5441 warning (_("Section .debug_names in %s length %s does not match "
5442 "section length %s, ignoring .debug_names."),
5443 filename
, plongest (bytes_read
+ length
),
5444 pulongest (section
->size
));
5448 /* The version number. */
5449 uint16_t version
= read_2_bytes (abfd
, addr
);
5453 warning (_("Section .debug_names in %s has unsupported version %d, "
5454 "ignoring .debug_names."),
5460 uint16_t padding
= read_2_bytes (abfd
, addr
);
5464 warning (_("Section .debug_names in %s has unsupported padding %d, "
5465 "ignoring .debug_names."),
5470 /* comp_unit_count - The number of CUs in the CU list. */
5471 map
.cu_count
= read_4_bytes (abfd
, addr
);
5474 /* local_type_unit_count - The number of TUs in the local TU
5476 map
.tu_count
= read_4_bytes (abfd
, addr
);
5479 /* foreign_type_unit_count - The number of TUs in the foreign TU
5481 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5483 if (foreign_tu_count
!= 0)
5485 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5486 "ignoring .debug_names."),
5487 filename
, static_cast<unsigned long> (foreign_tu_count
));
5491 /* bucket_count - The number of hash buckets in the hash lookup
5493 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5496 /* name_count - The number of unique names in the index. */
5497 map
.name_count
= read_4_bytes (abfd
, addr
);
5500 /* abbrev_table_size - The size in bytes of the abbreviations
5502 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5505 /* augmentation_string_size - The size in bytes of the augmentation
5506 string. This value is rounded up to a multiple of 4. */
5507 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5509 map
.augmentation_is_gdb
= ((augmentation_string_size
5510 == sizeof (dwarf5_augmentation
))
5511 && memcmp (addr
, dwarf5_augmentation
,
5512 sizeof (dwarf5_augmentation
)) == 0);
5513 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5514 addr
+= augmentation_string_size
;
5517 map
.cu_table_reordered
= addr
;
5518 addr
+= map
.cu_count
* map
.offset_size
;
5520 /* List of Local TUs */
5521 map
.tu_table_reordered
= addr
;
5522 addr
+= map
.tu_count
* map
.offset_size
;
5524 /* Hash Lookup Table */
5525 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5526 addr
+= map
.bucket_count
* 4;
5527 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5528 addr
+= map
.name_count
* 4;
5531 map
.name_table_string_offs_reordered
= addr
;
5532 addr
+= map
.name_count
* map
.offset_size
;
5533 map
.name_table_entry_offs_reordered
= addr
;
5534 addr
+= map
.name_count
* map
.offset_size
;
5536 const gdb_byte
*abbrev_table_start
= addr
;
5539 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5544 const auto insertpair
5545 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5546 if (!insertpair
.second
)
5548 warning (_("Section .debug_names in %s has duplicate index %s, "
5549 "ignoring .debug_names."),
5550 filename
, pulongest (index_num
));
5553 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5554 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5559 mapped_debug_names::index_val::attr attr
;
5560 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5562 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5564 if (attr
.form
== DW_FORM_implicit_const
)
5566 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5570 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5572 indexval
.attr_vec
.push_back (std::move (attr
));
5575 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5577 warning (_("Section .debug_names in %s has abbreviation_table "
5578 "of size %zu vs. written as %u, ignoring .debug_names."),
5579 filename
, addr
- abbrev_table_start
, abbrev_table_size
);
5582 map
.entry_pool
= addr
;
5587 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5591 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5592 const mapped_debug_names
&map
,
5593 dwarf2_section_info
§ion
,
5596 sect_offset sect_off_prev
;
5597 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5599 sect_offset sect_off_next
;
5600 if (i
< map
.cu_count
)
5603 = (sect_offset
) (extract_unsigned_integer
5604 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5606 map
.dwarf5_byte_order
));
5609 sect_off_next
= (sect_offset
) section
.size
;
5612 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5613 dwarf2_per_cu_data
*per_cu
5614 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5615 sect_off_prev
, length
);
5616 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5618 sect_off_prev
= sect_off_next
;
5622 /* Read the CU list from the mapped index, and use it to create all
5623 the CU objects for this dwarf2_per_objfile. */
5626 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5627 const mapped_debug_names
&map
,
5628 const mapped_debug_names
&dwz_map
)
5630 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5631 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5633 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5634 dwarf2_per_objfile
->info
,
5635 false /* is_dwz */);
5637 if (dwz_map
.cu_count
== 0)
5640 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5641 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5645 /* Read .debug_names. If everything went ok, initialize the "quick"
5646 elements of all the CUs and return true. Otherwise, return false. */
5649 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5651 std::unique_ptr
<mapped_debug_names
> map
5652 (new mapped_debug_names (dwarf2_per_objfile
));
5653 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5654 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5656 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5657 &dwarf2_per_objfile
->debug_names
,
5661 /* Don't use the index if it's empty. */
5662 if (map
->name_count
== 0)
5665 /* If there is a .dwz file, read it so we can get its CU list as
5667 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5670 if (!read_debug_names_from_section (objfile
,
5671 bfd_get_filename (dwz
->dwz_bfd
),
5672 &dwz
->debug_names
, dwz_map
))
5674 warning (_("could not read '.debug_names' section from %s; skipping"),
5675 bfd_get_filename (dwz
->dwz_bfd
));
5680 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5682 if (map
->tu_count
!= 0)
5684 /* We can only handle a single .debug_types when we have an
5686 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
5689 dwarf2_section_info
*section
= VEC_index (dwarf2_section_info_def
,
5690 dwarf2_per_objfile
->types
, 0);
5692 create_signatured_type_table_from_debug_names
5693 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5696 create_addrmap_from_aranges (dwarf2_per_objfile
,
5697 &dwarf2_per_objfile
->debug_aranges
);
5699 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5700 dwarf2_per_objfile
->using_index
= 1;
5701 dwarf2_per_objfile
->quick_file_names_table
=
5702 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5707 /* Type used to manage iterating over all CUs looking for a symbol for
5710 class dw2_debug_names_iterator
5713 /* If WANT_SPECIFIC_BLOCK is true, only look for symbols in block
5714 BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
5715 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5716 bool want_specific_block
,
5717 block_enum block_index
, domain_enum domain
,
5719 : m_map (map
), m_want_specific_block (want_specific_block
),
5720 m_block_index (block_index
), m_domain (domain
),
5721 m_addr (find_vec_in_debug_names (map
, name
))
5724 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5725 search_domain search
, uint32_t namei
)
5728 m_addr (find_vec_in_debug_names (map
, namei
))
5731 /* Return the next matching CU or NULL if there are no more. */
5732 dwarf2_per_cu_data
*next ();
5735 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5737 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5740 /* The internalized form of .debug_names. */
5741 const mapped_debug_names
&m_map
;
5743 /* If true, only look for symbols that match BLOCK_INDEX. */
5744 const bool m_want_specific_block
= false;
5746 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
5747 Unused if !WANT_SPECIFIC_BLOCK - FIRST_LOCAL_BLOCK is an invalid
5749 const block_enum m_block_index
= FIRST_LOCAL_BLOCK
;
5751 /* The kind of symbol we're looking for. */
5752 const domain_enum m_domain
= UNDEF_DOMAIN
;
5753 const search_domain m_search
= ALL_DOMAIN
;
5755 /* The list of CUs from the index entry of the symbol, or NULL if
5757 const gdb_byte
*m_addr
;
5761 mapped_debug_names::namei_to_name (uint32_t namei
) const
5763 const ULONGEST namei_string_offs
5764 = extract_unsigned_integer ((name_table_string_offs_reordered
5765 + namei
* offset_size
),
5768 return read_indirect_string_at_offset
5769 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5772 /* Find a slot in .debug_names for the object named NAME. If NAME is
5773 found, return pointer to its pool data. If NAME cannot be found,
5777 dw2_debug_names_iterator::find_vec_in_debug_names
5778 (const mapped_debug_names
&map
, const char *name
)
5780 int (*cmp
) (const char *, const char *);
5782 if (current_language
->la_language
== language_cplus
5783 || current_language
->la_language
== language_fortran
5784 || current_language
->la_language
== language_d
)
5786 /* NAME is already canonical. Drop any qualifiers as
5787 .debug_names does not contain any. */
5789 if (strchr (name
, '(') != NULL
)
5791 gdb::unique_xmalloc_ptr
<char> without_params
5792 = cp_remove_params (name
);
5794 if (without_params
!= NULL
)
5796 name
= without_params
.get();
5801 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5803 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5805 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5806 (map
.bucket_table_reordered
5807 + (full_hash
% map
.bucket_count
)), 4,
5808 map
.dwarf5_byte_order
);
5812 if (namei
>= map
.name_count
)
5814 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5816 namei
, map
.name_count
,
5817 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5823 const uint32_t namei_full_hash
5824 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5825 (map
.hash_table_reordered
+ namei
), 4,
5826 map
.dwarf5_byte_order
);
5827 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5830 if (full_hash
== namei_full_hash
)
5832 const char *const namei_string
= map
.namei_to_name (namei
);
5834 #if 0 /* An expensive sanity check. */
5835 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5837 complaint (_("Wrong .debug_names hash for string at index %u "
5839 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5844 if (cmp (namei_string
, name
) == 0)
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
;
5855 if (namei
>= map
.name_count
)
5861 dw2_debug_names_iterator::find_vec_in_debug_names
5862 (const mapped_debug_names
&map
, uint32_t namei
)
5864 if (namei
>= map
.name_count
)
5866 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5868 namei
, map
.name_count
,
5869 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5873 const ULONGEST namei_entry_offs
5874 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5875 + namei
* map
.offset_size
),
5876 map
.offset_size
, map
.dwarf5_byte_order
);
5877 return map
.entry_pool
+ namei_entry_offs
;
5880 /* See dw2_debug_names_iterator. */
5882 dwarf2_per_cu_data
*
5883 dw2_debug_names_iterator::next ()
5888 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5889 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5890 bfd
*const abfd
= objfile
->obfd
;
5894 unsigned int bytes_read
;
5895 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5896 m_addr
+= bytes_read
;
5900 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5901 if (indexval_it
== m_map
.abbrev_map
.cend ())
5903 complaint (_("Wrong .debug_names undefined abbrev code %s "
5905 pulongest (abbrev
), objfile_name (objfile
));
5908 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5909 bool have_is_static
= false;
5911 dwarf2_per_cu_data
*per_cu
= NULL
;
5912 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5917 case DW_FORM_implicit_const
:
5918 ull
= attr
.implicit_const
;
5920 case DW_FORM_flag_present
:
5924 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5925 m_addr
+= bytes_read
;
5928 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5929 dwarf_form_name (attr
.form
),
5930 objfile_name (objfile
));
5933 switch (attr
.dw_idx
)
5935 case DW_IDX_compile_unit
:
5936 /* Don't crash on bad data. */
5937 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5939 complaint (_(".debug_names entry has bad CU index %s"
5942 objfile_name (dwarf2_per_objfile
->objfile
));
5945 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5947 case DW_IDX_type_unit
:
5948 /* Don't crash on bad data. */
5949 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5951 complaint (_(".debug_names entry has bad TU index %s"
5954 objfile_name (dwarf2_per_objfile
->objfile
));
5957 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5959 case DW_IDX_GNU_internal
:
5960 if (!m_map
.augmentation_is_gdb
)
5962 have_is_static
= true;
5965 case DW_IDX_GNU_external
:
5966 if (!m_map
.augmentation_is_gdb
)
5968 have_is_static
= true;
5974 /* Skip if already read in. */
5975 if (per_cu
->v
.quick
->compunit_symtab
)
5978 /* Check static vs global. */
5981 const bool want_static
= m_block_index
!= GLOBAL_BLOCK
;
5982 if (m_want_specific_block
&& want_static
!= is_static
)
5986 /* Match dw2_symtab_iter_next, symbol_kind
5987 and debug_names::psymbol_tag. */
5991 switch (indexval
.dwarf_tag
)
5993 case DW_TAG_variable
:
5994 case DW_TAG_subprogram
:
5995 /* Some types are also in VAR_DOMAIN. */
5996 case DW_TAG_typedef
:
5997 case DW_TAG_structure_type
:
6004 switch (indexval
.dwarf_tag
)
6006 case DW_TAG_typedef
:
6007 case DW_TAG_structure_type
:
6014 switch (indexval
.dwarf_tag
)
6017 case DW_TAG_variable
:
6027 /* Match dw2_expand_symtabs_matching, symbol_kind and
6028 debug_names::psymbol_tag. */
6031 case VARIABLES_DOMAIN
:
6032 switch (indexval
.dwarf_tag
)
6034 case DW_TAG_variable
:
6040 case FUNCTIONS_DOMAIN
:
6041 switch (indexval
.dwarf_tag
)
6043 case DW_TAG_subprogram
:
6050 switch (indexval
.dwarf_tag
)
6052 case DW_TAG_typedef
:
6053 case DW_TAG_structure_type
:
6066 static struct compunit_symtab
*
6067 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, int block_index_int
,
6068 const char *name
, domain_enum domain
)
6070 const block_enum block_index
= static_cast<block_enum
> (block_index_int
);
6071 struct dwarf2_per_objfile
*dwarf2_per_objfile
6072 = get_dwarf2_per_objfile (objfile
);
6074 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6077 /* index is NULL if OBJF_READNOW. */
6080 const auto &map
= *mapp
;
6082 dw2_debug_names_iterator
iter (map
, true /* want_specific_block */,
6083 block_index
, domain
, name
);
6085 struct compunit_symtab
*stab_best
= NULL
;
6086 struct dwarf2_per_cu_data
*per_cu
;
6087 while ((per_cu
= iter
.next ()) != NULL
)
6089 struct symbol
*sym
, *with_opaque
= NULL
;
6090 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6091 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6092 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6094 sym
= block_find_symbol (block
, name
, domain
,
6095 block_find_non_opaque_type_preferred
,
6098 /* Some caution must be observed with overloaded functions and
6099 methods, since the index will not contain any overload
6100 information (but NAME might contain it). */
6103 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6105 if (with_opaque
!= NULL
6106 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6109 /* Keep looking through other CUs. */
6115 /* This dumps minimal information about .debug_names. It is called
6116 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6117 uses this to verify that .debug_names has been loaded. */
6120 dw2_debug_names_dump (struct objfile
*objfile
)
6122 struct dwarf2_per_objfile
*dwarf2_per_objfile
6123 = get_dwarf2_per_objfile (objfile
);
6125 gdb_assert (dwarf2_per_objfile
->using_index
);
6126 printf_filtered (".debug_names:");
6127 if (dwarf2_per_objfile
->debug_names_table
)
6128 printf_filtered (" exists\n");
6130 printf_filtered (" faked for \"readnow\"\n");
6131 printf_filtered ("\n");
6135 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6136 const char *func_name
)
6138 struct dwarf2_per_objfile
*dwarf2_per_objfile
6139 = get_dwarf2_per_objfile (objfile
);
6141 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6142 if (dwarf2_per_objfile
->debug_names_table
)
6144 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6146 /* Note: It doesn't matter what we pass for block_index here. */
6147 dw2_debug_names_iterator
iter (map
, false /* want_specific_block */,
6148 GLOBAL_BLOCK
, VAR_DOMAIN
, func_name
);
6150 struct dwarf2_per_cu_data
*per_cu
;
6151 while ((per_cu
= iter
.next ()) != NULL
)
6152 dw2_instantiate_symtab (per_cu
, false);
6157 dw2_debug_names_expand_symtabs_matching
6158 (struct objfile
*objfile
,
6159 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6160 const lookup_name_info
&lookup_name
,
6161 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6162 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6163 enum search_domain kind
)
6165 struct dwarf2_per_objfile
*dwarf2_per_objfile
6166 = get_dwarf2_per_objfile (objfile
);
6168 /* debug_names_table is NULL if OBJF_READNOW. */
6169 if (!dwarf2_per_objfile
->debug_names_table
)
6172 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6174 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6176 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6178 kind
, [&] (offset_type namei
)
6180 /* The name was matched, now expand corresponding CUs that were
6182 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6184 struct dwarf2_per_cu_data
*per_cu
;
6185 while ((per_cu
= iter
.next ()) != NULL
)
6186 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6191 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6194 dw2_find_last_source_symtab
,
6195 dw2_forget_cached_source_info
,
6196 dw2_map_symtabs_matching_filename
,
6197 dw2_debug_names_lookup_symbol
,
6199 dw2_debug_names_dump
,
6200 dw2_debug_names_expand_symtabs_for_function
,
6201 dw2_expand_all_symtabs
,
6202 dw2_expand_symtabs_with_fullname
,
6203 dw2_map_matching_symbols
,
6204 dw2_debug_names_expand_symtabs_matching
,
6205 dw2_find_pc_sect_compunit_symtab
,
6207 dw2_map_symbol_filenames
6210 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6211 to either a dwarf2_per_objfile or dwz_file object. */
6213 template <typename T
>
6214 static gdb::array_view
<const gdb_byte
>
6215 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6217 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6219 if (dwarf2_section_empty_p (section
))
6222 /* Older elfutils strip versions could keep the section in the main
6223 executable while splitting it for the separate debug info file. */
6224 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
6227 dwarf2_read_section (obj
, section
);
6229 /* dwarf2_section_info::size is a bfd_size_type, while
6230 gdb::array_view works with size_t. On 32-bit hosts, with
6231 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6232 is 32-bit. So we need an explicit narrowing conversion here.
6233 This is fine, because it's impossible to allocate or mmap an
6234 array/buffer larger than what size_t can represent. */
6235 return gdb::make_array_view (section
->buffer
, section
->size
);
6238 /* Lookup the index cache for the contents of the index associated to
6241 static gdb::array_view
<const gdb_byte
>
6242 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6244 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6245 if (build_id
== nullptr)
6248 return global_index_cache
.lookup_gdb_index (build_id
,
6249 &dwarf2_obj
->index_cache_res
);
6252 /* Same as the above, but for DWZ. */
6254 static gdb::array_view
<const gdb_byte
>
6255 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6257 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6258 if (build_id
== nullptr)
6261 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6264 /* See symfile.h. */
6267 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6269 struct dwarf2_per_objfile
*dwarf2_per_objfile
6270 = get_dwarf2_per_objfile (objfile
);
6272 /* If we're about to read full symbols, don't bother with the
6273 indices. In this case we also don't care if some other debug
6274 format is making psymtabs, because they are all about to be
6276 if ((objfile
->flags
& OBJF_READNOW
))
6278 dwarf2_per_objfile
->using_index
= 1;
6279 create_all_comp_units (dwarf2_per_objfile
);
6280 create_all_type_units (dwarf2_per_objfile
);
6281 dwarf2_per_objfile
->quick_file_names_table
6282 = create_quick_file_names_table
6283 (dwarf2_per_objfile
->all_comp_units
.size ());
6285 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6286 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6288 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6290 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6291 struct dwarf2_per_cu_quick_data
);
6294 /* Return 1 so that gdb sees the "quick" functions. However,
6295 these functions will be no-ops because we will have expanded
6297 *index_kind
= dw_index_kind::GDB_INDEX
;
6301 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6303 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6307 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6308 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6309 get_gdb_index_contents_from_section
<dwz_file
>))
6311 *index_kind
= dw_index_kind::GDB_INDEX
;
6315 /* ... otherwise, try to find the index in the index cache. */
6316 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6317 get_gdb_index_contents_from_cache
,
6318 get_gdb_index_contents_from_cache_dwz
))
6320 global_index_cache
.hit ();
6321 *index_kind
= dw_index_kind::GDB_INDEX
;
6325 global_index_cache
.miss ();
6331 /* Build a partial symbol table. */
6334 dwarf2_build_psymtabs (struct objfile
*objfile
)
6336 struct dwarf2_per_objfile
*dwarf2_per_objfile
6337 = get_dwarf2_per_objfile (objfile
);
6339 init_psymbol_list (objfile
, 1024);
6343 /* This isn't really ideal: all the data we allocate on the
6344 objfile's obstack is still uselessly kept around. However,
6345 freeing it seems unsafe. */
6346 psymtab_discarder
psymtabs (objfile
);
6347 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6350 /* (maybe) store an index in the cache. */
6351 global_index_cache
.store (dwarf2_per_objfile
);
6353 CATCH (except
, RETURN_MASK_ERROR
)
6355 exception_print (gdb_stderr
, except
);
6360 /* Return the total length of the CU described by HEADER. */
6363 get_cu_length (const struct comp_unit_head
*header
)
6365 return header
->initial_length_size
+ header
->length
;
6368 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6371 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6373 sect_offset bottom
= cu_header
->sect_off
;
6374 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6376 return sect_off
>= bottom
&& sect_off
< top
;
6379 /* Find the base address of the compilation unit for range lists and
6380 location lists. It will normally be specified by DW_AT_low_pc.
6381 In DWARF-3 draft 4, the base address could be overridden by
6382 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6383 compilation units with discontinuous ranges. */
6386 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6388 struct attribute
*attr
;
6391 cu
->base_address
= 0;
6393 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6396 cu
->base_address
= attr_value_as_address (attr
);
6401 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6404 cu
->base_address
= attr_value_as_address (attr
);
6410 /* Read in the comp unit header information from the debug_info at info_ptr.
6411 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6412 NOTE: This leaves members offset, first_die_offset to be filled in
6415 static const gdb_byte
*
6416 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6417 const gdb_byte
*info_ptr
,
6418 struct dwarf2_section_info
*section
,
6419 rcuh_kind section_kind
)
6422 unsigned int bytes_read
;
6423 const char *filename
= get_section_file_name (section
);
6424 bfd
*abfd
= get_section_bfd_owner (section
);
6426 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6427 cu_header
->initial_length_size
= bytes_read
;
6428 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6429 info_ptr
+= bytes_read
;
6430 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6431 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6432 error (_("Dwarf Error: wrong version in compilation unit header "
6433 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6434 cu_header
->version
, filename
);
6436 if (cu_header
->version
< 5)
6437 switch (section_kind
)
6439 case rcuh_kind::COMPILE
:
6440 cu_header
->unit_type
= DW_UT_compile
;
6442 case rcuh_kind::TYPE
:
6443 cu_header
->unit_type
= DW_UT_type
;
6446 internal_error (__FILE__
, __LINE__
,
6447 _("read_comp_unit_head: invalid section_kind"));
6451 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6452 (read_1_byte (abfd
, info_ptr
));
6454 switch (cu_header
->unit_type
)
6457 if (section_kind
!= rcuh_kind::COMPILE
)
6458 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6459 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
6463 section_kind
= rcuh_kind::TYPE
;
6466 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6467 "(is %d, should be %d or %d) [in module %s]"),
6468 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
6471 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6474 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6477 info_ptr
+= bytes_read
;
6478 if (cu_header
->version
< 5)
6480 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6483 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6484 if (signed_addr
< 0)
6485 internal_error (__FILE__
, __LINE__
,
6486 _("read_comp_unit_head: dwarf from non elf file"));
6487 cu_header
->signed_addr_p
= signed_addr
;
6489 if (section_kind
== rcuh_kind::TYPE
)
6491 LONGEST type_offset
;
6493 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6496 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6497 info_ptr
+= bytes_read
;
6498 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6499 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6500 error (_("Dwarf Error: Too big type_offset in compilation unit "
6501 "header (is %s) [in module %s]"), plongest (type_offset
),
6508 /* Helper function that returns the proper abbrev section for
6511 static struct dwarf2_section_info
*
6512 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6514 struct dwarf2_section_info
*abbrev
;
6515 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6517 if (this_cu
->is_dwz
)
6518 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6520 abbrev
= &dwarf2_per_objfile
->abbrev
;
6525 /* Subroutine of read_and_check_comp_unit_head and
6526 read_and_check_type_unit_head to simplify them.
6527 Perform various error checking on the header. */
6530 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6531 struct comp_unit_head
*header
,
6532 struct dwarf2_section_info
*section
,
6533 struct dwarf2_section_info
*abbrev_section
)
6535 const char *filename
= get_section_file_name (section
);
6537 if (to_underlying (header
->abbrev_sect_off
)
6538 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6539 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6540 "(offset %s + 6) [in module %s]"),
6541 sect_offset_str (header
->abbrev_sect_off
),
6542 sect_offset_str (header
->sect_off
),
6545 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6546 avoid potential 32-bit overflow. */
6547 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6549 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6550 "(offset %s + 0) [in module %s]"),
6551 header
->length
, sect_offset_str (header
->sect_off
),
6555 /* Read in a CU/TU header and perform some basic error checking.
6556 The contents of the header are stored in HEADER.
6557 The result is a pointer to the start of the first DIE. */
6559 static const gdb_byte
*
6560 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6561 struct comp_unit_head
*header
,
6562 struct dwarf2_section_info
*section
,
6563 struct dwarf2_section_info
*abbrev_section
,
6564 const gdb_byte
*info_ptr
,
6565 rcuh_kind section_kind
)
6567 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6569 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6571 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6573 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6575 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6581 /* Fetch the abbreviation table offset from a comp or type unit header. */
6584 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6585 struct dwarf2_section_info
*section
,
6586 sect_offset sect_off
)
6588 bfd
*abfd
= get_section_bfd_owner (section
);
6589 const gdb_byte
*info_ptr
;
6590 unsigned int initial_length_size
, offset_size
;
6593 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6594 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6595 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6596 offset_size
= initial_length_size
== 4 ? 4 : 8;
6597 info_ptr
+= initial_length_size
;
6599 version
= read_2_bytes (abfd
, info_ptr
);
6603 /* Skip unit type and address size. */
6607 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6610 /* Allocate a new partial symtab for file named NAME and mark this new
6611 partial symtab as being an include of PST. */
6614 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6615 struct objfile
*objfile
)
6617 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6619 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6621 /* It shares objfile->objfile_obstack. */
6622 subpst
->dirname
= pst
->dirname
;
6625 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6626 subpst
->dependencies
[0] = pst
;
6627 subpst
->number_of_dependencies
= 1;
6629 subpst
->read_symtab
= pst
->read_symtab
;
6631 /* No private part is necessary for include psymtabs. This property
6632 can be used to differentiate between such include psymtabs and
6633 the regular ones. */
6634 subpst
->read_symtab_private
= NULL
;
6637 /* Read the Line Number Program data and extract the list of files
6638 included by the source file represented by PST. Build an include
6639 partial symtab for each of these included files. */
6642 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6643 struct die_info
*die
,
6644 struct partial_symtab
*pst
)
6647 struct attribute
*attr
;
6649 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6651 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6653 return; /* No linetable, so no includes. */
6655 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6656 that we pass in the raw text_low here; that is ok because we're
6657 only decoding the line table to make include partial symtabs, and
6658 so the addresses aren't really used. */
6659 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6660 pst
->raw_text_low (), 1);
6664 hash_signatured_type (const void *item
)
6666 const struct signatured_type
*sig_type
6667 = (const struct signatured_type
*) item
;
6669 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6670 return sig_type
->signature
;
6674 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6676 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6677 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6679 return lhs
->signature
== rhs
->signature
;
6682 /* Allocate a hash table for signatured types. */
6685 allocate_signatured_type_table (struct objfile
*objfile
)
6687 return htab_create_alloc_ex (41,
6688 hash_signatured_type
,
6691 &objfile
->objfile_obstack
,
6692 hashtab_obstack_allocate
,
6693 dummy_obstack_deallocate
);
6696 /* A helper function to add a signatured type CU to a table. */
6699 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6701 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6702 std::vector
<signatured_type
*> *all_type_units
6703 = (std::vector
<signatured_type
*> *) datum
;
6705 all_type_units
->push_back (sigt
);
6710 /* A helper for create_debug_types_hash_table. Read types from SECTION
6711 and fill them into TYPES_HTAB. It will process only type units,
6712 therefore DW_UT_type. */
6715 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6716 struct dwo_file
*dwo_file
,
6717 dwarf2_section_info
*section
, htab_t
&types_htab
,
6718 rcuh_kind section_kind
)
6720 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6721 struct dwarf2_section_info
*abbrev_section
;
6723 const gdb_byte
*info_ptr
, *end_ptr
;
6725 abbrev_section
= (dwo_file
!= NULL
6726 ? &dwo_file
->sections
.abbrev
6727 : &dwarf2_per_objfile
->abbrev
);
6729 if (dwarf_read_debug
)
6730 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6731 get_section_name (section
),
6732 get_section_file_name (abbrev_section
));
6734 dwarf2_read_section (objfile
, section
);
6735 info_ptr
= section
->buffer
;
6737 if (info_ptr
== NULL
)
6740 /* We can't set abfd until now because the section may be empty or
6741 not present, in which case the bfd is unknown. */
6742 abfd
= get_section_bfd_owner (section
);
6744 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6745 because we don't need to read any dies: the signature is in the
6748 end_ptr
= info_ptr
+ section
->size
;
6749 while (info_ptr
< end_ptr
)
6751 struct signatured_type
*sig_type
;
6752 struct dwo_unit
*dwo_tu
;
6754 const gdb_byte
*ptr
= info_ptr
;
6755 struct comp_unit_head header
;
6756 unsigned int length
;
6758 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6760 /* Initialize it due to a false compiler warning. */
6761 header
.signature
= -1;
6762 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6764 /* We need to read the type's signature in order to build the hash
6765 table, but we don't need anything else just yet. */
6767 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6768 abbrev_section
, ptr
, section_kind
);
6770 length
= get_cu_length (&header
);
6772 /* Skip dummy type units. */
6773 if (ptr
>= info_ptr
+ length
6774 || peek_abbrev_code (abfd
, ptr
) == 0
6775 || header
.unit_type
!= DW_UT_type
)
6781 if (types_htab
== NULL
)
6784 types_htab
= allocate_dwo_unit_table (objfile
);
6786 types_htab
= allocate_signatured_type_table (objfile
);
6792 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6794 dwo_tu
->dwo_file
= dwo_file
;
6795 dwo_tu
->signature
= header
.signature
;
6796 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6797 dwo_tu
->section
= section
;
6798 dwo_tu
->sect_off
= sect_off
;
6799 dwo_tu
->length
= length
;
6803 /* N.B.: type_offset is not usable if this type uses a DWO file.
6804 The real type_offset is in the DWO file. */
6806 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6807 struct signatured_type
);
6808 sig_type
->signature
= header
.signature
;
6809 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6810 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6811 sig_type
->per_cu
.is_debug_types
= 1;
6812 sig_type
->per_cu
.section
= section
;
6813 sig_type
->per_cu
.sect_off
= sect_off
;
6814 sig_type
->per_cu
.length
= length
;
6817 slot
= htab_find_slot (types_htab
,
6818 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6820 gdb_assert (slot
!= NULL
);
6823 sect_offset dup_sect_off
;
6827 const struct dwo_unit
*dup_tu
6828 = (const struct dwo_unit
*) *slot
;
6830 dup_sect_off
= dup_tu
->sect_off
;
6834 const struct signatured_type
*dup_tu
6835 = (const struct signatured_type
*) *slot
;
6837 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6840 complaint (_("debug type entry at offset %s is duplicate to"
6841 " the entry at offset %s, signature %s"),
6842 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6843 hex_string (header
.signature
));
6845 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6847 if (dwarf_read_debug
> 1)
6848 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6849 sect_offset_str (sect_off
),
6850 hex_string (header
.signature
));
6856 /* Create the hash table of all entries in the .debug_types
6857 (or .debug_types.dwo) section(s).
6858 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6859 otherwise it is NULL.
6861 The result is a pointer to the hash table or NULL if there are no types.
6863 Note: This function processes DWO files only, not DWP files. */
6866 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6867 struct dwo_file
*dwo_file
,
6868 VEC (dwarf2_section_info_def
) *types
,
6872 struct dwarf2_section_info
*section
;
6874 if (VEC_empty (dwarf2_section_info_def
, types
))
6878 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
6880 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, section
,
6881 types_htab
, rcuh_kind::TYPE
);
6884 /* Create the hash table of all entries in the .debug_types section,
6885 and initialize all_type_units.
6886 The result is zero if there is an error (e.g. missing .debug_types section),
6887 otherwise non-zero. */
6890 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6892 htab_t types_htab
= NULL
;
6894 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6895 &dwarf2_per_objfile
->info
, types_htab
,
6896 rcuh_kind::COMPILE
);
6897 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6898 dwarf2_per_objfile
->types
, types_htab
);
6899 if (types_htab
== NULL
)
6901 dwarf2_per_objfile
->signatured_types
= NULL
;
6905 dwarf2_per_objfile
->signatured_types
= types_htab
;
6907 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6908 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6910 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6911 &dwarf2_per_objfile
->all_type_units
);
6916 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6917 If SLOT is non-NULL, it is the entry to use in the hash table.
6918 Otherwise we find one. */
6920 static struct signatured_type
*
6921 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6924 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6926 if (dwarf2_per_objfile
->all_type_units
.size ()
6927 == dwarf2_per_objfile
->all_type_units
.capacity ())
6928 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6930 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6931 struct signatured_type
);
6933 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6934 sig_type
->signature
= sig
;
6935 sig_type
->per_cu
.is_debug_types
= 1;
6936 if (dwarf2_per_objfile
->using_index
)
6938 sig_type
->per_cu
.v
.quick
=
6939 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6940 struct dwarf2_per_cu_quick_data
);
6945 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6948 gdb_assert (*slot
== NULL
);
6950 /* The rest of sig_type must be filled in by the caller. */
6954 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6955 Fill in SIG_ENTRY with DWO_ENTRY. */
6958 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6959 struct signatured_type
*sig_entry
,
6960 struct dwo_unit
*dwo_entry
)
6962 /* Make sure we're not clobbering something we don't expect to. */
6963 gdb_assert (! sig_entry
->per_cu
.queued
);
6964 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6965 if (dwarf2_per_objfile
->using_index
)
6967 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6968 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6971 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6972 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6973 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6974 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6975 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6977 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6978 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6979 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6980 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6981 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6982 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6983 sig_entry
->dwo_unit
= dwo_entry
;
6986 /* Subroutine of lookup_signatured_type.
6987 If we haven't read the TU yet, create the signatured_type data structure
6988 for a TU to be read in directly from a DWO file, bypassing the stub.
6989 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6990 using .gdb_index, then when reading a CU we want to stay in the DWO file
6991 containing that CU. Otherwise we could end up reading several other DWO
6992 files (due to comdat folding) to process the transitive closure of all the
6993 mentioned TUs, and that can be slow. The current DWO file will have every
6994 type signature that it needs.
6995 We only do this for .gdb_index because in the psymtab case we already have
6996 to read all the DWOs to build the type unit groups. */
6998 static struct signatured_type
*
6999 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7001 struct dwarf2_per_objfile
*dwarf2_per_objfile
7002 = cu
->per_cu
->dwarf2_per_objfile
;
7003 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7004 struct dwo_file
*dwo_file
;
7005 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7006 struct signatured_type find_sig_entry
, *sig_entry
;
7009 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7011 /* If TU skeletons have been removed then we may not have read in any
7013 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7015 dwarf2_per_objfile
->signatured_types
7016 = allocate_signatured_type_table (objfile
);
7019 /* We only ever need to read in one copy of a signatured type.
7020 Use the global signatured_types array to do our own comdat-folding
7021 of types. If this is the first time we're reading this TU, and
7022 the TU has an entry in .gdb_index, replace the recorded data from
7023 .gdb_index with this TU. */
7025 find_sig_entry
.signature
= sig
;
7026 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7027 &find_sig_entry
, INSERT
);
7028 sig_entry
= (struct signatured_type
*) *slot
;
7030 /* We can get here with the TU already read, *or* in the process of being
7031 read. Don't reassign the global entry to point to this DWO if that's
7032 the case. Also note that if the TU is already being read, it may not
7033 have come from a DWO, the program may be a mix of Fission-compiled
7034 code and non-Fission-compiled code. */
7036 /* Have we already tried to read this TU?
7037 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7038 needn't exist in the global table yet). */
7039 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7042 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7043 dwo_unit of the TU itself. */
7044 dwo_file
= cu
->dwo_unit
->dwo_file
;
7046 /* Ok, this is the first time we're reading this TU. */
7047 if (dwo_file
->tus
== NULL
)
7049 find_dwo_entry
.signature
= sig
;
7050 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7051 if (dwo_entry
== NULL
)
7054 /* If the global table doesn't have an entry for this TU, add one. */
7055 if (sig_entry
== NULL
)
7056 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7058 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7059 sig_entry
->per_cu
.tu_read
= 1;
7063 /* Subroutine of lookup_signatured_type.
7064 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7065 then try the DWP file. If the TU stub (skeleton) has been removed then
7066 it won't be in .gdb_index. */
7068 static struct signatured_type
*
7069 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7071 struct dwarf2_per_objfile
*dwarf2_per_objfile
7072 = cu
->per_cu
->dwarf2_per_objfile
;
7073 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7074 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7075 struct dwo_unit
*dwo_entry
;
7076 struct signatured_type find_sig_entry
, *sig_entry
;
7079 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7080 gdb_assert (dwp_file
!= NULL
);
7082 /* If TU skeletons have been removed then we may not have read in any
7084 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7086 dwarf2_per_objfile
->signatured_types
7087 = allocate_signatured_type_table (objfile
);
7090 find_sig_entry
.signature
= sig
;
7091 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7092 &find_sig_entry
, INSERT
);
7093 sig_entry
= (struct signatured_type
*) *slot
;
7095 /* Have we already tried to read this TU?
7096 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7097 needn't exist in the global table yet). */
7098 if (sig_entry
!= NULL
)
7101 if (dwp_file
->tus
== NULL
)
7103 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7104 sig
, 1 /* is_debug_types */);
7105 if (dwo_entry
== NULL
)
7108 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
);
7114 /* Lookup a signature based type for DW_FORM_ref_sig8.
7115 Returns NULL if signature SIG is not present in the table.
7116 It is up to the caller to complain about this. */
7118 static struct signatured_type
*
7119 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7121 struct dwarf2_per_objfile
*dwarf2_per_objfile
7122 = cu
->per_cu
->dwarf2_per_objfile
;
7125 && dwarf2_per_objfile
->using_index
)
7127 /* We're in a DWO/DWP file, and we're using .gdb_index.
7128 These cases require special processing. */
7129 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7130 return lookup_dwo_signatured_type (cu
, sig
);
7132 return lookup_dwp_signatured_type (cu
, sig
);
7136 struct signatured_type find_entry
, *entry
;
7138 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7140 find_entry
.signature
= sig
;
7141 entry
= ((struct signatured_type
*)
7142 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7147 /* Low level DIE reading support. */
7149 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7152 init_cu_die_reader (struct die_reader_specs
*reader
,
7153 struct dwarf2_cu
*cu
,
7154 struct dwarf2_section_info
*section
,
7155 struct dwo_file
*dwo_file
,
7156 struct abbrev_table
*abbrev_table
)
7158 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7159 reader
->abfd
= get_section_bfd_owner (section
);
7161 reader
->dwo_file
= dwo_file
;
7162 reader
->die_section
= section
;
7163 reader
->buffer
= section
->buffer
;
7164 reader
->buffer_end
= section
->buffer
+ section
->size
;
7165 reader
->comp_dir
= NULL
;
7166 reader
->abbrev_table
= abbrev_table
;
7169 /* Subroutine of init_cutu_and_read_dies to simplify it.
7170 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7171 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7174 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7175 from it to the DIE in the DWO. If NULL we are skipping the stub.
7176 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7177 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7178 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7179 STUB_COMP_DIR may be non-NULL.
7180 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7181 are filled in with the info of the DIE from the DWO file.
7182 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7183 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7184 kept around for at least as long as *RESULT_READER.
7186 The result is non-zero if a valid (non-dummy) DIE was found. */
7189 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7190 struct dwo_unit
*dwo_unit
,
7191 struct die_info
*stub_comp_unit_die
,
7192 const char *stub_comp_dir
,
7193 struct die_reader_specs
*result_reader
,
7194 const gdb_byte
**result_info_ptr
,
7195 struct die_info
**result_comp_unit_die
,
7196 int *result_has_children
,
7197 abbrev_table_up
*result_dwo_abbrev_table
)
7199 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7200 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7201 struct dwarf2_cu
*cu
= this_cu
->cu
;
7203 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7204 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7205 int i
,num_extra_attrs
;
7206 struct dwarf2_section_info
*dwo_abbrev_section
;
7207 struct attribute
*attr
;
7208 struct die_info
*comp_unit_die
;
7210 /* At most one of these may be provided. */
7211 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7213 /* These attributes aren't processed until later:
7214 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7215 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7216 referenced later. However, these attributes are found in the stub
7217 which we won't have later. In order to not impose this complication
7218 on the rest of the code, we read them here and copy them to the
7227 if (stub_comp_unit_die
!= NULL
)
7229 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7231 if (! this_cu
->is_debug_types
)
7232 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7233 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7234 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7235 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7236 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7238 /* There should be a DW_AT_addr_base attribute here (if needed).
7239 We need the value before we can process DW_FORM_GNU_addr_index. */
7241 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7243 cu
->addr_base
= DW_UNSND (attr
);
7245 /* There should be a DW_AT_ranges_base attribute here (if needed).
7246 We need the value before we can process DW_AT_ranges. */
7247 cu
->ranges_base
= 0;
7248 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7250 cu
->ranges_base
= DW_UNSND (attr
);
7252 else if (stub_comp_dir
!= NULL
)
7254 /* Reconstruct the comp_dir attribute to simplify the code below. */
7255 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7256 comp_dir
->name
= DW_AT_comp_dir
;
7257 comp_dir
->form
= DW_FORM_string
;
7258 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7259 DW_STRING (comp_dir
) = stub_comp_dir
;
7262 /* Set up for reading the DWO CU/TU. */
7263 cu
->dwo_unit
= dwo_unit
;
7264 dwarf2_section_info
*section
= dwo_unit
->section
;
7265 dwarf2_read_section (objfile
, section
);
7266 abfd
= get_section_bfd_owner (section
);
7267 begin_info_ptr
= info_ptr
= (section
->buffer
7268 + to_underlying (dwo_unit
->sect_off
));
7269 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7271 if (this_cu
->is_debug_types
)
7273 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7275 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7276 &cu
->header
, section
,
7278 info_ptr
, rcuh_kind::TYPE
);
7279 /* This is not an assert because it can be caused by bad debug info. */
7280 if (sig_type
->signature
!= cu
->header
.signature
)
7282 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7283 " TU at offset %s [in module %s]"),
7284 hex_string (sig_type
->signature
),
7285 hex_string (cu
->header
.signature
),
7286 sect_offset_str (dwo_unit
->sect_off
),
7287 bfd_get_filename (abfd
));
7289 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7290 /* For DWOs coming from DWP files, we don't know the CU length
7291 nor the type's offset in the TU until now. */
7292 dwo_unit
->length
= get_cu_length (&cu
->header
);
7293 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7295 /* Establish the type offset that can be used to lookup the type.
7296 For DWO files, we don't know it until now. */
7297 sig_type
->type_offset_in_section
7298 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7302 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7303 &cu
->header
, section
,
7305 info_ptr
, rcuh_kind::COMPILE
);
7306 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7307 /* For DWOs coming from DWP files, we don't know the CU length
7309 dwo_unit
->length
= get_cu_length (&cu
->header
);
7312 *result_dwo_abbrev_table
7313 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7314 cu
->header
.abbrev_sect_off
);
7315 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7316 result_dwo_abbrev_table
->get ());
7318 /* Read in the die, but leave space to copy over the attributes
7319 from the stub. This has the benefit of simplifying the rest of
7320 the code - all the work to maintain the illusion of a single
7321 DW_TAG_{compile,type}_unit DIE is done here. */
7322 num_extra_attrs
= ((stmt_list
!= NULL
)
7326 + (comp_dir
!= NULL
));
7327 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7328 result_has_children
, num_extra_attrs
);
7330 /* Copy over the attributes from the stub to the DIE we just read in. */
7331 comp_unit_die
= *result_comp_unit_die
;
7332 i
= comp_unit_die
->num_attrs
;
7333 if (stmt_list
!= NULL
)
7334 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7336 comp_unit_die
->attrs
[i
++] = *low_pc
;
7337 if (high_pc
!= NULL
)
7338 comp_unit_die
->attrs
[i
++] = *high_pc
;
7340 comp_unit_die
->attrs
[i
++] = *ranges
;
7341 if (comp_dir
!= NULL
)
7342 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7343 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7345 if (dwarf_die_debug
)
7347 fprintf_unfiltered (gdb_stdlog
,
7348 "Read die from %s@0x%x of %s:\n",
7349 get_section_name (section
),
7350 (unsigned) (begin_info_ptr
- section
->buffer
),
7351 bfd_get_filename (abfd
));
7352 dump_die (comp_unit_die
, dwarf_die_debug
);
7355 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7356 TUs by skipping the stub and going directly to the entry in the DWO file.
7357 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7358 to get it via circuitous means. Blech. */
7359 if (comp_dir
!= NULL
)
7360 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7362 /* Skip dummy compilation units. */
7363 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7364 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7367 *result_info_ptr
= info_ptr
;
7371 /* Subroutine of init_cutu_and_read_dies to simplify it.
7372 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7373 Returns NULL if the specified DWO unit cannot be found. */
7375 static struct dwo_unit
*
7376 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7377 struct die_info
*comp_unit_die
)
7379 struct dwarf2_cu
*cu
= this_cu
->cu
;
7381 struct dwo_unit
*dwo_unit
;
7382 const char *comp_dir
, *dwo_name
;
7384 gdb_assert (cu
!= NULL
);
7386 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7387 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7388 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7390 if (this_cu
->is_debug_types
)
7392 struct signatured_type
*sig_type
;
7394 /* Since this_cu is the first member of struct signatured_type,
7395 we can go from a pointer to one to a pointer to the other. */
7396 sig_type
= (struct signatured_type
*) this_cu
;
7397 signature
= sig_type
->signature
;
7398 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7402 struct attribute
*attr
;
7404 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7406 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7408 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7409 signature
= DW_UNSND (attr
);
7410 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7417 /* Subroutine of init_cutu_and_read_dies to simplify it.
7418 See it for a description of the parameters.
7419 Read a TU directly from a DWO file, bypassing the stub. */
7422 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7423 int use_existing_cu
, int keep
,
7424 die_reader_func_ftype
*die_reader_func
,
7427 std::unique_ptr
<dwarf2_cu
> new_cu
;
7428 struct signatured_type
*sig_type
;
7429 struct die_reader_specs reader
;
7430 const gdb_byte
*info_ptr
;
7431 struct die_info
*comp_unit_die
;
7433 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7435 /* Verify we can do the following downcast, and that we have the
7437 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7438 sig_type
= (struct signatured_type
*) this_cu
;
7439 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7441 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7443 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7444 /* There's no need to do the rereading_dwo_cu handling that
7445 init_cutu_and_read_dies does since we don't read the stub. */
7449 /* If !use_existing_cu, this_cu->cu must be NULL. */
7450 gdb_assert (this_cu
->cu
== NULL
);
7451 new_cu
.reset (new dwarf2_cu (this_cu
));
7454 /* A future optimization, if needed, would be to use an existing
7455 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7456 could share abbrev tables. */
7458 /* The abbreviation table used by READER, this must live at least as long as
7460 abbrev_table_up dwo_abbrev_table
;
7462 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7463 NULL
/* stub_comp_unit_die */,
7464 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7466 &comp_unit_die
, &has_children
,
7467 &dwo_abbrev_table
) == 0)
7473 /* All the "real" work is done here. */
7474 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7476 /* This duplicates the code in init_cutu_and_read_dies,
7477 but the alternative is making the latter more complex.
7478 This function is only for the special case of using DWO files directly:
7479 no point in overly complicating the general case just to handle this. */
7480 if (new_cu
!= NULL
&& keep
)
7482 /* Link this CU into read_in_chain. */
7483 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7484 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7485 /* The chain owns it now. */
7490 /* Initialize a CU (or TU) and read its DIEs.
7491 If the CU defers to a DWO file, read the DWO file as well.
7493 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7494 Otherwise the table specified in the comp unit header is read in and used.
7495 This is an optimization for when we already have the abbrev table.
7497 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7498 Otherwise, a new CU is allocated with xmalloc.
7500 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7501 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7503 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7504 linker) then DIE_READER_FUNC will not get called. */
7507 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7508 struct abbrev_table
*abbrev_table
,
7509 int use_existing_cu
, int keep
,
7511 die_reader_func_ftype
*die_reader_func
,
7514 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7515 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7516 struct dwarf2_section_info
*section
= this_cu
->section
;
7517 bfd
*abfd
= get_section_bfd_owner (section
);
7518 struct dwarf2_cu
*cu
;
7519 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7520 struct die_reader_specs reader
;
7521 struct die_info
*comp_unit_die
;
7523 struct attribute
*attr
;
7524 struct signatured_type
*sig_type
= NULL
;
7525 struct dwarf2_section_info
*abbrev_section
;
7526 /* Non-zero if CU currently points to a DWO file and we need to
7527 reread it. When this happens we need to reread the skeleton die
7528 before we can reread the DWO file (this only applies to CUs, not TUs). */
7529 int rereading_dwo_cu
= 0;
7531 if (dwarf_die_debug
)
7532 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7533 this_cu
->is_debug_types
? "type" : "comp",
7534 sect_offset_str (this_cu
->sect_off
));
7536 if (use_existing_cu
)
7539 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7540 file (instead of going through the stub), short-circuit all of this. */
7541 if (this_cu
->reading_dwo_directly
)
7543 /* Narrow down the scope of possibilities to have to understand. */
7544 gdb_assert (this_cu
->is_debug_types
);
7545 gdb_assert (abbrev_table
== NULL
);
7546 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7547 die_reader_func
, data
);
7551 /* This is cheap if the section is already read in. */
7552 dwarf2_read_section (objfile
, section
);
7554 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7556 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7558 std::unique_ptr
<dwarf2_cu
> new_cu
;
7559 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7562 /* If this CU is from a DWO file we need to start over, we need to
7563 refetch the attributes from the skeleton CU.
7564 This could be optimized by retrieving those attributes from when we
7565 were here the first time: the previous comp_unit_die was stored in
7566 comp_unit_obstack. But there's no data yet that we need this
7568 if (cu
->dwo_unit
!= NULL
)
7569 rereading_dwo_cu
= 1;
7573 /* If !use_existing_cu, this_cu->cu must be NULL. */
7574 gdb_assert (this_cu
->cu
== NULL
);
7575 new_cu
.reset (new dwarf2_cu (this_cu
));
7579 /* Get the header. */
7580 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7582 /* We already have the header, there's no need to read it in again. */
7583 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7587 if (this_cu
->is_debug_types
)
7589 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7590 &cu
->header
, section
,
7591 abbrev_section
, info_ptr
,
7594 /* Since per_cu is the first member of struct signatured_type,
7595 we can go from a pointer to one to a pointer to the other. */
7596 sig_type
= (struct signatured_type
*) this_cu
;
7597 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7598 gdb_assert (sig_type
->type_offset_in_tu
7599 == cu
->header
.type_cu_offset_in_tu
);
7600 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7602 /* LENGTH has not been set yet for type units if we're
7603 using .gdb_index. */
7604 this_cu
->length
= get_cu_length (&cu
->header
);
7606 /* Establish the type offset that can be used to lookup the type. */
7607 sig_type
->type_offset_in_section
=
7608 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7610 this_cu
->dwarf_version
= cu
->header
.version
;
7614 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7615 &cu
->header
, section
,
7618 rcuh_kind::COMPILE
);
7620 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7621 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7622 this_cu
->dwarf_version
= cu
->header
.version
;
7626 /* Skip dummy compilation units. */
7627 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7628 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7631 /* If we don't have them yet, read the abbrevs for this compilation unit.
7632 And if we need to read them now, make sure they're freed when we're
7633 done (own the table through ABBREV_TABLE_HOLDER). */
7634 abbrev_table_up abbrev_table_holder
;
7635 if (abbrev_table
!= NULL
)
7636 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7640 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7641 cu
->header
.abbrev_sect_off
);
7642 abbrev_table
= abbrev_table_holder
.get ();
7645 /* Read the top level CU/TU die. */
7646 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7647 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7649 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7652 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7653 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7654 table from the DWO file and pass the ownership over to us. It will be
7655 referenced from READER, so we must make sure to free it after we're done
7658 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7659 DWO CU, that this test will fail (the attribute will not be present). */
7660 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7661 abbrev_table_up dwo_abbrev_table
;
7664 struct dwo_unit
*dwo_unit
;
7665 struct die_info
*dwo_comp_unit_die
;
7669 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7670 " has children (offset %s) [in module %s]"),
7671 sect_offset_str (this_cu
->sect_off
),
7672 bfd_get_filename (abfd
));
7674 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7675 if (dwo_unit
!= NULL
)
7677 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7678 comp_unit_die
, NULL
,
7680 &dwo_comp_unit_die
, &has_children
,
7681 &dwo_abbrev_table
) == 0)
7686 comp_unit_die
= dwo_comp_unit_die
;
7690 /* Yikes, we couldn't find the rest of the DIE, we only have
7691 the stub. A complaint has already been logged. There's
7692 not much more we can do except pass on the stub DIE to
7693 die_reader_func. We don't want to throw an error on bad
7698 /* All of the above is setup for this call. Yikes. */
7699 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7701 /* Done, clean up. */
7702 if (new_cu
!= NULL
&& keep
)
7704 /* Link this CU into read_in_chain. */
7705 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7706 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7707 /* The chain owns it now. */
7712 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7713 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7714 to have already done the lookup to find the DWO file).
7716 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7717 THIS_CU->is_debug_types, but nothing else.
7719 We fill in THIS_CU->length.
7721 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7722 linker) then DIE_READER_FUNC will not get called.
7724 THIS_CU->cu is always freed when done.
7725 This is done in order to not leave THIS_CU->cu in a state where we have
7726 to care whether it refers to the "main" CU or the DWO CU. */
7729 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7730 struct dwo_file
*dwo_file
,
7731 die_reader_func_ftype
*die_reader_func
,
7734 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7735 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7736 struct dwarf2_section_info
*section
= this_cu
->section
;
7737 bfd
*abfd
= get_section_bfd_owner (section
);
7738 struct dwarf2_section_info
*abbrev_section
;
7739 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7740 struct die_reader_specs reader
;
7741 struct die_info
*comp_unit_die
;
7744 if (dwarf_die_debug
)
7745 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7746 this_cu
->is_debug_types
? "type" : "comp",
7747 sect_offset_str (this_cu
->sect_off
));
7749 gdb_assert (this_cu
->cu
== NULL
);
7751 abbrev_section
= (dwo_file
!= NULL
7752 ? &dwo_file
->sections
.abbrev
7753 : get_abbrev_section_for_cu (this_cu
));
7755 /* This is cheap if the section is already read in. */
7756 dwarf2_read_section (objfile
, section
);
7758 struct dwarf2_cu
cu (this_cu
);
7760 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7761 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7762 &cu
.header
, section
,
7763 abbrev_section
, info_ptr
,
7764 (this_cu
->is_debug_types
7766 : rcuh_kind::COMPILE
));
7768 this_cu
->length
= get_cu_length (&cu
.header
);
7770 /* Skip dummy compilation units. */
7771 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7772 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7775 abbrev_table_up abbrev_table
7776 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7777 cu
.header
.abbrev_sect_off
);
7779 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7780 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7782 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7785 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
7786 does not lookup the specified DWO file.
7787 This cannot be used to read DWO files.
7789 THIS_CU->cu is always freed when done.
7790 This is done in order to not leave THIS_CU->cu in a state where we have
7791 to care whether it refers to the "main" CU or the DWO CU.
7792 We can revisit this if the data shows there's a performance issue. */
7795 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7796 die_reader_func_ftype
*die_reader_func
,
7799 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
7802 /* Type Unit Groups.
7804 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7805 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7806 so that all types coming from the same compilation (.o file) are grouped
7807 together. A future step could be to put the types in the same symtab as
7808 the CU the types ultimately came from. */
7811 hash_type_unit_group (const void *item
)
7813 const struct type_unit_group
*tu_group
7814 = (const struct type_unit_group
*) item
;
7816 return hash_stmt_list_entry (&tu_group
->hash
);
7820 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7822 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7823 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7825 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7828 /* Allocate a hash table for type unit groups. */
7831 allocate_type_unit_groups_table (struct objfile
*objfile
)
7833 return htab_create_alloc_ex (3,
7834 hash_type_unit_group
,
7837 &objfile
->objfile_obstack
,
7838 hashtab_obstack_allocate
,
7839 dummy_obstack_deallocate
);
7842 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7843 partial symtabs. We combine several TUs per psymtab to not let the size
7844 of any one psymtab grow too big. */
7845 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7846 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7848 /* Helper routine for get_type_unit_group.
7849 Create the type_unit_group object used to hold one or more TUs. */
7851 static struct type_unit_group
*
7852 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7854 struct dwarf2_per_objfile
*dwarf2_per_objfile
7855 = cu
->per_cu
->dwarf2_per_objfile
;
7856 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7857 struct dwarf2_per_cu_data
*per_cu
;
7858 struct type_unit_group
*tu_group
;
7860 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7861 struct type_unit_group
);
7862 per_cu
= &tu_group
->per_cu
;
7863 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7865 if (dwarf2_per_objfile
->using_index
)
7867 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7868 struct dwarf2_per_cu_quick_data
);
7872 unsigned int line_offset
= to_underlying (line_offset_struct
);
7873 struct partial_symtab
*pst
;
7876 /* Give the symtab a useful name for debug purposes. */
7877 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7878 name
= string_printf ("<type_units_%d>",
7879 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7881 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7883 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7887 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7888 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7893 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7894 STMT_LIST is a DW_AT_stmt_list attribute. */
7896 static struct type_unit_group
*
7897 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7899 struct dwarf2_per_objfile
*dwarf2_per_objfile
7900 = cu
->per_cu
->dwarf2_per_objfile
;
7901 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7902 struct type_unit_group
*tu_group
;
7904 unsigned int line_offset
;
7905 struct type_unit_group type_unit_group_for_lookup
;
7907 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7909 dwarf2_per_objfile
->type_unit_groups
=
7910 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7913 /* Do we need to create a new group, or can we use an existing one? */
7917 line_offset
= DW_UNSND (stmt_list
);
7918 ++tu_stats
->nr_symtab_sharers
;
7922 /* Ugh, no stmt_list. Rare, but we have to handle it.
7923 We can do various things here like create one group per TU or
7924 spread them over multiple groups to split up the expansion work.
7925 To avoid worst case scenarios (too many groups or too large groups)
7926 we, umm, group them in bunches. */
7927 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7928 | (tu_stats
->nr_stmt_less_type_units
7929 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7930 ++tu_stats
->nr_stmt_less_type_units
;
7933 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7934 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7935 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7936 &type_unit_group_for_lookup
, INSERT
);
7939 tu_group
= (struct type_unit_group
*) *slot
;
7940 gdb_assert (tu_group
!= NULL
);
7944 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7945 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7947 ++tu_stats
->nr_symtabs
;
7953 /* Partial symbol tables. */
7955 /* Create a psymtab named NAME and assign it to PER_CU.
7957 The caller must fill in the following details:
7958 dirname, textlow, texthigh. */
7960 static struct partial_symtab
*
7961 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7963 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7964 struct partial_symtab
*pst
;
7966 pst
= start_psymtab_common (objfile
, name
, 0);
7968 pst
->psymtabs_addrmap_supported
= 1;
7970 /* This is the glue that links PST into GDB's symbol API. */
7971 pst
->read_symtab_private
= per_cu
;
7972 pst
->read_symtab
= dwarf2_read_symtab
;
7973 per_cu
->v
.psymtab
= pst
;
7978 /* The DATA object passed to process_psymtab_comp_unit_reader has this
7981 struct process_psymtab_comp_unit_data
7983 /* True if we are reading a DW_TAG_partial_unit. */
7985 int want_partial_unit
;
7987 /* The "pretend" language that is used if the CU doesn't declare a
7990 enum language pretend_language
;
7993 /* die_reader_func for process_psymtab_comp_unit. */
7996 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7997 const gdb_byte
*info_ptr
,
7998 struct die_info
*comp_unit_die
,
8002 struct dwarf2_cu
*cu
= reader
->cu
;
8003 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8004 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8005 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8007 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8008 struct partial_symtab
*pst
;
8009 enum pc_bounds_kind cu_bounds_kind
;
8010 const char *filename
;
8011 struct process_psymtab_comp_unit_data
*info
8012 = (struct process_psymtab_comp_unit_data
*) data
;
8014 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
8017 gdb_assert (! per_cu
->is_debug_types
);
8019 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
8021 /* Allocate a new partial symbol table structure. */
8022 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8023 if (filename
== NULL
)
8026 pst
= create_partial_symtab (per_cu
, filename
);
8028 /* This must be done before calling dwarf2_build_include_psymtabs. */
8029 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8031 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8033 dwarf2_find_base_address (comp_unit_die
, cu
);
8035 /* Possibly set the default values of LOWPC and HIGHPC from
8037 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8038 &best_highpc
, cu
, pst
);
8039 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8042 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
8045 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
8047 /* Store the contiguous range if it is not empty; it can be
8048 empty for CUs with no code. */
8049 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8053 /* Check if comp unit has_children.
8054 If so, read the rest of the partial symbols from this comp unit.
8055 If not, there's no more debug_info for this comp unit. */
8058 struct partial_die_info
*first_die
;
8059 CORE_ADDR lowpc
, highpc
;
8061 lowpc
= ((CORE_ADDR
) -1);
8062 highpc
= ((CORE_ADDR
) 0);
8064 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8066 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8067 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8069 /* If we didn't find a lowpc, set it to highpc to avoid
8070 complaints from `maint check'. */
8071 if (lowpc
== ((CORE_ADDR
) -1))
8074 /* If the compilation unit didn't have an explicit address range,
8075 then use the information extracted from its child dies. */
8076 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8079 best_highpc
= highpc
;
8082 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
8083 best_lowpc
+ baseaddr
)
8085 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
8086 best_highpc
+ baseaddr
)
8089 end_psymtab_common (objfile
, pst
);
8091 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
8094 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8095 struct dwarf2_per_cu_data
*iter
;
8097 /* Fill in 'dependencies' here; we fill in 'users' in a
8099 pst
->number_of_dependencies
= len
;
8101 = objfile
->partial_symtabs
->allocate_dependencies (len
);
8103 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8106 pst
->dependencies
[i
] = iter
->v
.psymtab
;
8108 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8111 /* Get the list of files included in the current compilation unit,
8112 and build a psymtab for each of them. */
8113 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8115 if (dwarf_read_debug
)
8116 fprintf_unfiltered (gdb_stdlog
,
8117 "Psymtab for %s unit @%s: %s - %s"
8118 ", %d global, %d static syms\n",
8119 per_cu
->is_debug_types
? "type" : "comp",
8120 sect_offset_str (per_cu
->sect_off
),
8121 paddress (gdbarch
, pst
->text_low (objfile
)),
8122 paddress (gdbarch
, pst
->text_high (objfile
)),
8123 pst
->n_global_syms
, pst
->n_static_syms
);
8126 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8127 Process compilation unit THIS_CU for a psymtab. */
8130 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8131 int want_partial_unit
,
8132 enum language pretend_language
)
8134 /* If this compilation unit was already read in, free the
8135 cached copy in order to read it in again. This is
8136 necessary because we skipped some symbols when we first
8137 read in the compilation unit (see load_partial_dies).
8138 This problem could be avoided, but the benefit is unclear. */
8139 if (this_cu
->cu
!= NULL
)
8140 free_one_cached_comp_unit (this_cu
);
8142 if (this_cu
->is_debug_types
)
8143 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8144 build_type_psymtabs_reader
, NULL
);
8147 process_psymtab_comp_unit_data info
;
8148 info
.want_partial_unit
= want_partial_unit
;
8149 info
.pretend_language
= pretend_language
;
8150 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8151 process_psymtab_comp_unit_reader
, &info
);
8154 /* Age out any secondary CUs. */
8155 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8158 /* Reader function for build_type_psymtabs. */
8161 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8162 const gdb_byte
*info_ptr
,
8163 struct die_info
*type_unit_die
,
8167 struct dwarf2_per_objfile
*dwarf2_per_objfile
8168 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8169 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8170 struct dwarf2_cu
*cu
= reader
->cu
;
8171 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8172 struct signatured_type
*sig_type
;
8173 struct type_unit_group
*tu_group
;
8174 struct attribute
*attr
;
8175 struct partial_die_info
*first_die
;
8176 CORE_ADDR lowpc
, highpc
;
8177 struct partial_symtab
*pst
;
8179 gdb_assert (data
== NULL
);
8180 gdb_assert (per_cu
->is_debug_types
);
8181 sig_type
= (struct signatured_type
*) per_cu
;
8186 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8187 tu_group
= get_type_unit_group (cu
, attr
);
8189 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
8191 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8192 pst
= create_partial_symtab (per_cu
, "");
8195 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8197 lowpc
= (CORE_ADDR
) -1;
8198 highpc
= (CORE_ADDR
) 0;
8199 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8201 end_psymtab_common (objfile
, pst
);
8204 /* Struct used to sort TUs by their abbreviation table offset. */
8206 struct tu_abbrev_offset
8208 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8209 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8212 signatured_type
*sig_type
;
8213 sect_offset abbrev_offset
;
8216 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8219 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8220 const struct tu_abbrev_offset
&b
)
8222 return a
.abbrev_offset
< b
.abbrev_offset
;
8225 /* Efficiently read all the type units.
8226 This does the bulk of the work for build_type_psymtabs.
8228 The efficiency is because we sort TUs by the abbrev table they use and
8229 only read each abbrev table once. In one program there are 200K TUs
8230 sharing 8K abbrev tables.
8232 The main purpose of this function is to support building the
8233 dwarf2_per_objfile->type_unit_groups table.
8234 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8235 can collapse the search space by grouping them by stmt_list.
8236 The savings can be significant, in the same program from above the 200K TUs
8237 share 8K stmt_list tables.
8239 FUNC is expected to call get_type_unit_group, which will create the
8240 struct type_unit_group if necessary and add it to
8241 dwarf2_per_objfile->type_unit_groups. */
8244 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8246 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8247 abbrev_table_up abbrev_table
;
8248 sect_offset abbrev_offset
;
8250 /* It's up to the caller to not call us multiple times. */
8251 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8253 if (dwarf2_per_objfile
->all_type_units
.empty ())
8256 /* TUs typically share abbrev tables, and there can be way more TUs than
8257 abbrev tables. Sort by abbrev table to reduce the number of times we
8258 read each abbrev table in.
8259 Alternatives are to punt or to maintain a cache of abbrev tables.
8260 This is simpler and efficient enough for now.
8262 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8263 symtab to use). Typically TUs with the same abbrev offset have the same
8264 stmt_list value too so in practice this should work well.
8266 The basic algorithm here is:
8268 sort TUs by abbrev table
8269 for each TU with same abbrev table:
8270 read abbrev table if first user
8271 read TU top level DIE
8272 [IWBN if DWO skeletons had DW_AT_stmt_list]
8275 if (dwarf_read_debug
)
8276 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8278 /* Sort in a separate table to maintain the order of all_type_units
8279 for .gdb_index: TU indices directly index all_type_units. */
8280 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8281 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8283 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8284 sorted_by_abbrev
.emplace_back
8285 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8286 sig_type
->per_cu
.section
,
8287 sig_type
->per_cu
.sect_off
));
8289 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8290 sort_tu_by_abbrev_offset
);
8292 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8294 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8296 /* Switch to the next abbrev table if necessary. */
8297 if (abbrev_table
== NULL
8298 || tu
.abbrev_offset
!= abbrev_offset
)
8300 abbrev_offset
= tu
.abbrev_offset
;
8302 abbrev_table_read_table (dwarf2_per_objfile
,
8303 &dwarf2_per_objfile
->abbrev
,
8305 ++tu_stats
->nr_uniq_abbrev_tables
;
8308 init_cutu_and_read_dies (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8309 0, 0, false, build_type_psymtabs_reader
, NULL
);
8313 /* Print collected type unit statistics. */
8316 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8318 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8320 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8321 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8322 dwarf2_per_objfile
->all_type_units
.size ());
8323 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8324 tu_stats
->nr_uniq_abbrev_tables
);
8325 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8326 tu_stats
->nr_symtabs
);
8327 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8328 tu_stats
->nr_symtab_sharers
);
8329 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8330 tu_stats
->nr_stmt_less_type_units
);
8331 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8332 tu_stats
->nr_all_type_units_reallocs
);
8335 /* Traversal function for build_type_psymtabs. */
8338 build_type_psymtab_dependencies (void **slot
, void *info
)
8340 struct dwarf2_per_objfile
*dwarf2_per_objfile
8341 = (struct dwarf2_per_objfile
*) info
;
8342 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8343 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8344 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8345 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8346 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
8347 struct signatured_type
*iter
;
8350 gdb_assert (len
> 0);
8351 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8353 pst
->number_of_dependencies
= len
;
8354 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8356 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
8359 gdb_assert (iter
->per_cu
.is_debug_types
);
8360 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8361 iter
->type_unit_group
= tu_group
;
8364 VEC_free (sig_type_ptr
, tu_group
->tus
);
8369 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8370 Build partial symbol tables for the .debug_types comp-units. */
8373 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8375 if (! create_all_type_units (dwarf2_per_objfile
))
8378 build_type_psymtabs_1 (dwarf2_per_objfile
);
8381 /* Traversal function for process_skeletonless_type_unit.
8382 Read a TU in a DWO file and build partial symbols for it. */
8385 process_skeletonless_type_unit (void **slot
, void *info
)
8387 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8388 struct dwarf2_per_objfile
*dwarf2_per_objfile
8389 = (struct dwarf2_per_objfile
*) info
;
8390 struct signatured_type find_entry
, *entry
;
8392 /* If this TU doesn't exist in the global table, add it and read it in. */
8394 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8396 dwarf2_per_objfile
->signatured_types
8397 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8400 find_entry
.signature
= dwo_unit
->signature
;
8401 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8403 /* If we've already seen this type there's nothing to do. What's happening
8404 is we're doing our own version of comdat-folding here. */
8408 /* This does the job that create_all_type_units would have done for
8410 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8411 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8414 /* This does the job that build_type_psymtabs_1 would have done. */
8415 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0, false,
8416 build_type_psymtabs_reader
, NULL
);
8421 /* Traversal function for process_skeletonless_type_units. */
8424 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8426 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8428 if (dwo_file
->tus
!= NULL
)
8430 htab_traverse_noresize (dwo_file
->tus
,
8431 process_skeletonless_type_unit
, info
);
8437 /* Scan all TUs of DWO files, verifying we've processed them.
8438 This is needed in case a TU was emitted without its skeleton.
8439 Note: This can't be done until we know what all the DWO files are. */
8442 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8444 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8445 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8446 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8448 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
8449 process_dwo_file_for_skeletonless_type_units
,
8450 dwarf2_per_objfile
);
8454 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8457 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8459 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8461 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8466 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8468 /* Set the 'user' field only if it is not already set. */
8469 if (pst
->dependencies
[j
]->user
== NULL
)
8470 pst
->dependencies
[j
]->user
= pst
;
8475 /* Build the partial symbol table by doing a quick pass through the
8476 .debug_info and .debug_abbrev sections. */
8479 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8481 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8483 if (dwarf_read_debug
)
8485 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8486 objfile_name (objfile
));
8489 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8491 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8493 /* Any cached compilation units will be linked by the per-objfile
8494 read_in_chain. Make sure to free them when we're done. */
8495 free_cached_comp_units
freer (dwarf2_per_objfile
);
8497 build_type_psymtabs (dwarf2_per_objfile
);
8499 create_all_comp_units (dwarf2_per_objfile
);
8501 /* Create a temporary address map on a temporary obstack. We later
8502 copy this to the final obstack. */
8503 auto_obstack temp_obstack
;
8505 scoped_restore save_psymtabs_addrmap
8506 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8507 addrmap_create_mutable (&temp_obstack
));
8509 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8510 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8512 /* This has to wait until we read the CUs, we need the list of DWOs. */
8513 process_skeletonless_type_units (dwarf2_per_objfile
);
8515 /* Now that all TUs have been processed we can fill in the dependencies. */
8516 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8518 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8519 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8522 if (dwarf_read_debug
)
8523 print_tu_stats (dwarf2_per_objfile
);
8525 set_partial_user (dwarf2_per_objfile
);
8527 objfile
->partial_symtabs
->psymtabs_addrmap
8528 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8529 objfile
->partial_symtabs
->obstack ());
8530 /* At this point we want to keep the address map. */
8531 save_psymtabs_addrmap
.release ();
8533 if (dwarf_read_debug
)
8534 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8535 objfile_name (objfile
));
8538 /* die_reader_func for load_partial_comp_unit. */
8541 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8542 const gdb_byte
*info_ptr
,
8543 struct die_info
*comp_unit_die
,
8547 struct dwarf2_cu
*cu
= reader
->cu
;
8549 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8551 /* Check if comp unit has_children.
8552 If so, read the rest of the partial symbols from this comp unit.
8553 If not, there's no more debug_info for this comp unit. */
8555 load_partial_dies (reader
, info_ptr
, 0);
8558 /* Load the partial DIEs for a secondary CU into memory.
8559 This is also used when rereading a primary CU with load_all_dies. */
8562 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8564 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, false,
8565 load_partial_comp_unit_reader
, NULL
);
8569 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8570 struct dwarf2_section_info
*section
,
8571 struct dwarf2_section_info
*abbrev_section
,
8572 unsigned int is_dwz
)
8574 const gdb_byte
*info_ptr
;
8575 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8577 if (dwarf_read_debug
)
8578 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8579 get_section_name (section
),
8580 get_section_file_name (section
));
8582 dwarf2_read_section (objfile
, section
);
8584 info_ptr
= section
->buffer
;
8586 while (info_ptr
< section
->buffer
+ section
->size
)
8588 struct dwarf2_per_cu_data
*this_cu
;
8590 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8592 comp_unit_head cu_header
;
8593 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8594 abbrev_section
, info_ptr
,
8595 rcuh_kind::COMPILE
);
8597 /* Save the compilation unit for later lookup. */
8598 if (cu_header
.unit_type
!= DW_UT_type
)
8600 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8601 struct dwarf2_per_cu_data
);
8602 memset (this_cu
, 0, sizeof (*this_cu
));
8606 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8607 struct signatured_type
);
8608 memset (sig_type
, 0, sizeof (*sig_type
));
8609 sig_type
->signature
= cu_header
.signature
;
8610 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8611 this_cu
= &sig_type
->per_cu
;
8613 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8614 this_cu
->sect_off
= sect_off
;
8615 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8616 this_cu
->is_dwz
= is_dwz
;
8617 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8618 this_cu
->section
= section
;
8620 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8622 info_ptr
= info_ptr
+ this_cu
->length
;
8626 /* Create a list of all compilation units in OBJFILE.
8627 This is only done for -readnow and building partial symtabs. */
8630 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8632 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8633 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8634 &dwarf2_per_objfile
->abbrev
, 0);
8636 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8638 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8642 /* Process all loaded DIEs for compilation unit CU, starting at
8643 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8644 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8645 DW_AT_ranges). See the comments of add_partial_subprogram on how
8646 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8649 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8650 CORE_ADDR
*highpc
, int set_addrmap
,
8651 struct dwarf2_cu
*cu
)
8653 struct partial_die_info
*pdi
;
8655 /* Now, march along the PDI's, descending into ones which have
8656 interesting children but skipping the children of the other ones,
8657 until we reach the end of the compilation unit. */
8665 /* Anonymous namespaces or modules have no name but have interesting
8666 children, so we need to look at them. Ditto for anonymous
8669 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8670 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8671 || pdi
->tag
== DW_TAG_imported_unit
8672 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8676 case DW_TAG_subprogram
:
8677 case DW_TAG_inlined_subroutine
:
8678 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8680 case DW_TAG_constant
:
8681 case DW_TAG_variable
:
8682 case DW_TAG_typedef
:
8683 case DW_TAG_union_type
:
8684 if (!pdi
->is_declaration
)
8686 add_partial_symbol (pdi
, cu
);
8689 case DW_TAG_class_type
:
8690 case DW_TAG_interface_type
:
8691 case DW_TAG_structure_type
:
8692 if (!pdi
->is_declaration
)
8694 add_partial_symbol (pdi
, cu
);
8696 if ((cu
->language
== language_rust
8697 || cu
->language
== language_cplus
) && pdi
->has_children
)
8698 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8701 case DW_TAG_enumeration_type
:
8702 if (!pdi
->is_declaration
)
8703 add_partial_enumeration (pdi
, cu
);
8705 case DW_TAG_base_type
:
8706 case DW_TAG_subrange_type
:
8707 /* File scope base type definitions are added to the partial
8709 add_partial_symbol (pdi
, cu
);
8711 case DW_TAG_namespace
:
8712 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8715 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8717 case DW_TAG_imported_unit
:
8719 struct dwarf2_per_cu_data
*per_cu
;
8721 /* For now we don't handle imported units in type units. */
8722 if (cu
->per_cu
->is_debug_types
)
8724 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8725 " supported in type units [in module %s]"),
8726 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8729 per_cu
= dwarf2_find_containing_comp_unit
8730 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8731 cu
->per_cu
->dwarf2_per_objfile
);
8733 /* Go read the partial unit, if needed. */
8734 if (per_cu
->v
.psymtab
== NULL
)
8735 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8737 VEC_safe_push (dwarf2_per_cu_ptr
,
8738 cu
->per_cu
->imported_symtabs
, per_cu
);
8741 case DW_TAG_imported_declaration
:
8742 add_partial_symbol (pdi
, cu
);
8749 /* If the die has a sibling, skip to the sibling. */
8751 pdi
= pdi
->die_sibling
;
8755 /* Functions used to compute the fully scoped name of a partial DIE.
8757 Normally, this is simple. For C++, the parent DIE's fully scoped
8758 name is concatenated with "::" and the partial DIE's name.
8759 Enumerators are an exception; they use the scope of their parent
8760 enumeration type, i.e. the name of the enumeration type is not
8761 prepended to the enumerator.
8763 There are two complexities. One is DW_AT_specification; in this
8764 case "parent" means the parent of the target of the specification,
8765 instead of the direct parent of the DIE. The other is compilers
8766 which do not emit DW_TAG_namespace; in this case we try to guess
8767 the fully qualified name of structure types from their members'
8768 linkage names. This must be done using the DIE's children rather
8769 than the children of any DW_AT_specification target. We only need
8770 to do this for structures at the top level, i.e. if the target of
8771 any DW_AT_specification (if any; otherwise the DIE itself) does not
8774 /* Compute the scope prefix associated with PDI's parent, in
8775 compilation unit CU. The result will be allocated on CU's
8776 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8777 field. NULL is returned if no prefix is necessary. */
8779 partial_die_parent_scope (struct partial_die_info
*pdi
,
8780 struct dwarf2_cu
*cu
)
8782 const char *grandparent_scope
;
8783 struct partial_die_info
*parent
, *real_pdi
;
8785 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8786 then this means the parent of the specification DIE. */
8789 while (real_pdi
->has_specification
)
8790 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
8791 real_pdi
->spec_is_dwz
, cu
);
8793 parent
= real_pdi
->die_parent
;
8797 if (parent
->scope_set
)
8798 return parent
->scope
;
8802 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8804 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8805 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8806 Work around this problem here. */
8807 if (cu
->language
== language_cplus
8808 && parent
->tag
== DW_TAG_namespace
8809 && strcmp (parent
->name
, "::") == 0
8810 && grandparent_scope
== NULL
)
8812 parent
->scope
= NULL
;
8813 parent
->scope_set
= 1;
8817 if (pdi
->tag
== DW_TAG_enumerator
)
8818 /* Enumerators should not get the name of the enumeration as a prefix. */
8819 parent
->scope
= grandparent_scope
;
8820 else if (parent
->tag
== DW_TAG_namespace
8821 || parent
->tag
== DW_TAG_module
8822 || parent
->tag
== DW_TAG_structure_type
8823 || parent
->tag
== DW_TAG_class_type
8824 || parent
->tag
== DW_TAG_interface_type
8825 || parent
->tag
== DW_TAG_union_type
8826 || parent
->tag
== DW_TAG_enumeration_type
)
8828 if (grandparent_scope
== NULL
)
8829 parent
->scope
= parent
->name
;
8831 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8833 parent
->name
, 0, cu
);
8837 /* FIXME drow/2004-04-01: What should we be doing with
8838 function-local names? For partial symbols, we should probably be
8840 complaint (_("unhandled containing DIE tag %d for DIE at %s"),
8841 parent
->tag
, sect_offset_str (pdi
->sect_off
));
8842 parent
->scope
= grandparent_scope
;
8845 parent
->scope_set
= 1;
8846 return parent
->scope
;
8849 /* Return the fully scoped name associated with PDI, from compilation unit
8850 CU. The result will be allocated with malloc. */
8853 partial_die_full_name (struct partial_die_info
*pdi
,
8854 struct dwarf2_cu
*cu
)
8856 const char *parent_scope
;
8858 /* If this is a template instantiation, we can not work out the
8859 template arguments from partial DIEs. So, unfortunately, we have
8860 to go through the full DIEs. At least any work we do building
8861 types here will be reused if full symbols are loaded later. */
8862 if (pdi
->has_template_arguments
)
8866 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8868 struct die_info
*die
;
8869 struct attribute attr
;
8870 struct dwarf2_cu
*ref_cu
= cu
;
8872 /* DW_FORM_ref_addr is using section offset. */
8873 attr
.name
= (enum dwarf_attribute
) 0;
8874 attr
.form
= DW_FORM_ref_addr
;
8875 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8876 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8878 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8882 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8883 if (parent_scope
== NULL
)
8886 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
8890 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8892 struct dwarf2_per_objfile
*dwarf2_per_objfile
8893 = cu
->per_cu
->dwarf2_per_objfile
;
8894 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8895 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8897 const char *actual_name
= NULL
;
8899 char *built_actual_name
;
8901 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8903 built_actual_name
= partial_die_full_name (pdi
, cu
);
8904 if (built_actual_name
!= NULL
)
8905 actual_name
= built_actual_name
;
8907 if (actual_name
== NULL
)
8908 actual_name
= pdi
->name
;
8912 case DW_TAG_inlined_subroutine
:
8913 case DW_TAG_subprogram
:
8914 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8916 if (pdi
->is_external
|| cu
->language
== language_ada
)
8918 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
8919 of the global scope. But in Ada, we want to be able to access
8920 nested procedures globally. So all Ada subprograms are stored
8921 in the global scope. */
8922 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8923 built_actual_name
!= NULL
,
8924 VAR_DOMAIN
, LOC_BLOCK
,
8925 SECT_OFF_TEXT (objfile
),
8926 psymbol_placement::GLOBAL
,
8928 cu
->language
, objfile
);
8932 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8933 built_actual_name
!= NULL
,
8934 VAR_DOMAIN
, LOC_BLOCK
,
8935 SECT_OFF_TEXT (objfile
),
8936 psymbol_placement::STATIC
,
8937 addr
, cu
->language
, objfile
);
8940 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8941 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8943 case DW_TAG_constant
:
8944 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8945 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8946 -1, (pdi
->is_external
8947 ? psymbol_placement::GLOBAL
8948 : psymbol_placement::STATIC
),
8949 0, cu
->language
, objfile
);
8951 case DW_TAG_variable
:
8953 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8957 && !dwarf2_per_objfile
->has_section_at_zero
)
8959 /* A global or static variable may also have been stripped
8960 out by the linker if unused, in which case its address
8961 will be nullified; do not add such variables into partial
8962 symbol table then. */
8964 else if (pdi
->is_external
)
8967 Don't enter into the minimal symbol tables as there is
8968 a minimal symbol table entry from the ELF symbols already.
8969 Enter into partial symbol table if it has a location
8970 descriptor or a type.
8971 If the location descriptor is missing, new_symbol will create
8972 a LOC_UNRESOLVED symbol, the address of the variable will then
8973 be determined from the minimal symbol table whenever the variable
8975 The address for the partial symbol table entry is not
8976 used by GDB, but it comes in handy for debugging partial symbol
8979 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8980 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8981 built_actual_name
!= NULL
,
8982 VAR_DOMAIN
, LOC_STATIC
,
8983 SECT_OFF_TEXT (objfile
),
8984 psymbol_placement::GLOBAL
,
8985 addr
, cu
->language
, objfile
);
8989 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8991 /* Static Variable. Skip symbols whose value we cannot know (those
8992 without location descriptors or constant values). */
8993 if (!has_loc
&& !pdi
->has_const_value
)
8995 xfree (built_actual_name
);
8999 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9000 built_actual_name
!= NULL
,
9001 VAR_DOMAIN
, LOC_STATIC
,
9002 SECT_OFF_TEXT (objfile
),
9003 psymbol_placement::STATIC
,
9005 cu
->language
, objfile
);
9008 case DW_TAG_typedef
:
9009 case DW_TAG_base_type
:
9010 case DW_TAG_subrange_type
:
9011 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9012 built_actual_name
!= NULL
,
9013 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9014 psymbol_placement::STATIC
,
9015 0, cu
->language
, objfile
);
9017 case DW_TAG_imported_declaration
:
9018 case DW_TAG_namespace
:
9019 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9020 built_actual_name
!= NULL
,
9021 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9022 psymbol_placement::GLOBAL
,
9023 0, cu
->language
, objfile
);
9026 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9027 built_actual_name
!= NULL
,
9028 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
9029 psymbol_placement::GLOBAL
,
9030 0, cu
->language
, objfile
);
9032 case DW_TAG_class_type
:
9033 case DW_TAG_interface_type
:
9034 case DW_TAG_structure_type
:
9035 case DW_TAG_union_type
:
9036 case DW_TAG_enumeration_type
:
9037 /* Skip external references. The DWARF standard says in the section
9038 about "Structure, Union, and Class Type Entries": "An incomplete
9039 structure, union or class type is represented by a structure,
9040 union or class entry that does not have a byte size attribute
9041 and that has a DW_AT_declaration attribute." */
9042 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9044 xfree (built_actual_name
);
9048 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9049 static vs. global. */
9050 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9051 built_actual_name
!= NULL
,
9052 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
9053 cu
->language
== language_cplus
9054 ? psymbol_placement::GLOBAL
9055 : psymbol_placement::STATIC
,
9056 0, cu
->language
, objfile
);
9059 case DW_TAG_enumerator
:
9060 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9061 built_actual_name
!= NULL
,
9062 VAR_DOMAIN
, LOC_CONST
, -1,
9063 cu
->language
== language_cplus
9064 ? psymbol_placement::GLOBAL
9065 : psymbol_placement::STATIC
,
9066 0, cu
->language
, objfile
);
9072 xfree (built_actual_name
);
9075 /* Read a partial die corresponding to a namespace; also, add a symbol
9076 corresponding to that namespace to the symbol table. NAMESPACE is
9077 the name of the enclosing namespace. */
9080 add_partial_namespace (struct partial_die_info
*pdi
,
9081 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9082 int set_addrmap
, struct dwarf2_cu
*cu
)
9084 /* Add a symbol for the namespace. */
9086 add_partial_symbol (pdi
, cu
);
9088 /* Now scan partial symbols in that namespace. */
9090 if (pdi
->has_children
)
9091 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9094 /* Read a partial die corresponding to a Fortran module. */
9097 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9098 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9100 /* Add a symbol for the namespace. */
9102 add_partial_symbol (pdi
, cu
);
9104 /* Now scan partial symbols in that module. */
9106 if (pdi
->has_children
)
9107 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9110 /* Read a partial die corresponding to a subprogram or an inlined
9111 subprogram and create a partial symbol for that subprogram.
9112 When the CU language allows it, this routine also defines a partial
9113 symbol for each nested subprogram that this subprogram contains.
9114 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9115 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9117 PDI may also be a lexical block, in which case we simply search
9118 recursively for subprograms defined inside that lexical block.
9119 Again, this is only performed when the CU language allows this
9120 type of definitions. */
9123 add_partial_subprogram (struct partial_die_info
*pdi
,
9124 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9125 int set_addrmap
, struct dwarf2_cu
*cu
)
9127 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9129 if (pdi
->has_pc_info
)
9131 if (pdi
->lowpc
< *lowpc
)
9132 *lowpc
= pdi
->lowpc
;
9133 if (pdi
->highpc
> *highpc
)
9134 *highpc
= pdi
->highpc
;
9137 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9138 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9140 CORE_ADDR this_highpc
;
9141 CORE_ADDR this_lowpc
;
9143 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9144 SECT_OFF_TEXT (objfile
));
9146 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9147 pdi
->lowpc
+ baseaddr
)
9150 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9151 pdi
->highpc
+ baseaddr
)
9153 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
9154 this_lowpc
, this_highpc
- 1,
9155 cu
->per_cu
->v
.psymtab
);
9159 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9161 if (!pdi
->is_declaration
)
9162 /* Ignore subprogram DIEs that do not have a name, they are
9163 illegal. Do not emit a complaint at this point, we will
9164 do so when we convert this psymtab into a symtab. */
9166 add_partial_symbol (pdi
, cu
);
9170 if (! pdi
->has_children
)
9173 if (cu
->language
== language_ada
)
9175 pdi
= pdi
->die_child
;
9179 if (pdi
->tag
== DW_TAG_subprogram
9180 || pdi
->tag
== DW_TAG_inlined_subroutine
9181 || pdi
->tag
== DW_TAG_lexical_block
)
9182 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9183 pdi
= pdi
->die_sibling
;
9188 /* Read a partial die corresponding to an enumeration type. */
9191 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9192 struct dwarf2_cu
*cu
)
9194 struct partial_die_info
*pdi
;
9196 if (enum_pdi
->name
!= NULL
)
9197 add_partial_symbol (enum_pdi
, cu
);
9199 pdi
= enum_pdi
->die_child
;
9202 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9203 complaint (_("malformed enumerator DIE ignored"));
9205 add_partial_symbol (pdi
, cu
);
9206 pdi
= pdi
->die_sibling
;
9210 /* Return the initial uleb128 in the die at INFO_PTR. */
9213 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9215 unsigned int bytes_read
;
9217 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9220 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9221 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9223 Return the corresponding abbrev, or NULL if the number is zero (indicating
9224 an empty DIE). In either case *BYTES_READ will be set to the length of
9225 the initial number. */
9227 static struct abbrev_info
*
9228 peek_die_abbrev (const die_reader_specs
&reader
,
9229 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9231 dwarf2_cu
*cu
= reader
.cu
;
9232 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9233 unsigned int abbrev_number
9234 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9236 if (abbrev_number
== 0)
9239 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9242 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9243 " at offset %s [in module %s]"),
9244 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9245 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9251 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9252 Returns a pointer to the end of a series of DIEs, terminated by an empty
9253 DIE. Any children of the skipped DIEs will also be skipped. */
9255 static const gdb_byte
*
9256 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9260 unsigned int bytes_read
;
9261 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9264 return info_ptr
+ bytes_read
;
9266 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9270 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9271 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9272 abbrev corresponding to that skipped uleb128 should be passed in
9273 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9276 static const gdb_byte
*
9277 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9278 struct abbrev_info
*abbrev
)
9280 unsigned int bytes_read
;
9281 struct attribute attr
;
9282 bfd
*abfd
= reader
->abfd
;
9283 struct dwarf2_cu
*cu
= reader
->cu
;
9284 const gdb_byte
*buffer
= reader
->buffer
;
9285 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9286 unsigned int form
, i
;
9288 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9290 /* The only abbrev we care about is DW_AT_sibling. */
9291 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9293 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9294 if (attr
.form
== DW_FORM_ref_addr
)
9295 complaint (_("ignoring absolute DW_AT_sibling"));
9298 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9299 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9301 if (sibling_ptr
< info_ptr
)
9302 complaint (_("DW_AT_sibling points backwards"));
9303 else if (sibling_ptr
> reader
->buffer_end
)
9304 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9310 /* If it isn't DW_AT_sibling, skip this attribute. */
9311 form
= abbrev
->attrs
[i
].form
;
9315 case DW_FORM_ref_addr
:
9316 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9317 and later it is offset sized. */
9318 if (cu
->header
.version
== 2)
9319 info_ptr
+= cu
->header
.addr_size
;
9321 info_ptr
+= cu
->header
.offset_size
;
9323 case DW_FORM_GNU_ref_alt
:
9324 info_ptr
+= cu
->header
.offset_size
;
9327 info_ptr
+= cu
->header
.addr_size
;
9334 case DW_FORM_flag_present
:
9335 case DW_FORM_implicit_const
:
9347 case DW_FORM_ref_sig8
:
9350 case DW_FORM_data16
:
9353 case DW_FORM_string
:
9354 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9355 info_ptr
+= bytes_read
;
9357 case DW_FORM_sec_offset
:
9359 case DW_FORM_GNU_strp_alt
:
9360 info_ptr
+= cu
->header
.offset_size
;
9362 case DW_FORM_exprloc
:
9364 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9365 info_ptr
+= bytes_read
;
9367 case DW_FORM_block1
:
9368 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9370 case DW_FORM_block2
:
9371 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9373 case DW_FORM_block4
:
9374 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9378 case DW_FORM_ref_udata
:
9379 case DW_FORM_GNU_addr_index
:
9380 case DW_FORM_GNU_str_index
:
9381 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9383 case DW_FORM_indirect
:
9384 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9385 info_ptr
+= bytes_read
;
9386 /* We need to continue parsing from here, so just go back to
9388 goto skip_attribute
;
9391 error (_("Dwarf Error: Cannot handle %s "
9392 "in DWARF reader [in module %s]"),
9393 dwarf_form_name (form
),
9394 bfd_get_filename (abfd
));
9398 if (abbrev
->has_children
)
9399 return skip_children (reader
, info_ptr
);
9404 /* Locate ORIG_PDI's sibling.
9405 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9407 static const gdb_byte
*
9408 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9409 struct partial_die_info
*orig_pdi
,
9410 const gdb_byte
*info_ptr
)
9412 /* Do we know the sibling already? */
9414 if (orig_pdi
->sibling
)
9415 return orig_pdi
->sibling
;
9417 /* Are there any children to deal with? */
9419 if (!orig_pdi
->has_children
)
9422 /* Skip the children the long way. */
9424 return skip_children (reader
, info_ptr
);
9427 /* Expand this partial symbol table into a full symbol table. SELF is
9431 dwarf2_read_symtab (struct partial_symtab
*self
,
9432 struct objfile
*objfile
)
9434 struct dwarf2_per_objfile
*dwarf2_per_objfile
9435 = get_dwarf2_per_objfile (objfile
);
9439 warning (_("bug: psymtab for %s is already read in."),
9446 printf_filtered (_("Reading in symbols for %s..."),
9448 gdb_flush (gdb_stdout
);
9451 /* If this psymtab is constructed from a debug-only objfile, the
9452 has_section_at_zero flag will not necessarily be correct. We
9453 can get the correct value for this flag by looking at the data
9454 associated with the (presumably stripped) associated objfile. */
9455 if (objfile
->separate_debug_objfile_backlink
)
9457 struct dwarf2_per_objfile
*dpo_backlink
9458 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9460 dwarf2_per_objfile
->has_section_at_zero
9461 = dpo_backlink
->has_section_at_zero
;
9464 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9466 psymtab_to_symtab_1 (self
);
9468 /* Finish up the debug error message. */
9470 printf_filtered (_("done.\n"));
9473 process_cu_includes (dwarf2_per_objfile
);
9476 /* Reading in full CUs. */
9478 /* Add PER_CU to the queue. */
9481 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9482 enum language pretend_language
)
9484 struct dwarf2_queue_item
*item
;
9487 item
= XNEW (struct dwarf2_queue_item
);
9488 item
->per_cu
= per_cu
;
9489 item
->pretend_language
= pretend_language
;
9492 if (dwarf2_queue
== NULL
)
9493 dwarf2_queue
= item
;
9495 dwarf2_queue_tail
->next
= item
;
9497 dwarf2_queue_tail
= item
;
9500 /* If PER_CU is not yet queued, add it to the queue.
9501 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9503 The result is non-zero if PER_CU was queued, otherwise the result is zero
9504 meaning either PER_CU is already queued or it is already loaded.
9506 N.B. There is an invariant here that if a CU is queued then it is loaded.
9507 The caller is required to load PER_CU if we return non-zero. */
9510 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9511 struct dwarf2_per_cu_data
*per_cu
,
9512 enum language pretend_language
)
9514 /* We may arrive here during partial symbol reading, if we need full
9515 DIEs to process an unusual case (e.g. template arguments). Do
9516 not queue PER_CU, just tell our caller to load its DIEs. */
9517 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9519 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9524 /* Mark the dependence relation so that we don't flush PER_CU
9526 if (dependent_cu
!= NULL
)
9527 dwarf2_add_dependence (dependent_cu
, per_cu
);
9529 /* If it's already on the queue, we have nothing to do. */
9533 /* If the compilation unit is already loaded, just mark it as
9535 if (per_cu
->cu
!= NULL
)
9537 per_cu
->cu
->last_used
= 0;
9541 /* Add it to the queue. */
9542 queue_comp_unit (per_cu
, pretend_language
);
9547 /* Process the queue. */
9550 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9552 struct dwarf2_queue_item
*item
, *next_item
;
9554 if (dwarf_read_debug
)
9556 fprintf_unfiltered (gdb_stdlog
,
9557 "Expanding one or more symtabs of objfile %s ...\n",
9558 objfile_name (dwarf2_per_objfile
->objfile
));
9561 /* The queue starts out with one item, but following a DIE reference
9562 may load a new CU, adding it to the end of the queue. */
9563 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9565 if ((dwarf2_per_objfile
->using_index
9566 ? !item
->per_cu
->v
.quick
->compunit_symtab
9567 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9568 /* Skip dummy CUs. */
9569 && item
->per_cu
->cu
!= NULL
)
9571 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9572 unsigned int debug_print_threshold
;
9575 if (per_cu
->is_debug_types
)
9577 struct signatured_type
*sig_type
=
9578 (struct signatured_type
*) per_cu
;
9580 sprintf (buf
, "TU %s at offset %s",
9581 hex_string (sig_type
->signature
),
9582 sect_offset_str (per_cu
->sect_off
));
9583 /* There can be 100s of TUs.
9584 Only print them in verbose mode. */
9585 debug_print_threshold
= 2;
9589 sprintf (buf
, "CU at offset %s",
9590 sect_offset_str (per_cu
->sect_off
));
9591 debug_print_threshold
= 1;
9594 if (dwarf_read_debug
>= debug_print_threshold
)
9595 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9597 if (per_cu
->is_debug_types
)
9598 process_full_type_unit (per_cu
, item
->pretend_language
);
9600 process_full_comp_unit (per_cu
, item
->pretend_language
);
9602 if (dwarf_read_debug
>= debug_print_threshold
)
9603 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9606 item
->per_cu
->queued
= 0;
9607 next_item
= item
->next
;
9611 dwarf2_queue_tail
= NULL
;
9613 if (dwarf_read_debug
)
9615 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9616 objfile_name (dwarf2_per_objfile
->objfile
));
9620 /* Read in full symbols for PST, and anything it depends on. */
9623 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9625 struct dwarf2_per_cu_data
*per_cu
;
9631 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9632 if (!pst
->dependencies
[i
]->readin
9633 && pst
->dependencies
[i
]->user
== NULL
)
9635 /* Inform about additional files that need to be read in. */
9638 /* FIXME: i18n: Need to make this a single string. */
9639 fputs_filtered (" ", gdb_stdout
);
9641 fputs_filtered ("and ", gdb_stdout
);
9643 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9644 wrap_here (""); /* Flush output. */
9645 gdb_flush (gdb_stdout
);
9647 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9650 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9654 /* It's an include file, no symbols to read for it.
9655 Everything is in the parent symtab. */
9660 dw2_do_instantiate_symtab (per_cu
, false);
9663 /* Trivial hash function for die_info: the hash value of a DIE
9664 is its offset in .debug_info for this objfile. */
9667 die_hash (const void *item
)
9669 const struct die_info
*die
= (const struct die_info
*) item
;
9671 return to_underlying (die
->sect_off
);
9674 /* Trivial comparison function for die_info structures: two DIEs
9675 are equal if they have the same offset. */
9678 die_eq (const void *item_lhs
, const void *item_rhs
)
9680 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9681 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9683 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9686 /* die_reader_func for load_full_comp_unit.
9687 This is identical to read_signatured_type_reader,
9688 but is kept separate for now. */
9691 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9692 const gdb_byte
*info_ptr
,
9693 struct die_info
*comp_unit_die
,
9697 struct dwarf2_cu
*cu
= reader
->cu
;
9698 enum language
*language_ptr
= (enum language
*) data
;
9700 gdb_assert (cu
->die_hash
== NULL
);
9702 htab_create_alloc_ex (cu
->header
.length
/ 12,
9706 &cu
->comp_unit_obstack
,
9707 hashtab_obstack_allocate
,
9708 dummy_obstack_deallocate
);
9711 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9712 &info_ptr
, comp_unit_die
);
9713 cu
->dies
= comp_unit_die
;
9714 /* comp_unit_die is not stored in die_hash, no need. */
9716 /* We try not to read any attributes in this function, because not
9717 all CUs needed for references have been loaded yet, and symbol
9718 table processing isn't initialized. But we have to set the CU language,
9719 or we won't be able to build types correctly.
9720 Similarly, if we do not read the producer, we can not apply
9721 producer-specific interpretation. */
9722 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9725 /* Load the DIEs associated with PER_CU into memory. */
9728 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9730 enum language pretend_language
)
9732 gdb_assert (! this_cu
->is_debug_types
);
9734 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, skip_partial
,
9735 load_full_comp_unit_reader
, &pretend_language
);
9738 /* Add a DIE to the delayed physname list. */
9741 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9742 const char *name
, struct die_info
*die
,
9743 struct dwarf2_cu
*cu
)
9745 struct delayed_method_info mi
;
9747 mi
.fnfield_index
= fnfield_index
;
9751 cu
->method_list
.push_back (mi
);
9754 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9755 "const" / "volatile". If so, decrements LEN by the length of the
9756 modifier and return true. Otherwise return false. */
9760 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9762 size_t mod_len
= sizeof (mod
) - 1;
9763 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9771 /* Compute the physnames of any methods on the CU's method list.
9773 The computation of method physnames is delayed in order to avoid the
9774 (bad) condition that one of the method's formal parameters is of an as yet
9778 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9780 /* Only C++ delays computing physnames. */
9781 if (cu
->method_list
.empty ())
9783 gdb_assert (cu
->language
== language_cplus
);
9785 for (const delayed_method_info
&mi
: cu
->method_list
)
9787 const char *physname
;
9788 struct fn_fieldlist
*fn_flp
9789 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9790 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9791 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9792 = physname
? physname
: "";
9794 /* Since there's no tag to indicate whether a method is a
9795 const/volatile overload, extract that information out of the
9797 if (physname
!= NULL
)
9799 size_t len
= strlen (physname
);
9803 if (physname
[len
] == ')') /* shortcut */
9805 else if (check_modifier (physname
, len
, " const"))
9806 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9807 else if (check_modifier (physname
, len
, " volatile"))
9808 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9815 /* The list is no longer needed. */
9816 cu
->method_list
.clear ();
9819 /* Go objects should be embedded in a DW_TAG_module DIE,
9820 and it's not clear if/how imported objects will appear.
9821 To keep Go support simple until that's worked out,
9822 go back through what we've read and create something usable.
9823 We could do this while processing each DIE, and feels kinda cleaner,
9824 but that way is more invasive.
9825 This is to, for example, allow the user to type "p var" or "b main"
9826 without having to specify the package name, and allow lookups
9827 of module.object to work in contexts that use the expression
9831 fixup_go_packaging (struct dwarf2_cu
*cu
)
9833 char *package_name
= NULL
;
9834 struct pending
*list
;
9837 for (list
= *cu
->get_builder ()->get_global_symbols ();
9841 for (i
= 0; i
< list
->nsyms
; ++i
)
9843 struct symbol
*sym
= list
->symbol
[i
];
9845 if (SYMBOL_LANGUAGE (sym
) == language_go
9846 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9848 char *this_package_name
= go_symbol_package_name (sym
);
9850 if (this_package_name
== NULL
)
9852 if (package_name
== NULL
)
9853 package_name
= this_package_name
;
9856 struct objfile
*objfile
9857 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9858 if (strcmp (package_name
, this_package_name
) != 0)
9859 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9860 (symbol_symtab (sym
) != NULL
9861 ? symtab_to_filename_for_display
9862 (symbol_symtab (sym
))
9863 : objfile_name (objfile
)),
9864 this_package_name
, package_name
);
9865 xfree (this_package_name
);
9871 if (package_name
!= NULL
)
9873 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9874 const char *saved_package_name
9875 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
9877 strlen (package_name
));
9878 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9879 saved_package_name
);
9882 sym
= allocate_symbol (objfile
);
9883 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
9884 SYMBOL_SET_NAMES (sym
, saved_package_name
,
9885 strlen (saved_package_name
), 0, objfile
);
9886 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9887 e.g., "main" finds the "main" module and not C's main(). */
9888 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9889 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9890 SYMBOL_TYPE (sym
) = type
;
9892 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9894 xfree (package_name
);
9898 /* Allocate a fully-qualified name consisting of the two parts on the
9902 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9904 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9907 /* A helper that allocates a struct discriminant_info to attach to a
9910 static struct discriminant_info
*
9911 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9914 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9915 gdb_assert (discriminant_index
== -1
9916 || (discriminant_index
>= 0
9917 && discriminant_index
< TYPE_NFIELDS (type
)));
9918 gdb_assert (default_index
== -1
9919 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9921 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9923 struct discriminant_info
*disc
9924 = ((struct discriminant_info
*)
9926 offsetof (struct discriminant_info
, discriminants
)
9927 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9928 disc
->default_index
= default_index
;
9929 disc
->discriminant_index
= discriminant_index
;
9931 struct dynamic_prop prop
;
9932 prop
.kind
= PROP_UNDEFINED
;
9933 prop
.data
.baton
= disc
;
9935 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9940 /* Some versions of rustc emitted enums in an unusual way.
9942 Ordinary enums were emitted as unions. The first element of each
9943 structure in the union was named "RUST$ENUM$DISR". This element
9944 held the discriminant.
9946 These versions of Rust also implemented the "non-zero"
9947 optimization. When the enum had two values, and one is empty and
9948 the other holds a pointer that cannot be zero, the pointer is used
9949 as the discriminant, with a zero value meaning the empty variant.
9950 Here, the union's first member is of the form
9951 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9952 where the fieldnos are the indices of the fields that should be
9953 traversed in order to find the field (which may be several fields deep)
9954 and the variantname is the name of the variant of the case when the
9957 This function recognizes whether TYPE is of one of these forms,
9958 and, if so, smashes it to be a variant type. */
9961 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9963 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9965 /* We don't need to deal with empty enums. */
9966 if (TYPE_NFIELDS (type
) == 0)
9969 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9970 if (TYPE_NFIELDS (type
) == 1
9971 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9973 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9975 /* Decode the field name to find the offset of the
9977 ULONGEST bit_offset
= 0;
9978 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9979 while (name
[0] >= '0' && name
[0] <= '9')
9982 unsigned long index
= strtoul (name
, &tail
, 10);
9985 || index
>= TYPE_NFIELDS (field_type
)
9986 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9987 != FIELD_LOC_KIND_BITPOS
))
9989 complaint (_("Could not parse Rust enum encoding string \"%s\""
9991 TYPE_FIELD_NAME (type
, 0),
9992 objfile_name (objfile
));
9997 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9998 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10001 /* Make a union to hold the variants. */
10002 struct type
*union_type
= alloc_type (objfile
);
10003 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10004 TYPE_NFIELDS (union_type
) = 3;
10005 TYPE_FIELDS (union_type
)
10006 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10007 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10008 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10010 /* Put the discriminant must at index 0. */
10011 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10012 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10013 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10014 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10016 /* The order of fields doesn't really matter, so put the real
10017 field at index 1 and the data-less field at index 2. */
10018 struct discriminant_info
*disc
10019 = alloc_discriminant_info (union_type
, 0, 1);
10020 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10021 TYPE_FIELD_NAME (union_type
, 1)
10022 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10023 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10024 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10025 TYPE_FIELD_NAME (union_type
, 1));
10027 const char *dataless_name
10028 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10030 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10032 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10033 /* NAME points into the original discriminant name, which
10034 already has the correct lifetime. */
10035 TYPE_FIELD_NAME (union_type
, 2) = name
;
10036 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10037 disc
->discriminants
[2] = 0;
10039 /* Smash this type to be a structure type. We have to do this
10040 because the type has already been recorded. */
10041 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10042 TYPE_NFIELDS (type
) = 1;
10044 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10046 /* Install the variant part. */
10047 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10048 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10049 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10051 else if (TYPE_NFIELDS (type
) == 1)
10053 /* We assume that a union with a single field is a univariant
10055 /* Smash this type to be a structure type. We have to do this
10056 because the type has already been recorded. */
10057 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10059 /* Make a union to hold the variants. */
10060 struct type
*union_type
= alloc_type (objfile
);
10061 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10062 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10063 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10064 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10065 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10067 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10068 const char *variant_name
10069 = rust_last_path_segment (TYPE_NAME (field_type
));
10070 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10071 TYPE_NAME (field_type
)
10072 = rust_fully_qualify (&objfile
->objfile_obstack
,
10073 TYPE_NAME (type
), variant_name
);
10075 /* Install the union in the outer struct type. */
10076 TYPE_NFIELDS (type
) = 1;
10078 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10079 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10080 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10081 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10083 alloc_discriminant_info (union_type
, -1, 0);
10087 struct type
*disr_type
= nullptr;
10088 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10090 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10092 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10094 /* All fields of a true enum will be structs. */
10097 else if (TYPE_NFIELDS (disr_type
) == 0)
10099 /* Could be data-less variant, so keep going. */
10100 disr_type
= nullptr;
10102 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10103 "RUST$ENUM$DISR") != 0)
10105 /* Not a Rust enum. */
10115 /* If we got here without a discriminant, then it's probably
10117 if (disr_type
== nullptr)
10120 /* Smash this type to be a structure type. We have to do this
10121 because the type has already been recorded. */
10122 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10124 /* Make a union to hold the variants. */
10125 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10126 struct type
*union_type
= alloc_type (objfile
);
10127 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10128 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10129 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10130 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10131 TYPE_FIELDS (union_type
)
10132 = (struct field
*) TYPE_ZALLOC (union_type
,
10133 (TYPE_NFIELDS (union_type
)
10134 * sizeof (struct field
)));
10136 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10137 TYPE_NFIELDS (type
) * sizeof (struct field
));
10139 /* Install the discriminant at index 0 in the union. */
10140 TYPE_FIELD (union_type
, 0) = *disr_field
;
10141 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10142 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10144 /* Install the union in the outer struct type. */
10145 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10146 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10147 TYPE_NFIELDS (type
) = 1;
10149 /* Set the size and offset of the union type. */
10150 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10152 /* We need a way to find the correct discriminant given a
10153 variant name. For convenience we build a map here. */
10154 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10155 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10156 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10158 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10161 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10162 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10166 int n_fields
= TYPE_NFIELDS (union_type
);
10167 struct discriminant_info
*disc
10168 = alloc_discriminant_info (union_type
, 0, -1);
10169 /* Skip the discriminant here. */
10170 for (int i
= 1; i
< n_fields
; ++i
)
10172 /* Find the final word in the name of this variant's type.
10173 That name can be used to look up the correct
10175 const char *variant_name
10176 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10179 auto iter
= discriminant_map
.find (variant_name
);
10180 if (iter
!= discriminant_map
.end ())
10181 disc
->discriminants
[i
] = iter
->second
;
10183 /* Remove the discriminant field, if it exists. */
10184 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10185 if (TYPE_NFIELDS (sub_type
) > 0)
10187 --TYPE_NFIELDS (sub_type
);
10188 ++TYPE_FIELDS (sub_type
);
10190 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10191 TYPE_NAME (sub_type
)
10192 = rust_fully_qualify (&objfile
->objfile_obstack
,
10193 TYPE_NAME (type
), variant_name
);
10198 /* Rewrite some Rust unions to be structures with variants parts. */
10201 rust_union_quirks (struct dwarf2_cu
*cu
)
10203 gdb_assert (cu
->language
== language_rust
);
10204 for (type
*type_
: cu
->rust_unions
)
10205 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10206 /* We don't need this any more. */
10207 cu
->rust_unions
.clear ();
10210 /* Return the symtab for PER_CU. This works properly regardless of
10211 whether we're using the index or psymtabs. */
10213 static struct compunit_symtab
*
10214 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10216 return (per_cu
->dwarf2_per_objfile
->using_index
10217 ? per_cu
->v
.quick
->compunit_symtab
10218 : per_cu
->v
.psymtab
->compunit_symtab
);
10221 /* A helper function for computing the list of all symbol tables
10222 included by PER_CU. */
10225 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
10226 htab_t all_children
, htab_t all_type_symtabs
,
10227 struct dwarf2_per_cu_data
*per_cu
,
10228 struct compunit_symtab
*immediate_parent
)
10232 struct compunit_symtab
*cust
;
10233 struct dwarf2_per_cu_data
*iter
;
10235 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10238 /* This inclusion and its children have been processed. */
10243 /* Only add a CU if it has a symbol table. */
10244 cust
= get_compunit_symtab (per_cu
);
10247 /* If this is a type unit only add its symbol table if we haven't
10248 seen it yet (type unit per_cu's can share symtabs). */
10249 if (per_cu
->is_debug_types
)
10251 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10255 result
->push_back (cust
);
10256 if (cust
->user
== NULL
)
10257 cust
->user
= immediate_parent
;
10262 result
->push_back (cust
);
10263 if (cust
->user
== NULL
)
10264 cust
->user
= immediate_parent
;
10269 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
10272 recursively_compute_inclusions (result
, all_children
,
10273 all_type_symtabs
, iter
, cust
);
10277 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10281 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10283 gdb_assert (! per_cu
->is_debug_types
);
10285 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
10288 struct dwarf2_per_cu_data
*per_cu_iter
;
10289 std::vector
<compunit_symtab
*> result_symtabs
;
10290 htab_t all_children
, all_type_symtabs
;
10291 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10293 /* If we don't have a symtab, we can just skip this case. */
10297 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10298 NULL
, xcalloc
, xfree
);
10299 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10300 NULL
, xcalloc
, xfree
);
10303 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
10307 recursively_compute_inclusions (&result_symtabs
, all_children
,
10308 all_type_symtabs
, per_cu_iter
,
10312 /* Now we have a transitive closure of all the included symtabs. */
10313 len
= result_symtabs
.size ();
10315 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10316 struct compunit_symtab
*, len
+ 1);
10317 memcpy (cust
->includes
, result_symtabs
.data (),
10318 len
* sizeof (compunit_symtab
*));
10319 cust
->includes
[len
] = NULL
;
10321 htab_delete (all_children
);
10322 htab_delete (all_type_symtabs
);
10326 /* Compute the 'includes' field for the symtabs of all the CUs we just
10330 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10332 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10334 if (! iter
->is_debug_types
)
10335 compute_compunit_symtab_includes (iter
);
10338 dwarf2_per_objfile
->just_read_cus
.clear ();
10341 /* Generate full symbol information for PER_CU, whose DIEs have
10342 already been loaded into memory. */
10345 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10346 enum language pretend_language
)
10348 struct dwarf2_cu
*cu
= per_cu
->cu
;
10349 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10350 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10351 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10352 CORE_ADDR lowpc
, highpc
;
10353 struct compunit_symtab
*cust
;
10354 CORE_ADDR baseaddr
;
10355 struct block
*static_block
;
10358 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10360 /* Clear the list here in case something was left over. */
10361 cu
->method_list
.clear ();
10363 cu
->language
= pretend_language
;
10364 cu
->language_defn
= language_def (cu
->language
);
10366 /* Do line number decoding in read_file_scope () */
10367 process_die (cu
->dies
, cu
);
10369 /* For now fudge the Go package. */
10370 if (cu
->language
== language_go
)
10371 fixup_go_packaging (cu
);
10373 /* Now that we have processed all the DIEs in the CU, all the types
10374 should be complete, and it should now be safe to compute all of the
10376 compute_delayed_physnames (cu
);
10378 if (cu
->language
== language_rust
)
10379 rust_union_quirks (cu
);
10381 /* Some compilers don't define a DW_AT_high_pc attribute for the
10382 compilation unit. If the DW_AT_high_pc is missing, synthesize
10383 it, by scanning the DIE's below the compilation unit. */
10384 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10386 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10387 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10389 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10390 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10391 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10392 addrmap to help ensure it has an accurate map of pc values belonging to
10394 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10396 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10397 SECT_OFF_TEXT (objfile
),
10402 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10404 /* Set symtab language to language from DW_AT_language. If the
10405 compilation is from a C file generated by language preprocessors, do
10406 not set the language if it was already deduced by start_subfile. */
10407 if (!(cu
->language
== language_c
10408 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10409 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10411 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10412 produce DW_AT_location with location lists but it can be possibly
10413 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10414 there were bugs in prologue debug info, fixed later in GCC-4.5
10415 by "unwind info for epilogues" patch (which is not directly related).
10417 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10418 needed, it would be wrong due to missing DW_AT_producer there.
10420 Still one can confuse GDB by using non-standard GCC compilation
10421 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10423 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10424 cust
->locations_valid
= 1;
10426 if (gcc_4_minor
>= 5)
10427 cust
->epilogue_unwind_valid
= 1;
10429 cust
->call_site_htab
= cu
->call_site_htab
;
10432 if (dwarf2_per_objfile
->using_index
)
10433 per_cu
->v
.quick
->compunit_symtab
= cust
;
10436 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10437 pst
->compunit_symtab
= cust
;
10441 /* Push it for inclusion processing later. */
10442 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10444 /* Not needed any more. */
10445 cu
->reset_builder ();
10448 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10449 already been loaded into memory. */
10452 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10453 enum language pretend_language
)
10455 struct dwarf2_cu
*cu
= per_cu
->cu
;
10456 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10457 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10458 struct compunit_symtab
*cust
;
10459 struct signatured_type
*sig_type
;
10461 gdb_assert (per_cu
->is_debug_types
);
10462 sig_type
= (struct signatured_type
*) per_cu
;
10464 /* Clear the list here in case something was left over. */
10465 cu
->method_list
.clear ();
10467 cu
->language
= pretend_language
;
10468 cu
->language_defn
= language_def (cu
->language
);
10470 /* The symbol tables are set up in read_type_unit_scope. */
10471 process_die (cu
->dies
, cu
);
10473 /* For now fudge the Go package. */
10474 if (cu
->language
== language_go
)
10475 fixup_go_packaging (cu
);
10477 /* Now that we have processed all the DIEs in the CU, all the types
10478 should be complete, and it should now be safe to compute all of the
10480 compute_delayed_physnames (cu
);
10482 if (cu
->language
== language_rust
)
10483 rust_union_quirks (cu
);
10485 /* TUs share symbol tables.
10486 If this is the first TU to use this symtab, complete the construction
10487 of it with end_expandable_symtab. Otherwise, complete the addition of
10488 this TU's symbols to the existing symtab. */
10489 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10491 buildsym_compunit
*builder
= cu
->get_builder ();
10492 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10493 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10497 /* Set symtab language to language from DW_AT_language. If the
10498 compilation is from a C file generated by language preprocessors,
10499 do not set the language if it was already deduced by
10501 if (!(cu
->language
== language_c
10502 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10503 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10508 cu
->get_builder ()->augment_type_symtab ();
10509 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10512 if (dwarf2_per_objfile
->using_index
)
10513 per_cu
->v
.quick
->compunit_symtab
= cust
;
10516 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10517 pst
->compunit_symtab
= cust
;
10521 /* Not needed any more. */
10522 cu
->reset_builder ();
10525 /* Process an imported unit DIE. */
10528 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10530 struct attribute
*attr
;
10532 /* For now we don't handle imported units in type units. */
10533 if (cu
->per_cu
->is_debug_types
)
10535 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10536 " supported in type units [in module %s]"),
10537 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10540 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10543 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10544 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10545 dwarf2_per_cu_data
*per_cu
10546 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10547 cu
->per_cu
->dwarf2_per_objfile
);
10549 /* If necessary, add it to the queue and load its DIEs. */
10550 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10551 load_full_comp_unit (per_cu
, false, cu
->language
);
10553 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
10558 /* RAII object that represents a process_die scope: i.e.,
10559 starts/finishes processing a DIE. */
10560 class process_die_scope
10563 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10564 : m_die (die
), m_cu (cu
)
10566 /* We should only be processing DIEs not already in process. */
10567 gdb_assert (!m_die
->in_process
);
10568 m_die
->in_process
= true;
10571 ~process_die_scope ()
10573 m_die
->in_process
= false;
10575 /* If we're done processing the DIE for the CU that owns the line
10576 header, we don't need the line header anymore. */
10577 if (m_cu
->line_header_die_owner
== m_die
)
10579 delete m_cu
->line_header
;
10580 m_cu
->line_header
= NULL
;
10581 m_cu
->line_header_die_owner
= NULL
;
10590 /* Process a die and its children. */
10593 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10595 process_die_scope
scope (die
, cu
);
10599 case DW_TAG_padding
:
10601 case DW_TAG_compile_unit
:
10602 case DW_TAG_partial_unit
:
10603 read_file_scope (die
, cu
);
10605 case DW_TAG_type_unit
:
10606 read_type_unit_scope (die
, cu
);
10608 case DW_TAG_subprogram
:
10609 case DW_TAG_inlined_subroutine
:
10610 read_func_scope (die
, cu
);
10612 case DW_TAG_lexical_block
:
10613 case DW_TAG_try_block
:
10614 case DW_TAG_catch_block
:
10615 read_lexical_block_scope (die
, cu
);
10617 case DW_TAG_call_site
:
10618 case DW_TAG_GNU_call_site
:
10619 read_call_site_scope (die
, cu
);
10621 case DW_TAG_class_type
:
10622 case DW_TAG_interface_type
:
10623 case DW_TAG_structure_type
:
10624 case DW_TAG_union_type
:
10625 process_structure_scope (die
, cu
);
10627 case DW_TAG_enumeration_type
:
10628 process_enumeration_scope (die
, cu
);
10631 /* These dies have a type, but processing them does not create
10632 a symbol or recurse to process the children. Therefore we can
10633 read them on-demand through read_type_die. */
10634 case DW_TAG_subroutine_type
:
10635 case DW_TAG_set_type
:
10636 case DW_TAG_array_type
:
10637 case DW_TAG_pointer_type
:
10638 case DW_TAG_ptr_to_member_type
:
10639 case DW_TAG_reference_type
:
10640 case DW_TAG_rvalue_reference_type
:
10641 case DW_TAG_string_type
:
10644 case DW_TAG_base_type
:
10645 case DW_TAG_subrange_type
:
10646 case DW_TAG_typedef
:
10647 /* Add a typedef symbol for the type definition, if it has a
10649 new_symbol (die
, read_type_die (die
, cu
), cu
);
10651 case DW_TAG_common_block
:
10652 read_common_block (die
, cu
);
10654 case DW_TAG_common_inclusion
:
10656 case DW_TAG_namespace
:
10657 cu
->processing_has_namespace_info
= true;
10658 read_namespace (die
, cu
);
10660 case DW_TAG_module
:
10661 cu
->processing_has_namespace_info
= true;
10662 read_module (die
, cu
);
10664 case DW_TAG_imported_declaration
:
10665 cu
->processing_has_namespace_info
= true;
10666 if (read_namespace_alias (die
, cu
))
10668 /* The declaration is not a global namespace alias. */
10669 /* Fall through. */
10670 case DW_TAG_imported_module
:
10671 cu
->processing_has_namespace_info
= true;
10672 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10673 || cu
->language
!= language_fortran
))
10674 complaint (_("Tag '%s' has unexpected children"),
10675 dwarf_tag_name (die
->tag
));
10676 read_import_statement (die
, cu
);
10679 case DW_TAG_imported_unit
:
10680 process_imported_unit_die (die
, cu
);
10683 case DW_TAG_variable
:
10684 read_variable (die
, cu
);
10688 new_symbol (die
, NULL
, cu
);
10693 /* DWARF name computation. */
10695 /* A helper function for dwarf2_compute_name which determines whether DIE
10696 needs to have the name of the scope prepended to the name listed in the
10700 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10702 struct attribute
*attr
;
10706 case DW_TAG_namespace
:
10707 case DW_TAG_typedef
:
10708 case DW_TAG_class_type
:
10709 case DW_TAG_interface_type
:
10710 case DW_TAG_structure_type
:
10711 case DW_TAG_union_type
:
10712 case DW_TAG_enumeration_type
:
10713 case DW_TAG_enumerator
:
10714 case DW_TAG_subprogram
:
10715 case DW_TAG_inlined_subroutine
:
10716 case DW_TAG_member
:
10717 case DW_TAG_imported_declaration
:
10720 case DW_TAG_variable
:
10721 case DW_TAG_constant
:
10722 /* We only need to prefix "globally" visible variables. These include
10723 any variable marked with DW_AT_external or any variable that
10724 lives in a namespace. [Variables in anonymous namespaces
10725 require prefixing, but they are not DW_AT_external.] */
10727 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10729 struct dwarf2_cu
*spec_cu
= cu
;
10731 return die_needs_namespace (die_specification (die
, &spec_cu
),
10735 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10736 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10737 && die
->parent
->tag
!= DW_TAG_module
)
10739 /* A variable in a lexical block of some kind does not need a
10740 namespace, even though in C++ such variables may be external
10741 and have a mangled name. */
10742 if (die
->parent
->tag
== DW_TAG_lexical_block
10743 || die
->parent
->tag
== DW_TAG_try_block
10744 || die
->parent
->tag
== DW_TAG_catch_block
10745 || die
->parent
->tag
== DW_TAG_subprogram
)
10754 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10755 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10756 defined for the given DIE. */
10758 static struct attribute
*
10759 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10761 struct attribute
*attr
;
10763 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10765 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10770 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10771 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10772 defined for the given DIE. */
10774 static const char *
10775 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10777 const char *linkage_name
;
10779 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10780 if (linkage_name
== NULL
)
10781 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10783 return linkage_name
;
10786 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10787 compute the physname for the object, which include a method's:
10788 - formal parameters (C++),
10789 - receiver type (Go),
10791 The term "physname" is a bit confusing.
10792 For C++, for example, it is the demangled name.
10793 For Go, for example, it's the mangled name.
10795 For Ada, return the DIE's linkage name rather than the fully qualified
10796 name. PHYSNAME is ignored..
10798 The result is allocated on the objfile_obstack and canonicalized. */
10800 static const char *
10801 dwarf2_compute_name (const char *name
,
10802 struct die_info
*die
, struct dwarf2_cu
*cu
,
10805 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10808 name
= dwarf2_name (die
, cu
);
10810 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10811 but otherwise compute it by typename_concat inside GDB.
10812 FIXME: Actually this is not really true, or at least not always true.
10813 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
10814 Fortran names because there is no mangling standard. So new_symbol
10815 will set the demangled name to the result of dwarf2_full_name, and it is
10816 the demangled name that GDB uses if it exists. */
10817 if (cu
->language
== language_ada
10818 || (cu
->language
== language_fortran
&& physname
))
10820 /* For Ada unit, we prefer the linkage name over the name, as
10821 the former contains the exported name, which the user expects
10822 to be able to reference. Ideally, we want the user to be able
10823 to reference this entity using either natural or linkage name,
10824 but we haven't started looking at this enhancement yet. */
10825 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10827 if (linkage_name
!= NULL
)
10828 return linkage_name
;
10831 /* These are the only languages we know how to qualify names in. */
10833 && (cu
->language
== language_cplus
10834 || cu
->language
== language_fortran
|| cu
->language
== language_d
10835 || cu
->language
== language_rust
))
10837 if (die_needs_namespace (die
, cu
))
10839 const char *prefix
;
10840 const char *canonical_name
= NULL
;
10844 prefix
= determine_prefix (die
, cu
);
10845 if (*prefix
!= '\0')
10847 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
10850 buf
.puts (prefixed_name
);
10851 xfree (prefixed_name
);
10856 /* Template parameters may be specified in the DIE's DW_AT_name, or
10857 as children with DW_TAG_template_type_param or
10858 DW_TAG_value_type_param. If the latter, add them to the name
10859 here. If the name already has template parameters, then
10860 skip this step; some versions of GCC emit both, and
10861 it is more efficient to use the pre-computed name.
10863 Something to keep in mind about this process: it is very
10864 unlikely, or in some cases downright impossible, to produce
10865 something that will match the mangled name of a function.
10866 If the definition of the function has the same debug info,
10867 we should be able to match up with it anyway. But fallbacks
10868 using the minimal symbol, for instance to find a method
10869 implemented in a stripped copy of libstdc++, will not work.
10870 If we do not have debug info for the definition, we will have to
10871 match them up some other way.
10873 When we do name matching there is a related problem with function
10874 templates; two instantiated function templates are allowed to
10875 differ only by their return types, which we do not add here. */
10877 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10879 struct attribute
*attr
;
10880 struct die_info
*child
;
10883 die
->building_fullname
= 1;
10885 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10889 const gdb_byte
*bytes
;
10890 struct dwarf2_locexpr_baton
*baton
;
10893 if (child
->tag
!= DW_TAG_template_type_param
10894 && child
->tag
!= DW_TAG_template_value_param
)
10905 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10908 complaint (_("template parameter missing DW_AT_type"));
10909 buf
.puts ("UNKNOWN_TYPE");
10912 type
= die_type (child
, cu
);
10914 if (child
->tag
== DW_TAG_template_type_param
)
10916 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10917 &type_print_raw_options
);
10921 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10924 complaint (_("template parameter missing "
10925 "DW_AT_const_value"));
10926 buf
.puts ("UNKNOWN_VALUE");
10930 dwarf2_const_value_attr (attr
, type
, name
,
10931 &cu
->comp_unit_obstack
, cu
,
10932 &value
, &bytes
, &baton
);
10934 if (TYPE_NOSIGN (type
))
10935 /* GDB prints characters as NUMBER 'CHAR'. If that's
10936 changed, this can use value_print instead. */
10937 c_printchar (value
, type
, &buf
);
10940 struct value_print_options opts
;
10943 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10947 else if (bytes
!= NULL
)
10949 v
= allocate_value (type
);
10950 memcpy (value_contents_writeable (v
), bytes
,
10951 TYPE_LENGTH (type
));
10954 v
= value_from_longest (type
, value
);
10956 /* Specify decimal so that we do not depend on
10958 get_formatted_print_options (&opts
, 'd');
10960 value_print (v
, &buf
, &opts
);
10965 die
->building_fullname
= 0;
10969 /* Close the argument list, with a space if necessary
10970 (nested templates). */
10971 if (!buf
.empty () && buf
.string ().back () == '>')
10978 /* For C++ methods, append formal parameter type
10979 information, if PHYSNAME. */
10981 if (physname
&& die
->tag
== DW_TAG_subprogram
10982 && cu
->language
== language_cplus
)
10984 struct type
*type
= read_type_die (die
, cu
);
10986 c_type_print_args (type
, &buf
, 1, cu
->language
,
10987 &type_print_raw_options
);
10989 if (cu
->language
== language_cplus
)
10991 /* Assume that an artificial first parameter is
10992 "this", but do not crash if it is not. RealView
10993 marks unnamed (and thus unused) parameters as
10994 artificial; there is no way to differentiate
10996 if (TYPE_NFIELDS (type
) > 0
10997 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10998 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10999 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11001 buf
.puts (" const");
11005 const std::string
&intermediate_name
= buf
.string ();
11007 if (cu
->language
== language_cplus
)
11009 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11010 &objfile
->per_bfd
->storage_obstack
);
11012 /* If we only computed INTERMEDIATE_NAME, or if
11013 INTERMEDIATE_NAME is already canonical, then we need to
11014 copy it to the appropriate obstack. */
11015 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11016 name
= ((const char *)
11017 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11018 intermediate_name
.c_str (),
11019 intermediate_name
.length ()));
11021 name
= canonical_name
;
11028 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11029 If scope qualifiers are appropriate they will be added. The result
11030 will be allocated on the storage_obstack, or NULL if the DIE does
11031 not have a name. NAME may either be from a previous call to
11032 dwarf2_name or NULL.
11034 The output string will be canonicalized (if C++). */
11036 static const char *
11037 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11039 return dwarf2_compute_name (name
, die
, cu
, 0);
11042 /* Construct a physname for the given DIE in CU. NAME may either be
11043 from a previous call to dwarf2_name or NULL. The result will be
11044 allocated on the objfile_objstack or NULL if the DIE does not have a
11047 The output string will be canonicalized (if C++). */
11049 static const char *
11050 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11052 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11053 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11056 /* In this case dwarf2_compute_name is just a shortcut not building anything
11058 if (!die_needs_namespace (die
, cu
))
11059 return dwarf2_compute_name (name
, die
, cu
, 1);
11061 mangled
= dw2_linkage_name (die
, cu
);
11063 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11064 See https://github.com/rust-lang/rust/issues/32925. */
11065 if (cu
->language
== language_rust
&& mangled
!= NULL
11066 && strchr (mangled
, '{') != NULL
)
11069 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11071 gdb::unique_xmalloc_ptr
<char> demangled
;
11072 if (mangled
!= NULL
)
11075 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11077 /* Do nothing (do not demangle the symbol name). */
11079 else if (cu
->language
== language_go
)
11081 /* This is a lie, but we already lie to the caller new_symbol.
11082 new_symbol assumes we return the mangled name.
11083 This just undoes that lie until things are cleaned up. */
11087 /* Use DMGL_RET_DROP for C++ template functions to suppress
11088 their return type. It is easier for GDB users to search
11089 for such functions as `name(params)' than `long name(params)'.
11090 In such case the minimal symbol names do not match the full
11091 symbol names but for template functions there is never a need
11092 to look up their definition from their declaration so
11093 the only disadvantage remains the minimal symbol variant
11094 `long name(params)' does not have the proper inferior type. */
11095 demangled
.reset (gdb_demangle (mangled
,
11096 (DMGL_PARAMS
| DMGL_ANSI
11097 | DMGL_RET_DROP
)));
11100 canon
= demangled
.get ();
11108 if (canon
== NULL
|| check_physname
)
11110 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11112 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11114 /* It may not mean a bug in GDB. The compiler could also
11115 compute DW_AT_linkage_name incorrectly. But in such case
11116 GDB would need to be bug-to-bug compatible. */
11118 complaint (_("Computed physname <%s> does not match demangled <%s> "
11119 "(from linkage <%s>) - DIE at %s [in module %s]"),
11120 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11121 objfile_name (objfile
));
11123 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11124 is available here - over computed PHYSNAME. It is safer
11125 against both buggy GDB and buggy compilers. */
11139 retval
= ((const char *)
11140 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11141 retval
, strlen (retval
)));
11146 /* Inspect DIE in CU for a namespace alias. If one exists, record
11147 a new symbol for it.
11149 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11152 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11154 struct attribute
*attr
;
11156 /* If the die does not have a name, this is not a namespace
11158 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11162 struct die_info
*d
= die
;
11163 struct dwarf2_cu
*imported_cu
= cu
;
11165 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11166 keep inspecting DIEs until we hit the underlying import. */
11167 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11168 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11170 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11174 d
= follow_die_ref (d
, attr
, &imported_cu
);
11175 if (d
->tag
!= DW_TAG_imported_declaration
)
11179 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11181 complaint (_("DIE at %s has too many recursively imported "
11182 "declarations"), sect_offset_str (d
->sect_off
));
11189 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11191 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11192 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11194 /* This declaration is a global namespace alias. Add
11195 a symbol for it whose type is the aliased namespace. */
11196 new_symbol (die
, type
, cu
);
11205 /* Return the using directives repository (global or local?) to use in the
11206 current context for CU.
11208 For Ada, imported declarations can materialize renamings, which *may* be
11209 global. However it is impossible (for now?) in DWARF to distinguish
11210 "external" imported declarations and "static" ones. As all imported
11211 declarations seem to be static in all other languages, make them all CU-wide
11212 global only in Ada. */
11214 static struct using_direct
**
11215 using_directives (struct dwarf2_cu
*cu
)
11217 if (cu
->language
== language_ada
11218 && cu
->get_builder ()->outermost_context_p ())
11219 return cu
->get_builder ()->get_global_using_directives ();
11221 return cu
->get_builder ()->get_local_using_directives ();
11224 /* Read the import statement specified by the given die and record it. */
11227 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11229 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11230 struct attribute
*import_attr
;
11231 struct die_info
*imported_die
, *child_die
;
11232 struct dwarf2_cu
*imported_cu
;
11233 const char *imported_name
;
11234 const char *imported_name_prefix
;
11235 const char *canonical_name
;
11236 const char *import_alias
;
11237 const char *imported_declaration
= NULL
;
11238 const char *import_prefix
;
11239 std::vector
<const char *> excludes
;
11241 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11242 if (import_attr
== NULL
)
11244 complaint (_("Tag '%s' has no DW_AT_import"),
11245 dwarf_tag_name (die
->tag
));
11250 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11251 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11252 if (imported_name
== NULL
)
11254 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11256 The import in the following code:
11270 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11271 <52> DW_AT_decl_file : 1
11272 <53> DW_AT_decl_line : 6
11273 <54> DW_AT_import : <0x75>
11274 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11275 <59> DW_AT_name : B
11276 <5b> DW_AT_decl_file : 1
11277 <5c> DW_AT_decl_line : 2
11278 <5d> DW_AT_type : <0x6e>
11280 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11281 <76> DW_AT_byte_size : 4
11282 <77> DW_AT_encoding : 5 (signed)
11284 imports the wrong die ( 0x75 instead of 0x58 ).
11285 This case will be ignored until the gcc bug is fixed. */
11289 /* Figure out the local name after import. */
11290 import_alias
= dwarf2_name (die
, cu
);
11292 /* Figure out where the statement is being imported to. */
11293 import_prefix
= determine_prefix (die
, cu
);
11295 /* Figure out what the scope of the imported die is and prepend it
11296 to the name of the imported die. */
11297 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11299 if (imported_die
->tag
!= DW_TAG_namespace
11300 && imported_die
->tag
!= DW_TAG_module
)
11302 imported_declaration
= imported_name
;
11303 canonical_name
= imported_name_prefix
;
11305 else if (strlen (imported_name_prefix
) > 0)
11306 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11307 imported_name_prefix
,
11308 (cu
->language
== language_d
? "." : "::"),
11309 imported_name
, (char *) NULL
);
11311 canonical_name
= imported_name
;
11313 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11314 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11315 child_die
= sibling_die (child_die
))
11317 /* DWARF-4: A Fortran use statement with a “rename list” may be
11318 represented by an imported module entry with an import attribute
11319 referring to the module and owned entries corresponding to those
11320 entities that are renamed as part of being imported. */
11322 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11324 complaint (_("child DW_TAG_imported_declaration expected "
11325 "- DIE at %s [in module %s]"),
11326 sect_offset_str (child_die
->sect_off
),
11327 objfile_name (objfile
));
11331 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11332 if (import_attr
== NULL
)
11334 complaint (_("Tag '%s' has no DW_AT_import"),
11335 dwarf_tag_name (child_die
->tag
));
11340 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11342 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11343 if (imported_name
== NULL
)
11345 complaint (_("child DW_TAG_imported_declaration has unknown "
11346 "imported name - DIE at %s [in module %s]"),
11347 sect_offset_str (child_die
->sect_off
),
11348 objfile_name (objfile
));
11352 excludes
.push_back (imported_name
);
11354 process_die (child_die
, cu
);
11357 add_using_directive (using_directives (cu
),
11361 imported_declaration
,
11364 &objfile
->objfile_obstack
);
11367 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11368 types, but gives them a size of zero. Starting with version 14,
11369 ICC is compatible with GCC. */
11372 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11374 if (!cu
->checked_producer
)
11375 check_producer (cu
);
11377 return cu
->producer_is_icc_lt_14
;
11380 /* ICC generates a DW_AT_type for C void functions. This was observed on
11381 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11382 which says that void functions should not have a DW_AT_type. */
11385 producer_is_icc (struct dwarf2_cu
*cu
)
11387 if (!cu
->checked_producer
)
11388 check_producer (cu
);
11390 return cu
->producer_is_icc
;
11393 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11394 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11395 this, it was first present in GCC release 4.3.0. */
11398 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11400 if (!cu
->checked_producer
)
11401 check_producer (cu
);
11403 return cu
->producer_is_gcc_lt_4_3
;
11406 static file_and_directory
11407 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11409 file_and_directory res
;
11411 /* Find the filename. Do not use dwarf2_name here, since the filename
11412 is not a source language identifier. */
11413 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11414 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11416 if (res
.comp_dir
== NULL
11417 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11418 && IS_ABSOLUTE_PATH (res
.name
))
11420 res
.comp_dir_storage
= ldirname (res
.name
);
11421 if (!res
.comp_dir_storage
.empty ())
11422 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11424 if (res
.comp_dir
!= NULL
)
11426 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11427 directory, get rid of it. */
11428 const char *cp
= strchr (res
.comp_dir
, ':');
11430 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11431 res
.comp_dir
= cp
+ 1;
11434 if (res
.name
== NULL
)
11435 res
.name
= "<unknown>";
11440 /* Handle DW_AT_stmt_list for a compilation unit.
11441 DIE is the DW_TAG_compile_unit die for CU.
11442 COMP_DIR is the compilation directory. LOWPC is passed to
11443 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11446 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11447 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11449 struct dwarf2_per_objfile
*dwarf2_per_objfile
11450 = cu
->per_cu
->dwarf2_per_objfile
;
11451 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11452 struct attribute
*attr
;
11453 struct line_header line_header_local
;
11454 hashval_t line_header_local_hash
;
11456 int decode_mapping
;
11458 gdb_assert (! cu
->per_cu
->is_debug_types
);
11460 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11464 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11466 /* The line header hash table is only created if needed (it exists to
11467 prevent redundant reading of the line table for partial_units).
11468 If we're given a partial_unit, we'll need it. If we're given a
11469 compile_unit, then use the line header hash table if it's already
11470 created, but don't create one just yet. */
11472 if (dwarf2_per_objfile
->line_header_hash
== NULL
11473 && die
->tag
== DW_TAG_partial_unit
)
11475 dwarf2_per_objfile
->line_header_hash
11476 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11477 line_header_eq_voidp
,
11478 free_line_header_voidp
,
11479 &objfile
->objfile_obstack
,
11480 hashtab_obstack_allocate
,
11481 dummy_obstack_deallocate
);
11484 line_header_local
.sect_off
= line_offset
;
11485 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11486 line_header_local_hash
= line_header_hash (&line_header_local
);
11487 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11489 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11490 &line_header_local
,
11491 line_header_local_hash
, NO_INSERT
);
11493 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11494 is not present in *SLOT (since if there is something in *SLOT then
11495 it will be for a partial_unit). */
11496 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11498 gdb_assert (*slot
!= NULL
);
11499 cu
->line_header
= (struct line_header
*) *slot
;
11504 /* dwarf_decode_line_header does not yet provide sufficient information.
11505 We always have to call also dwarf_decode_lines for it. */
11506 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11510 cu
->line_header
= lh
.release ();
11511 cu
->line_header_die_owner
= die
;
11513 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11517 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11518 &line_header_local
,
11519 line_header_local_hash
, INSERT
);
11520 gdb_assert (slot
!= NULL
);
11522 if (slot
!= NULL
&& *slot
== NULL
)
11524 /* This newly decoded line number information unit will be owned
11525 by line_header_hash hash table. */
11526 *slot
= cu
->line_header
;
11527 cu
->line_header_die_owner
= NULL
;
11531 /* We cannot free any current entry in (*slot) as that struct line_header
11532 may be already used by multiple CUs. Create only temporary decoded
11533 line_header for this CU - it may happen at most once for each line
11534 number information unit. And if we're not using line_header_hash
11535 then this is what we want as well. */
11536 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11538 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11539 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11544 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11547 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11549 struct dwarf2_per_objfile
*dwarf2_per_objfile
11550 = cu
->per_cu
->dwarf2_per_objfile
;
11551 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11552 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11553 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11554 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11555 struct attribute
*attr
;
11556 struct die_info
*child_die
;
11557 CORE_ADDR baseaddr
;
11559 prepare_one_comp_unit (cu
, die
, cu
->language
);
11560 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11562 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11564 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11565 from finish_block. */
11566 if (lowpc
== ((CORE_ADDR
) -1))
11568 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11570 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11572 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11573 standardised yet. As a workaround for the language detection we fall
11574 back to the DW_AT_producer string. */
11575 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11576 cu
->language
= language_opencl
;
11578 /* Similar hack for Go. */
11579 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11580 set_cu_language (DW_LANG_Go
, cu
);
11582 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11584 /* Decode line number information if present. We do this before
11585 processing child DIEs, so that the line header table is available
11586 for DW_AT_decl_file. */
11587 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11589 /* Process all dies in compilation unit. */
11590 if (die
->child
!= NULL
)
11592 child_die
= die
->child
;
11593 while (child_die
&& child_die
->tag
)
11595 process_die (child_die
, cu
);
11596 child_die
= sibling_die (child_die
);
11600 /* Decode macro information, if present. Dwarf 2 macro information
11601 refers to information in the line number info statement program
11602 header, so we can only read it if we've read the header
11604 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11606 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11607 if (attr
&& cu
->line_header
)
11609 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11610 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11612 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11616 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11617 if (attr
&& cu
->line_header
)
11619 unsigned int macro_offset
= DW_UNSND (attr
);
11621 dwarf_decode_macros (cu
, macro_offset
, 0);
11627 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11629 struct type_unit_group
*tu_group
;
11631 struct attribute
*attr
;
11633 struct signatured_type
*sig_type
;
11635 gdb_assert (per_cu
->is_debug_types
);
11636 sig_type
= (struct signatured_type
*) per_cu
;
11638 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11640 /* If we're using .gdb_index (includes -readnow) then
11641 per_cu->type_unit_group may not have been set up yet. */
11642 if (sig_type
->type_unit_group
== NULL
)
11643 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11644 tu_group
= sig_type
->type_unit_group
;
11646 /* If we've already processed this stmt_list there's no real need to
11647 do it again, we could fake it and just recreate the part we need
11648 (file name,index -> symtab mapping). If data shows this optimization
11649 is useful we can do it then. */
11650 first_time
= tu_group
->compunit_symtab
== NULL
;
11652 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11657 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11658 lh
= dwarf_decode_line_header (line_offset
, this);
11663 start_symtab ("", NULL
, 0);
11666 gdb_assert (tu_group
->symtabs
== NULL
);
11667 gdb_assert (m_builder
== nullptr);
11668 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11669 m_builder
.reset (new struct buildsym_compunit
11670 (COMPUNIT_OBJFILE (cust
), "",
11671 COMPUNIT_DIRNAME (cust
),
11672 compunit_language (cust
),
11678 line_header
= lh
.release ();
11679 line_header_die_owner
= die
;
11683 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11685 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11686 still initializing it, and our caller (a few levels up)
11687 process_full_type_unit still needs to know if this is the first
11690 tu_group
->num_symtabs
= line_header
->file_names
.size ();
11691 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11692 line_header
->file_names
.size ());
11694 for (i
= 0; i
< line_header
->file_names
.size (); ++i
)
11696 file_entry
&fe
= line_header
->file_names
[i
];
11698 dwarf2_start_subfile (this, fe
.name
,
11699 fe
.include_dir (line_header
));
11700 buildsym_compunit
*b
= get_builder ();
11701 if (b
->get_current_subfile ()->symtab
== NULL
)
11703 /* NOTE: start_subfile will recognize when it's been
11704 passed a file it has already seen. So we can't
11705 assume there's a simple mapping from
11706 cu->line_header->file_names to subfiles, plus
11707 cu->line_header->file_names may contain dups. */
11708 b
->get_current_subfile ()->symtab
11709 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11712 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11713 tu_group
->symtabs
[i
] = fe
.symtab
;
11718 gdb_assert (m_builder
== nullptr);
11719 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11720 m_builder
.reset (new struct buildsym_compunit
11721 (COMPUNIT_OBJFILE (cust
), "",
11722 COMPUNIT_DIRNAME (cust
),
11723 compunit_language (cust
),
11726 for (i
= 0; i
< line_header
->file_names
.size (); ++i
)
11728 file_entry
&fe
= line_header
->file_names
[i
];
11730 fe
.symtab
= tu_group
->symtabs
[i
];
11734 /* The main symtab is allocated last. Type units don't have DW_AT_name
11735 so they don't have a "real" (so to speak) symtab anyway.
11736 There is later code that will assign the main symtab to all symbols
11737 that don't have one. We need to handle the case of a symbol with a
11738 missing symtab (DW_AT_decl_file) anyway. */
11741 /* Process DW_TAG_type_unit.
11742 For TUs we want to skip the first top level sibling if it's not the
11743 actual type being defined by this TU. In this case the first top
11744 level sibling is there to provide context only. */
11747 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11749 struct die_info
*child_die
;
11751 prepare_one_comp_unit (cu
, die
, language_minimal
);
11753 /* Initialize (or reinitialize) the machinery for building symtabs.
11754 We do this before processing child DIEs, so that the line header table
11755 is available for DW_AT_decl_file. */
11756 cu
->setup_type_unit_groups (die
);
11758 if (die
->child
!= NULL
)
11760 child_die
= die
->child
;
11761 while (child_die
&& child_die
->tag
)
11763 process_die (child_die
, cu
);
11764 child_die
= sibling_die (child_die
);
11771 http://gcc.gnu.org/wiki/DebugFission
11772 http://gcc.gnu.org/wiki/DebugFissionDWP
11774 To simplify handling of both DWO files ("object" files with the DWARF info)
11775 and DWP files (a file with the DWOs packaged up into one file), we treat
11776 DWP files as having a collection of virtual DWO files. */
11779 hash_dwo_file (const void *item
)
11781 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11784 hash
= htab_hash_string (dwo_file
->dwo_name
);
11785 if (dwo_file
->comp_dir
!= NULL
)
11786 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11791 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11793 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11794 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11796 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11798 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11799 return lhs
->comp_dir
== rhs
->comp_dir
;
11800 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11803 /* Allocate a hash table for DWO files. */
11806 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11808 return htab_create_alloc_ex (41,
11812 &objfile
->objfile_obstack
,
11813 hashtab_obstack_allocate
,
11814 dummy_obstack_deallocate
);
11817 /* Lookup DWO file DWO_NAME. */
11820 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11821 const char *dwo_name
,
11822 const char *comp_dir
)
11824 struct dwo_file find_entry
;
11827 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11828 dwarf2_per_objfile
->dwo_files
11829 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11831 memset (&find_entry
, 0, sizeof (find_entry
));
11832 find_entry
.dwo_name
= dwo_name
;
11833 find_entry
.comp_dir
= comp_dir
;
11834 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
11840 hash_dwo_unit (const void *item
)
11842 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11844 /* This drops the top 32 bits of the id, but is ok for a hash. */
11845 return dwo_unit
->signature
;
11849 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11851 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11852 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11854 /* The signature is assumed to be unique within the DWO file.
11855 So while object file CU dwo_id's always have the value zero,
11856 that's OK, assuming each object file DWO file has only one CU,
11857 and that's the rule for now. */
11858 return lhs
->signature
== rhs
->signature
;
11861 /* Allocate a hash table for DWO CUs,TUs.
11862 There is one of these tables for each of CUs,TUs for each DWO file. */
11865 allocate_dwo_unit_table (struct objfile
*objfile
)
11867 /* Start out with a pretty small number.
11868 Generally DWO files contain only one CU and maybe some TUs. */
11869 return htab_create_alloc_ex (3,
11873 &objfile
->objfile_obstack
,
11874 hashtab_obstack_allocate
,
11875 dummy_obstack_deallocate
);
11878 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11880 struct create_dwo_cu_data
11882 struct dwo_file
*dwo_file
;
11883 struct dwo_unit dwo_unit
;
11886 /* die_reader_func for create_dwo_cu. */
11889 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11890 const gdb_byte
*info_ptr
,
11891 struct die_info
*comp_unit_die
,
11895 struct dwarf2_cu
*cu
= reader
->cu
;
11896 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11897 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11898 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11899 struct dwo_file
*dwo_file
= data
->dwo_file
;
11900 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11901 struct attribute
*attr
;
11903 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
11906 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11907 " its dwo_id [in module %s]"),
11908 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11912 dwo_unit
->dwo_file
= dwo_file
;
11913 dwo_unit
->signature
= DW_UNSND (attr
);
11914 dwo_unit
->section
= section
;
11915 dwo_unit
->sect_off
= sect_off
;
11916 dwo_unit
->length
= cu
->per_cu
->length
;
11918 if (dwarf_read_debug
)
11919 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11920 sect_offset_str (sect_off
),
11921 hex_string (dwo_unit
->signature
));
11924 /* Create the dwo_units for the CUs in a DWO_FILE.
11925 Note: This function processes DWO files only, not DWP files. */
11928 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11929 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11932 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11933 const gdb_byte
*info_ptr
, *end_ptr
;
11935 dwarf2_read_section (objfile
, §ion
);
11936 info_ptr
= section
.buffer
;
11938 if (info_ptr
== NULL
)
11941 if (dwarf_read_debug
)
11943 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11944 get_section_name (§ion
),
11945 get_section_file_name (§ion
));
11948 end_ptr
= info_ptr
+ section
.size
;
11949 while (info_ptr
< end_ptr
)
11951 struct dwarf2_per_cu_data per_cu
;
11952 struct create_dwo_cu_data create_dwo_cu_data
;
11953 struct dwo_unit
*dwo_unit
;
11955 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11957 memset (&create_dwo_cu_data
.dwo_unit
, 0,
11958 sizeof (create_dwo_cu_data
.dwo_unit
));
11959 memset (&per_cu
, 0, sizeof (per_cu
));
11960 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11961 per_cu
.is_debug_types
= 0;
11962 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11963 per_cu
.section
= §ion
;
11964 create_dwo_cu_data
.dwo_file
= &dwo_file
;
11966 init_cutu_and_read_dies_no_follow (
11967 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
11968 info_ptr
+= per_cu
.length
;
11970 // If the unit could not be parsed, skip it.
11971 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
11974 if (cus_htab
== NULL
)
11975 cus_htab
= allocate_dwo_unit_table (objfile
);
11977 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11978 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
11979 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
11980 gdb_assert (slot
!= NULL
);
11983 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11984 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11986 complaint (_("debug cu entry at offset %s is duplicate to"
11987 " the entry at offset %s, signature %s"),
11988 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11989 hex_string (dwo_unit
->signature
));
11991 *slot
= (void *)dwo_unit
;
11995 /* DWP file .debug_{cu,tu}_index section format:
11996 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12000 Both index sections have the same format, and serve to map a 64-bit
12001 signature to a set of section numbers. Each section begins with a header,
12002 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12003 indexes, and a pool of 32-bit section numbers. The index sections will be
12004 aligned at 8-byte boundaries in the file.
12006 The index section header consists of:
12008 V, 32 bit version number
12010 N, 32 bit number of compilation units or type units in the index
12011 M, 32 bit number of slots in the hash table
12013 Numbers are recorded using the byte order of the application binary.
12015 The hash table begins at offset 16 in the section, and consists of an array
12016 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12017 order of the application binary). Unused slots in the hash table are 0.
12018 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12020 The parallel table begins immediately after the hash table
12021 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12022 array of 32-bit indexes (using the byte order of the application binary),
12023 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12024 table contains a 32-bit index into the pool of section numbers. For unused
12025 hash table slots, the corresponding entry in the parallel table will be 0.
12027 The pool of section numbers begins immediately following the hash table
12028 (at offset 16 + 12 * M from the beginning of the section). The pool of
12029 section numbers consists of an array of 32-bit words (using the byte order
12030 of the application binary). Each item in the array is indexed starting
12031 from 0. The hash table entry provides the index of the first section
12032 number in the set. Additional section numbers in the set follow, and the
12033 set is terminated by a 0 entry (section number 0 is not used in ELF).
12035 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12036 section must be the first entry in the set, and the .debug_abbrev.dwo must
12037 be the second entry. Other members of the set may follow in any order.
12043 DWP Version 2 combines all the .debug_info, etc. sections into one,
12044 and the entries in the index tables are now offsets into these sections.
12045 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12048 Index Section Contents:
12050 Hash Table of Signatures dwp_hash_table.hash_table
12051 Parallel Table of Indices dwp_hash_table.unit_table
12052 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12053 Table of Section Sizes dwp_hash_table.v2.sizes
12055 The index section header consists of:
12057 V, 32 bit version number
12058 L, 32 bit number of columns in the table of section offsets
12059 N, 32 bit number of compilation units or type units in the index
12060 M, 32 bit number of slots in the hash table
12062 Numbers are recorded using the byte order of the application binary.
12064 The hash table has the same format as version 1.
12065 The parallel table of indices has the same format as version 1,
12066 except that the entries are origin-1 indices into the table of sections
12067 offsets and the table of section sizes.
12069 The table of offsets begins immediately following the parallel table
12070 (at offset 16 + 12 * M from the beginning of the section). The table is
12071 a two-dimensional array of 32-bit words (using the byte order of the
12072 application binary), with L columns and N+1 rows, in row-major order.
12073 Each row in the array is indexed starting from 0. The first row provides
12074 a key to the remaining rows: each column in this row provides an identifier
12075 for a debug section, and the offsets in the same column of subsequent rows
12076 refer to that section. The section identifiers are:
12078 DW_SECT_INFO 1 .debug_info.dwo
12079 DW_SECT_TYPES 2 .debug_types.dwo
12080 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12081 DW_SECT_LINE 4 .debug_line.dwo
12082 DW_SECT_LOC 5 .debug_loc.dwo
12083 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12084 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12085 DW_SECT_MACRO 8 .debug_macro.dwo
12087 The offsets provided by the CU and TU index sections are the base offsets
12088 for the contributions made by each CU or TU to the corresponding section
12089 in the package file. Each CU and TU header contains an abbrev_offset
12090 field, used to find the abbreviations table for that CU or TU within the
12091 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12092 be interpreted as relative to the base offset given in the index section.
12093 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12094 should be interpreted as relative to the base offset for .debug_line.dwo,
12095 and offsets into other debug sections obtained from DWARF attributes should
12096 also be interpreted as relative to the corresponding base offset.
12098 The table of sizes begins immediately following the table of offsets.
12099 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12100 with L columns and N rows, in row-major order. Each row in the array is
12101 indexed starting from 1 (row 0 is shared by the two tables).
12105 Hash table lookup is handled the same in version 1 and 2:
12107 We assume that N and M will not exceed 2^32 - 1.
12108 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12110 Given a 64-bit compilation unit signature or a type signature S, an entry
12111 in the hash table is located as follows:
12113 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12114 the low-order k bits all set to 1.
12116 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12118 3) If the hash table entry at index H matches the signature, use that
12119 entry. If the hash table entry at index H is unused (all zeroes),
12120 terminate the search: the signature is not present in the table.
12122 4) Let H = (H + H') modulo M. Repeat at Step 3.
12124 Because M > N and H' and M are relatively prime, the search is guaranteed
12125 to stop at an unused slot or find the match. */
12127 /* Create a hash table to map DWO IDs to their CU/TU entry in
12128 .debug_{info,types}.dwo in DWP_FILE.
12129 Returns NULL if there isn't one.
12130 Note: This function processes DWP files only, not DWO files. */
12132 static struct dwp_hash_table
*
12133 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12134 struct dwp_file
*dwp_file
, int is_debug_types
)
12136 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12137 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12138 const gdb_byte
*index_ptr
, *index_end
;
12139 struct dwarf2_section_info
*index
;
12140 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12141 struct dwp_hash_table
*htab
;
12143 if (is_debug_types
)
12144 index
= &dwp_file
->sections
.tu_index
;
12146 index
= &dwp_file
->sections
.cu_index
;
12148 if (dwarf2_section_empty_p (index
))
12150 dwarf2_read_section (objfile
, index
);
12152 index_ptr
= index
->buffer
;
12153 index_end
= index_ptr
+ index
->size
;
12155 version
= read_4_bytes (dbfd
, index_ptr
);
12158 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12162 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12164 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12167 if (version
!= 1 && version
!= 2)
12169 error (_("Dwarf Error: unsupported DWP file version (%s)"
12170 " [in module %s]"),
12171 pulongest (version
), dwp_file
->name
);
12173 if (nr_slots
!= (nr_slots
& -nr_slots
))
12175 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12176 " is not power of 2 [in module %s]"),
12177 pulongest (nr_slots
), dwp_file
->name
);
12180 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12181 htab
->version
= version
;
12182 htab
->nr_columns
= nr_columns
;
12183 htab
->nr_units
= nr_units
;
12184 htab
->nr_slots
= nr_slots
;
12185 htab
->hash_table
= index_ptr
;
12186 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12188 /* Exit early if the table is empty. */
12189 if (nr_slots
== 0 || nr_units
== 0
12190 || (version
== 2 && nr_columns
== 0))
12192 /* All must be zero. */
12193 if (nr_slots
!= 0 || nr_units
!= 0
12194 || (version
== 2 && nr_columns
!= 0))
12196 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
12197 " all zero [in modules %s]"),
12205 htab
->section_pool
.v1
.indices
=
12206 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12207 /* It's harder to decide whether the section is too small in v1.
12208 V1 is deprecated anyway so we punt. */
12212 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12213 int *ids
= htab
->section_pool
.v2
.section_ids
;
12214 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
12215 /* Reverse map for error checking. */
12216 int ids_seen
[DW_SECT_MAX
+ 1];
12219 if (nr_columns
< 2)
12221 error (_("Dwarf Error: bad DWP hash table, too few columns"
12222 " in section table [in module %s]"),
12225 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12227 error (_("Dwarf Error: bad DWP hash table, too many columns"
12228 " in section table [in module %s]"),
12231 memset (ids
, 255, sizeof_ids
);
12232 memset (ids_seen
, 255, sizeof (ids_seen
));
12233 for (i
= 0; i
< nr_columns
; ++i
)
12235 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12237 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12239 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12240 " in section table [in module %s]"),
12241 id
, dwp_file
->name
);
12243 if (ids_seen
[id
] != -1)
12245 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12246 " id %d in section table [in module %s]"),
12247 id
, dwp_file
->name
);
12252 /* Must have exactly one info or types section. */
12253 if (((ids_seen
[DW_SECT_INFO
] != -1)
12254 + (ids_seen
[DW_SECT_TYPES
] != -1))
12257 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12258 " DWO info/types section [in module %s]"),
12261 /* Must have an abbrev section. */
12262 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12264 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12265 " section [in module %s]"),
12268 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12269 htab
->section_pool
.v2
.sizes
=
12270 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12271 * nr_units
* nr_columns
);
12272 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12273 * nr_units
* nr_columns
))
12276 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12277 " [in module %s]"),
12285 /* Update SECTIONS with the data from SECTP.
12287 This function is like the other "locate" section routines that are
12288 passed to bfd_map_over_sections, but in this context the sections to
12289 read comes from the DWP V1 hash table, not the full ELF section table.
12291 The result is non-zero for success, or zero if an error was found. */
12294 locate_v1_virtual_dwo_sections (asection
*sectp
,
12295 struct virtual_v1_dwo_sections
*sections
)
12297 const struct dwop_section_names
*names
= &dwop_section_names
;
12299 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12301 /* There can be only one. */
12302 if (sections
->abbrev
.s
.section
!= NULL
)
12304 sections
->abbrev
.s
.section
= sectp
;
12305 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12307 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12308 || section_is_p (sectp
->name
, &names
->types_dwo
))
12310 /* There can be only one. */
12311 if (sections
->info_or_types
.s
.section
!= NULL
)
12313 sections
->info_or_types
.s
.section
= sectp
;
12314 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
12316 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12318 /* There can be only one. */
12319 if (sections
->line
.s
.section
!= NULL
)
12321 sections
->line
.s
.section
= sectp
;
12322 sections
->line
.size
= bfd_get_section_size (sectp
);
12324 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12326 /* There can be only one. */
12327 if (sections
->loc
.s
.section
!= NULL
)
12329 sections
->loc
.s
.section
= sectp
;
12330 sections
->loc
.size
= bfd_get_section_size (sectp
);
12332 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12334 /* There can be only one. */
12335 if (sections
->macinfo
.s
.section
!= NULL
)
12337 sections
->macinfo
.s
.section
= sectp
;
12338 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12340 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12342 /* There can be only one. */
12343 if (sections
->macro
.s
.section
!= NULL
)
12345 sections
->macro
.s
.section
= sectp
;
12346 sections
->macro
.size
= bfd_get_section_size (sectp
);
12348 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12350 /* There can be only one. */
12351 if (sections
->str_offsets
.s
.section
!= NULL
)
12353 sections
->str_offsets
.s
.section
= sectp
;
12354 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12358 /* No other kind of section is valid. */
12365 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12366 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12367 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12368 This is for DWP version 1 files. */
12370 static struct dwo_unit
*
12371 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12372 struct dwp_file
*dwp_file
,
12373 uint32_t unit_index
,
12374 const char *comp_dir
,
12375 ULONGEST signature
, int is_debug_types
)
12377 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12378 const struct dwp_hash_table
*dwp_htab
=
12379 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12380 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12381 const char *kind
= is_debug_types
? "TU" : "CU";
12382 struct dwo_file
*dwo_file
;
12383 struct dwo_unit
*dwo_unit
;
12384 struct virtual_v1_dwo_sections sections
;
12385 void **dwo_file_slot
;
12388 gdb_assert (dwp_file
->version
== 1);
12390 if (dwarf_read_debug
)
12392 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12394 pulongest (unit_index
), hex_string (signature
),
12398 /* Fetch the sections of this DWO unit.
12399 Put a limit on the number of sections we look for so that bad data
12400 doesn't cause us to loop forever. */
12402 #define MAX_NR_V1_DWO_SECTIONS \
12403 (1 /* .debug_info or .debug_types */ \
12404 + 1 /* .debug_abbrev */ \
12405 + 1 /* .debug_line */ \
12406 + 1 /* .debug_loc */ \
12407 + 1 /* .debug_str_offsets */ \
12408 + 1 /* .debug_macro or .debug_macinfo */ \
12409 + 1 /* trailing zero */)
12411 memset (§ions
, 0, sizeof (sections
));
12413 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12416 uint32_t section_nr
=
12417 read_4_bytes (dbfd
,
12418 dwp_htab
->section_pool
.v1
.indices
12419 + (unit_index
+ i
) * sizeof (uint32_t));
12421 if (section_nr
== 0)
12423 if (section_nr
>= dwp_file
->num_sections
)
12425 error (_("Dwarf Error: bad DWP hash table, section number too large"
12426 " [in module %s]"),
12430 sectp
= dwp_file
->elf_sections
[section_nr
];
12431 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12433 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12434 " [in module %s]"),
12440 || dwarf2_section_empty_p (§ions
.info_or_types
)
12441 || dwarf2_section_empty_p (§ions
.abbrev
))
12443 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12444 " [in module %s]"),
12447 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12449 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12450 " [in module %s]"),
12454 /* It's easier for the rest of the code if we fake a struct dwo_file and
12455 have dwo_unit "live" in that. At least for now.
12457 The DWP file can be made up of a random collection of CUs and TUs.
12458 However, for each CU + set of TUs that came from the same original DWO
12459 file, we can combine them back into a virtual DWO file to save space
12460 (fewer struct dwo_file objects to allocate). Remember that for really
12461 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12463 std::string virtual_dwo_name
=
12464 string_printf ("virtual-dwo/%d-%d-%d-%d",
12465 get_section_id (§ions
.abbrev
),
12466 get_section_id (§ions
.line
),
12467 get_section_id (§ions
.loc
),
12468 get_section_id (§ions
.str_offsets
));
12469 /* Can we use an existing virtual DWO file? */
12470 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12471 virtual_dwo_name
.c_str (),
12473 /* Create one if necessary. */
12474 if (*dwo_file_slot
== NULL
)
12476 if (dwarf_read_debug
)
12478 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12479 virtual_dwo_name
.c_str ());
12481 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12483 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12484 virtual_dwo_name
.c_str (),
12485 virtual_dwo_name
.size ());
12486 dwo_file
->comp_dir
= comp_dir
;
12487 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12488 dwo_file
->sections
.line
= sections
.line
;
12489 dwo_file
->sections
.loc
= sections
.loc
;
12490 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12491 dwo_file
->sections
.macro
= sections
.macro
;
12492 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12493 /* The "str" section is global to the entire DWP file. */
12494 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12495 /* The info or types section is assigned below to dwo_unit,
12496 there's no need to record it in dwo_file.
12497 Also, we can't simply record type sections in dwo_file because
12498 we record a pointer into the vector in dwo_unit. As we collect more
12499 types we'll grow the vector and eventually have to reallocate space
12500 for it, invalidating all copies of pointers into the previous
12502 *dwo_file_slot
= dwo_file
;
12506 if (dwarf_read_debug
)
12508 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12509 virtual_dwo_name
.c_str ());
12511 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12514 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12515 dwo_unit
->dwo_file
= dwo_file
;
12516 dwo_unit
->signature
= signature
;
12517 dwo_unit
->section
=
12518 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12519 *dwo_unit
->section
= sections
.info_or_types
;
12520 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12525 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12526 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12527 piece within that section used by a TU/CU, return a virtual section
12528 of just that piece. */
12530 static struct dwarf2_section_info
12531 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12532 struct dwarf2_section_info
*section
,
12533 bfd_size_type offset
, bfd_size_type size
)
12535 struct dwarf2_section_info result
;
12538 gdb_assert (section
!= NULL
);
12539 gdb_assert (!section
->is_virtual
);
12541 memset (&result
, 0, sizeof (result
));
12542 result
.s
.containing_section
= section
;
12543 result
.is_virtual
= 1;
12548 sectp
= get_section_bfd_section (section
);
12550 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12551 bounds of the real section. This is a pretty-rare event, so just
12552 flag an error (easier) instead of a warning and trying to cope. */
12554 || offset
+ size
> bfd_get_section_size (sectp
))
12556 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12557 " in section %s [in module %s]"),
12558 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
12559 objfile_name (dwarf2_per_objfile
->objfile
));
12562 result
.virtual_offset
= offset
;
12563 result
.size
= size
;
12567 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12568 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12569 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12570 This is for DWP version 2 files. */
12572 static struct dwo_unit
*
12573 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12574 struct dwp_file
*dwp_file
,
12575 uint32_t unit_index
,
12576 const char *comp_dir
,
12577 ULONGEST signature
, int is_debug_types
)
12579 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12580 const struct dwp_hash_table
*dwp_htab
=
12581 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12582 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12583 const char *kind
= is_debug_types
? "TU" : "CU";
12584 struct dwo_file
*dwo_file
;
12585 struct dwo_unit
*dwo_unit
;
12586 struct virtual_v2_dwo_sections sections
;
12587 void **dwo_file_slot
;
12590 gdb_assert (dwp_file
->version
== 2);
12592 if (dwarf_read_debug
)
12594 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12596 pulongest (unit_index
), hex_string (signature
),
12600 /* Fetch the section offsets of this DWO unit. */
12602 memset (§ions
, 0, sizeof (sections
));
12604 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12606 uint32_t offset
= read_4_bytes (dbfd
,
12607 dwp_htab
->section_pool
.v2
.offsets
12608 + (((unit_index
- 1) * dwp_htab
->nr_columns
12610 * sizeof (uint32_t)));
12611 uint32_t size
= read_4_bytes (dbfd
,
12612 dwp_htab
->section_pool
.v2
.sizes
12613 + (((unit_index
- 1) * dwp_htab
->nr_columns
12615 * sizeof (uint32_t)));
12617 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12620 case DW_SECT_TYPES
:
12621 sections
.info_or_types_offset
= offset
;
12622 sections
.info_or_types_size
= size
;
12624 case DW_SECT_ABBREV
:
12625 sections
.abbrev_offset
= offset
;
12626 sections
.abbrev_size
= size
;
12629 sections
.line_offset
= offset
;
12630 sections
.line_size
= size
;
12633 sections
.loc_offset
= offset
;
12634 sections
.loc_size
= size
;
12636 case DW_SECT_STR_OFFSETS
:
12637 sections
.str_offsets_offset
= offset
;
12638 sections
.str_offsets_size
= size
;
12640 case DW_SECT_MACINFO
:
12641 sections
.macinfo_offset
= offset
;
12642 sections
.macinfo_size
= size
;
12644 case DW_SECT_MACRO
:
12645 sections
.macro_offset
= offset
;
12646 sections
.macro_size
= size
;
12651 /* It's easier for the rest of the code if we fake a struct dwo_file and
12652 have dwo_unit "live" in that. At least for now.
12654 The DWP file can be made up of a random collection of CUs and TUs.
12655 However, for each CU + set of TUs that came from the same original DWO
12656 file, we can combine them back into a virtual DWO file to save space
12657 (fewer struct dwo_file objects to allocate). Remember that for really
12658 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12660 std::string virtual_dwo_name
=
12661 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12662 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12663 (long) (sections
.line_size
? sections
.line_offset
: 0),
12664 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12665 (long) (sections
.str_offsets_size
12666 ? sections
.str_offsets_offset
: 0));
12667 /* Can we use an existing virtual DWO file? */
12668 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12669 virtual_dwo_name
.c_str (),
12671 /* Create one if necessary. */
12672 if (*dwo_file_slot
== NULL
)
12674 if (dwarf_read_debug
)
12676 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12677 virtual_dwo_name
.c_str ());
12679 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12681 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12682 virtual_dwo_name
.c_str (),
12683 virtual_dwo_name
.size ());
12684 dwo_file
->comp_dir
= comp_dir
;
12685 dwo_file
->sections
.abbrev
=
12686 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12687 sections
.abbrev_offset
, sections
.abbrev_size
);
12688 dwo_file
->sections
.line
=
12689 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12690 sections
.line_offset
, sections
.line_size
);
12691 dwo_file
->sections
.loc
=
12692 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12693 sections
.loc_offset
, sections
.loc_size
);
12694 dwo_file
->sections
.macinfo
=
12695 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12696 sections
.macinfo_offset
, sections
.macinfo_size
);
12697 dwo_file
->sections
.macro
=
12698 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12699 sections
.macro_offset
, sections
.macro_size
);
12700 dwo_file
->sections
.str_offsets
=
12701 create_dwp_v2_section (dwarf2_per_objfile
,
12702 &dwp_file
->sections
.str_offsets
,
12703 sections
.str_offsets_offset
,
12704 sections
.str_offsets_size
);
12705 /* The "str" section is global to the entire DWP file. */
12706 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12707 /* The info or types section is assigned below to dwo_unit,
12708 there's no need to record it in dwo_file.
12709 Also, we can't simply record type sections in dwo_file because
12710 we record a pointer into the vector in dwo_unit. As we collect more
12711 types we'll grow the vector and eventually have to reallocate space
12712 for it, invalidating all copies of pointers into the previous
12714 *dwo_file_slot
= dwo_file
;
12718 if (dwarf_read_debug
)
12720 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12721 virtual_dwo_name
.c_str ());
12723 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12726 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12727 dwo_unit
->dwo_file
= dwo_file
;
12728 dwo_unit
->signature
= signature
;
12729 dwo_unit
->section
=
12730 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12731 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12733 ? &dwp_file
->sections
.types
12734 : &dwp_file
->sections
.info
,
12735 sections
.info_or_types_offset
,
12736 sections
.info_or_types_size
);
12737 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12742 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12743 Returns NULL if the signature isn't found. */
12745 static struct dwo_unit
*
12746 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12747 struct dwp_file
*dwp_file
, const char *comp_dir
,
12748 ULONGEST signature
, int is_debug_types
)
12750 const struct dwp_hash_table
*dwp_htab
=
12751 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12752 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12753 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12754 uint32_t hash
= signature
& mask
;
12755 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12758 struct dwo_unit find_dwo_cu
;
12760 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12761 find_dwo_cu
.signature
= signature
;
12762 slot
= htab_find_slot (is_debug_types
12763 ? dwp_file
->loaded_tus
12764 : dwp_file
->loaded_cus
,
12765 &find_dwo_cu
, INSERT
);
12768 return (struct dwo_unit
*) *slot
;
12770 /* Use a for loop so that we don't loop forever on bad debug info. */
12771 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12773 ULONGEST signature_in_table
;
12775 signature_in_table
=
12776 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12777 if (signature_in_table
== signature
)
12779 uint32_t unit_index
=
12780 read_4_bytes (dbfd
,
12781 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12783 if (dwp_file
->version
== 1)
12785 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12786 dwp_file
, unit_index
,
12787 comp_dir
, signature
,
12792 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12793 dwp_file
, unit_index
,
12794 comp_dir
, signature
,
12797 return (struct dwo_unit
*) *slot
;
12799 if (signature_in_table
== 0)
12801 hash
= (hash
+ hash2
) & mask
;
12804 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12805 " [in module %s]"),
12809 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12810 Open the file specified by FILE_NAME and hand it off to BFD for
12811 preliminary analysis. Return a newly initialized bfd *, which
12812 includes a canonicalized copy of FILE_NAME.
12813 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12814 SEARCH_CWD is true if the current directory is to be searched.
12815 It will be searched before debug-file-directory.
12816 If successful, the file is added to the bfd include table of the
12817 objfile's bfd (see gdb_bfd_record_inclusion).
12818 If unable to find/open the file, return NULL.
12819 NOTE: This function is derived from symfile_bfd_open. */
12821 static gdb_bfd_ref_ptr
12822 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12823 const char *file_name
, int is_dwp
, int search_cwd
)
12826 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12827 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12828 to debug_file_directory. */
12829 const char *search_path
;
12830 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12832 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12835 if (*debug_file_directory
!= '\0')
12837 search_path_holder
.reset (concat (".", dirname_separator_string
,
12838 debug_file_directory
,
12840 search_path
= search_path_holder
.get ();
12846 search_path
= debug_file_directory
;
12848 openp_flags flags
= OPF_RETURN_REALPATH
;
12850 flags
|= OPF_SEARCH_IN_PATH
;
12852 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12853 desc
= openp (search_path
, flags
, file_name
,
12854 O_RDONLY
| O_BINARY
, &absolute_name
);
12858 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12860 if (sym_bfd
== NULL
)
12862 bfd_set_cacheable (sym_bfd
.get (), 1);
12864 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12867 /* Success. Record the bfd as having been included by the objfile's bfd.
12868 This is important because things like demangled_names_hash lives in the
12869 objfile's per_bfd space and may have references to things like symbol
12870 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12871 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12876 /* Try to open DWO file FILE_NAME.
12877 COMP_DIR is the DW_AT_comp_dir attribute.
12878 The result is the bfd handle of the file.
12879 If there is a problem finding or opening the file, return NULL.
12880 Upon success, the canonicalized path of the file is stored in the bfd,
12881 same as symfile_bfd_open. */
12883 static gdb_bfd_ref_ptr
12884 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12885 const char *file_name
, const char *comp_dir
)
12887 if (IS_ABSOLUTE_PATH (file_name
))
12888 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12889 0 /*is_dwp*/, 0 /*search_cwd*/);
12891 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12893 if (comp_dir
!= NULL
)
12895 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
12896 file_name
, (char *) NULL
);
12898 /* NOTE: If comp_dir is a relative path, this will also try the
12899 search path, which seems useful. */
12900 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12903 1 /*search_cwd*/));
12904 xfree (path_to_try
);
12909 /* That didn't work, try debug-file-directory, which, despite its name,
12910 is a list of paths. */
12912 if (*debug_file_directory
== '\0')
12915 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12916 0 /*is_dwp*/, 1 /*search_cwd*/);
12919 /* This function is mapped across the sections and remembers the offset and
12920 size of each of the DWO debugging sections we are interested in. */
12923 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12925 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12926 const struct dwop_section_names
*names
= &dwop_section_names
;
12928 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12930 dwo_sections
->abbrev
.s
.section
= sectp
;
12931 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12933 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12935 dwo_sections
->info
.s
.section
= sectp
;
12936 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
12938 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12940 dwo_sections
->line
.s
.section
= sectp
;
12941 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
12943 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12945 dwo_sections
->loc
.s
.section
= sectp
;
12946 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
12948 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12950 dwo_sections
->macinfo
.s
.section
= sectp
;
12951 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12953 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12955 dwo_sections
->macro
.s
.section
= sectp
;
12956 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
12958 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12960 dwo_sections
->str
.s
.section
= sectp
;
12961 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
12963 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12965 dwo_sections
->str_offsets
.s
.section
= sectp
;
12966 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12968 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12970 struct dwarf2_section_info type_section
;
12972 memset (&type_section
, 0, sizeof (type_section
));
12973 type_section
.s
.section
= sectp
;
12974 type_section
.size
= bfd_get_section_size (sectp
);
12975 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
12980 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12981 by PER_CU. This is for the non-DWP case.
12982 The result is NULL if DWO_NAME can't be found. */
12984 static struct dwo_file
*
12985 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12986 const char *dwo_name
, const char *comp_dir
)
12988 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12989 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12991 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
));
12994 if (dwarf_read_debug
)
12995 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12999 /* We use a unique pointer here, despite the obstack allocation,
13000 because a dwo_file needs some cleanup if it is abandoned. */
13001 dwo_file_up
dwo_file (OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
13003 dwo_file
->dwo_name
= dwo_name
;
13004 dwo_file
->comp_dir
= comp_dir
;
13005 dwo_file
->dbfd
= dbfd
.release ();
13007 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
13008 &dwo_file
->sections
);
13010 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13013 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
13014 dwo_file
->sections
.types
, dwo_file
->tus
);
13016 if (dwarf_read_debug
)
13017 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13019 return dwo_file
.release ();
13022 /* This function is mapped across the sections and remembers the offset and
13023 size of each of the DWP debugging sections common to version 1 and 2 that
13024 we are interested in. */
13027 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13028 void *dwp_file_ptr
)
13030 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13031 const struct dwop_section_names
*names
= &dwop_section_names
;
13032 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13034 /* Record the ELF section number for later lookup: this is what the
13035 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13036 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13037 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13039 /* Look for specific sections that we need. */
13040 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13042 dwp_file
->sections
.str
.s
.section
= sectp
;
13043 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
13045 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13047 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13048 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
13050 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13052 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13053 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
13057 /* This function is mapped across the sections and remembers the offset and
13058 size of each of the DWP version 2 debugging sections that we are interested
13059 in. This is split into a separate function because we don't know if we
13060 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13063 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13065 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13066 const struct dwop_section_names
*names
= &dwop_section_names
;
13067 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13069 /* Record the ELF section number for later lookup: this is what the
13070 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13071 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13072 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13074 /* Look for specific sections that we need. */
13075 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13077 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13078 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
13080 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13082 dwp_file
->sections
.info
.s
.section
= sectp
;
13083 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
13085 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13087 dwp_file
->sections
.line
.s
.section
= sectp
;
13088 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
13090 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13092 dwp_file
->sections
.loc
.s
.section
= sectp
;
13093 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
13095 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13097 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13098 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
13100 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13102 dwp_file
->sections
.macro
.s
.section
= sectp
;
13103 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
13105 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13107 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13108 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
13110 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13112 dwp_file
->sections
.types
.s
.section
= sectp
;
13113 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
13117 /* Hash function for dwp_file loaded CUs/TUs. */
13120 hash_dwp_loaded_cutus (const void *item
)
13122 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13124 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13125 return dwo_unit
->signature
;
13128 /* Equality function for dwp_file loaded CUs/TUs. */
13131 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13133 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13134 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13136 return dua
->signature
== dub
->signature
;
13139 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13142 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13144 return htab_create_alloc_ex (3,
13145 hash_dwp_loaded_cutus
,
13146 eq_dwp_loaded_cutus
,
13148 &objfile
->objfile_obstack
,
13149 hashtab_obstack_allocate
,
13150 dummy_obstack_deallocate
);
13153 /* Try to open DWP file FILE_NAME.
13154 The result is the bfd handle of the file.
13155 If there is a problem finding or opening the file, return NULL.
13156 Upon success, the canonicalized path of the file is stored in the bfd,
13157 same as symfile_bfd_open. */
13159 static gdb_bfd_ref_ptr
13160 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13161 const char *file_name
)
13163 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13165 1 /*search_cwd*/));
13169 /* Work around upstream bug 15652.
13170 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13171 [Whether that's a "bug" is debatable, but it is getting in our way.]
13172 We have no real idea where the dwp file is, because gdb's realpath-ing
13173 of the executable's path may have discarded the needed info.
13174 [IWBN if the dwp file name was recorded in the executable, akin to
13175 .gnu_debuglink, but that doesn't exist yet.]
13176 Strip the directory from FILE_NAME and search again. */
13177 if (*debug_file_directory
!= '\0')
13179 /* Don't implicitly search the current directory here.
13180 If the user wants to search "." to handle this case,
13181 it must be added to debug-file-directory. */
13182 return try_open_dwop_file (dwarf2_per_objfile
,
13183 lbasename (file_name
), 1 /*is_dwp*/,
13190 /* Initialize the use of the DWP file for the current objfile.
13191 By convention the name of the DWP file is ${objfile}.dwp.
13192 The result is NULL if it can't be found. */
13194 static std::unique_ptr
<struct dwp_file
>
13195 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13197 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13199 /* Try to find first .dwp for the binary file before any symbolic links
13202 /* If the objfile is a debug file, find the name of the real binary
13203 file and get the name of dwp file from there. */
13204 std::string dwp_name
;
13205 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13207 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13208 const char *backlink_basename
= lbasename (backlink
->original_name
);
13210 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13213 dwp_name
= objfile
->original_name
;
13215 dwp_name
+= ".dwp";
13217 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13219 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13221 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13222 dwp_name
= objfile_name (objfile
);
13223 dwp_name
+= ".dwp";
13224 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13229 if (dwarf_read_debug
)
13230 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13231 return std::unique_ptr
<dwp_file
> ();
13234 const char *name
= bfd_get_filename (dbfd
.get ());
13235 std::unique_ptr
<struct dwp_file
> dwp_file
13236 (new struct dwp_file (name
, std::move (dbfd
)));
13238 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13239 dwp_file
->elf_sections
=
13240 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13241 dwp_file
->num_sections
, asection
*);
13243 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13244 dwarf2_locate_common_dwp_sections
,
13247 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13250 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13253 /* The DWP file version is stored in the hash table. Oh well. */
13254 if (dwp_file
->cus
&& dwp_file
->tus
13255 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13257 /* Technically speaking, we should try to limp along, but this is
13258 pretty bizarre. We use pulongest here because that's the established
13259 portability solution (e.g, we cannot use %u for uint32_t). */
13260 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13261 " TU version %s [in DWP file %s]"),
13262 pulongest (dwp_file
->cus
->version
),
13263 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13267 dwp_file
->version
= dwp_file
->cus
->version
;
13268 else if (dwp_file
->tus
)
13269 dwp_file
->version
= dwp_file
->tus
->version
;
13271 dwp_file
->version
= 2;
13273 if (dwp_file
->version
== 2)
13274 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13275 dwarf2_locate_v2_dwp_sections
,
13278 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13279 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13281 if (dwarf_read_debug
)
13283 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13284 fprintf_unfiltered (gdb_stdlog
,
13285 " %s CUs, %s TUs\n",
13286 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13287 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13293 /* Wrapper around open_and_init_dwp_file, only open it once. */
13295 static struct dwp_file
*
13296 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13298 if (! dwarf2_per_objfile
->dwp_checked
)
13300 dwarf2_per_objfile
->dwp_file
13301 = open_and_init_dwp_file (dwarf2_per_objfile
);
13302 dwarf2_per_objfile
->dwp_checked
= 1;
13304 return dwarf2_per_objfile
->dwp_file
.get ();
13307 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13308 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13309 or in the DWP file for the objfile, referenced by THIS_UNIT.
13310 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13311 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13313 This is called, for example, when wanting to read a variable with a
13314 complex location. Therefore we don't want to do file i/o for every call.
13315 Therefore we don't want to look for a DWO file on every call.
13316 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13317 then we check if we've already seen DWO_NAME, and only THEN do we check
13320 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13321 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13323 static struct dwo_unit
*
13324 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13325 const char *dwo_name
, const char *comp_dir
,
13326 ULONGEST signature
, int is_debug_types
)
13328 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13329 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13330 const char *kind
= is_debug_types
? "TU" : "CU";
13331 void **dwo_file_slot
;
13332 struct dwo_file
*dwo_file
;
13333 struct dwp_file
*dwp_file
;
13335 /* First see if there's a DWP file.
13336 If we have a DWP file but didn't find the DWO inside it, don't
13337 look for the original DWO file. It makes gdb behave differently
13338 depending on whether one is debugging in the build tree. */
13340 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13341 if (dwp_file
!= NULL
)
13343 const struct dwp_hash_table
*dwp_htab
=
13344 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13346 if (dwp_htab
!= NULL
)
13348 struct dwo_unit
*dwo_cutu
=
13349 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13350 signature
, is_debug_types
);
13352 if (dwo_cutu
!= NULL
)
13354 if (dwarf_read_debug
)
13356 fprintf_unfiltered (gdb_stdlog
,
13357 "Virtual DWO %s %s found: @%s\n",
13358 kind
, hex_string (signature
),
13359 host_address_to_string (dwo_cutu
));
13367 /* No DWP file, look for the DWO file. */
13369 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13370 dwo_name
, comp_dir
);
13371 if (*dwo_file_slot
== NULL
)
13373 /* Read in the file and build a table of the CUs/TUs it contains. */
13374 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13376 /* NOTE: This will be NULL if unable to open the file. */
13377 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13379 if (dwo_file
!= NULL
)
13381 struct dwo_unit
*dwo_cutu
= NULL
;
13383 if (is_debug_types
&& dwo_file
->tus
)
13385 struct dwo_unit find_dwo_cutu
;
13387 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13388 find_dwo_cutu
.signature
= signature
;
13390 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13392 else if (!is_debug_types
&& dwo_file
->cus
)
13394 struct dwo_unit find_dwo_cutu
;
13396 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13397 find_dwo_cutu
.signature
= signature
;
13398 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13402 if (dwo_cutu
!= NULL
)
13404 if (dwarf_read_debug
)
13406 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13407 kind
, dwo_name
, hex_string (signature
),
13408 host_address_to_string (dwo_cutu
));
13415 /* We didn't find it. This could mean a dwo_id mismatch, or
13416 someone deleted the DWO/DWP file, or the search path isn't set up
13417 correctly to find the file. */
13419 if (dwarf_read_debug
)
13421 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13422 kind
, dwo_name
, hex_string (signature
));
13425 /* This is a warning and not a complaint because it can be caused by
13426 pilot error (e.g., user accidentally deleting the DWO). */
13428 /* Print the name of the DWP file if we looked there, helps the user
13429 better diagnose the problem. */
13430 std::string dwp_text
;
13432 if (dwp_file
!= NULL
)
13433 dwp_text
= string_printf (" [in DWP file %s]",
13434 lbasename (dwp_file
->name
));
13436 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13437 " [in module %s]"),
13438 kind
, dwo_name
, hex_string (signature
),
13440 this_unit
->is_debug_types
? "TU" : "CU",
13441 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13446 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13447 See lookup_dwo_cutu_unit for details. */
13449 static struct dwo_unit
*
13450 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13451 const char *dwo_name
, const char *comp_dir
,
13452 ULONGEST signature
)
13454 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13457 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13458 See lookup_dwo_cutu_unit for details. */
13460 static struct dwo_unit
*
13461 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13462 const char *dwo_name
, const char *comp_dir
)
13464 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13467 /* Traversal function for queue_and_load_all_dwo_tus. */
13470 queue_and_load_dwo_tu (void **slot
, void *info
)
13472 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13473 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13474 ULONGEST signature
= dwo_unit
->signature
;
13475 struct signatured_type
*sig_type
=
13476 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13478 if (sig_type
!= NULL
)
13480 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13482 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13483 a real dependency of PER_CU on SIG_TYPE. That is detected later
13484 while processing PER_CU. */
13485 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13486 load_full_type_unit (sig_cu
);
13487 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
13493 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13494 The DWO may have the only definition of the type, though it may not be
13495 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13496 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13499 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13501 struct dwo_unit
*dwo_unit
;
13502 struct dwo_file
*dwo_file
;
13504 gdb_assert (!per_cu
->is_debug_types
);
13505 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13506 gdb_assert (per_cu
->cu
!= NULL
);
13508 dwo_unit
= per_cu
->cu
->dwo_unit
;
13509 gdb_assert (dwo_unit
!= NULL
);
13511 dwo_file
= dwo_unit
->dwo_file
;
13512 if (dwo_file
->tus
!= NULL
)
13513 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13516 /* Free all resources associated with DWO_FILE.
13517 Close the DWO file and munmap the sections. */
13520 free_dwo_file (struct dwo_file
*dwo_file
)
13522 /* Note: dbfd is NULL for virtual DWO files. */
13523 gdb_bfd_unref (dwo_file
->dbfd
);
13525 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
13528 /* Traversal function for free_dwo_files. */
13531 free_dwo_file_from_slot (void **slot
, void *info
)
13533 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
13535 free_dwo_file (dwo_file
);
13540 /* Free all resources associated with DWO_FILES. */
13543 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
13545 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
13548 /* Read in various DIEs. */
13550 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13551 Inherit only the children of the DW_AT_abstract_origin DIE not being
13552 already referenced by DW_AT_abstract_origin from the children of the
13556 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13558 struct die_info
*child_die
;
13559 sect_offset
*offsetp
;
13560 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13561 struct die_info
*origin_die
;
13562 /* Iterator of the ORIGIN_DIE children. */
13563 struct die_info
*origin_child_die
;
13564 struct attribute
*attr
;
13565 struct dwarf2_cu
*origin_cu
;
13566 struct pending
**origin_previous_list_in_scope
;
13568 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13572 /* Note that following die references may follow to a die in a
13576 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13578 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13580 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13581 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13583 if (die
->tag
!= origin_die
->tag
13584 && !(die
->tag
== DW_TAG_inlined_subroutine
13585 && origin_die
->tag
== DW_TAG_subprogram
))
13586 complaint (_("DIE %s and its abstract origin %s have different tags"),
13587 sect_offset_str (die
->sect_off
),
13588 sect_offset_str (origin_die
->sect_off
));
13590 std::vector
<sect_offset
> offsets
;
13592 for (child_die
= die
->child
;
13593 child_die
&& child_die
->tag
;
13594 child_die
= sibling_die (child_die
))
13596 struct die_info
*child_origin_die
;
13597 struct dwarf2_cu
*child_origin_cu
;
13599 /* We are trying to process concrete instance entries:
13600 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13601 it's not relevant to our analysis here. i.e. detecting DIEs that are
13602 present in the abstract instance but not referenced in the concrete
13604 if (child_die
->tag
== DW_TAG_call_site
13605 || child_die
->tag
== DW_TAG_GNU_call_site
)
13608 /* For each CHILD_DIE, find the corresponding child of
13609 ORIGIN_DIE. If there is more than one layer of
13610 DW_AT_abstract_origin, follow them all; there shouldn't be,
13611 but GCC versions at least through 4.4 generate this (GCC PR
13613 child_origin_die
= child_die
;
13614 child_origin_cu
= cu
;
13617 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13621 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13625 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13626 counterpart may exist. */
13627 if (child_origin_die
!= child_die
)
13629 if (child_die
->tag
!= child_origin_die
->tag
13630 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13631 && child_origin_die
->tag
== DW_TAG_subprogram
))
13632 complaint (_("Child DIE %s and its abstract origin %s have "
13634 sect_offset_str (child_die
->sect_off
),
13635 sect_offset_str (child_origin_die
->sect_off
));
13636 if (child_origin_die
->parent
!= origin_die
)
13637 complaint (_("Child DIE %s and its abstract origin %s have "
13638 "different parents"),
13639 sect_offset_str (child_die
->sect_off
),
13640 sect_offset_str (child_origin_die
->sect_off
));
13642 offsets
.push_back (child_origin_die
->sect_off
);
13645 std::sort (offsets
.begin (), offsets
.end ());
13646 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13647 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13648 if (offsetp
[-1] == *offsetp
)
13649 complaint (_("Multiple children of DIE %s refer "
13650 "to DIE %s as their abstract origin"),
13651 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13653 offsetp
= offsets
.data ();
13654 origin_child_die
= origin_die
->child
;
13655 while (origin_child_die
&& origin_child_die
->tag
)
13657 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13658 while (offsetp
< offsets_end
13659 && *offsetp
< origin_child_die
->sect_off
)
13661 if (offsetp
>= offsets_end
13662 || *offsetp
> origin_child_die
->sect_off
)
13664 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13665 Check whether we're already processing ORIGIN_CHILD_DIE.
13666 This can happen with mutually referenced abstract_origins.
13668 if (!origin_child_die
->in_process
)
13669 process_die (origin_child_die
, origin_cu
);
13671 origin_child_die
= sibling_die (origin_child_die
);
13673 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13677 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13679 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13680 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13681 struct context_stack
*newobj
;
13684 struct die_info
*child_die
;
13685 struct attribute
*attr
, *call_line
, *call_file
;
13687 CORE_ADDR baseaddr
;
13688 struct block
*block
;
13689 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13690 std::vector
<struct symbol
*> template_args
;
13691 struct template_symbol
*templ_func
= NULL
;
13695 /* If we do not have call site information, we can't show the
13696 caller of this inlined function. That's too confusing, so
13697 only use the scope for local variables. */
13698 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13699 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13700 if (call_line
== NULL
|| call_file
== NULL
)
13702 read_lexical_block_scope (die
, cu
);
13707 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13709 name
= dwarf2_name (die
, cu
);
13711 /* Ignore functions with missing or empty names. These are actually
13712 illegal according to the DWARF standard. */
13715 complaint (_("missing name for subprogram DIE at %s"),
13716 sect_offset_str (die
->sect_off
));
13720 /* Ignore functions with missing or invalid low and high pc attributes. */
13721 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13722 <= PC_BOUNDS_INVALID
)
13724 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13725 if (!attr
|| !DW_UNSND (attr
))
13726 complaint (_("cannot get low and high bounds "
13727 "for subprogram DIE at %s"),
13728 sect_offset_str (die
->sect_off
));
13732 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13733 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13735 /* If we have any template arguments, then we must allocate a
13736 different sort of symbol. */
13737 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13739 if (child_die
->tag
== DW_TAG_template_type_param
13740 || child_die
->tag
== DW_TAG_template_value_param
)
13742 templ_func
= allocate_template_symbol (objfile
);
13743 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13748 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13749 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13750 (struct symbol
*) templ_func
);
13752 /* If there is a location expression for DW_AT_frame_base, record
13754 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13756 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13758 /* If there is a location for the static link, record it. */
13759 newobj
->static_link
= NULL
;
13760 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13763 newobj
->static_link
13764 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13765 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
13768 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13770 if (die
->child
!= NULL
)
13772 child_die
= die
->child
;
13773 while (child_die
&& child_die
->tag
)
13775 if (child_die
->tag
== DW_TAG_template_type_param
13776 || child_die
->tag
== DW_TAG_template_value_param
)
13778 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13781 template_args
.push_back (arg
);
13784 process_die (child_die
, cu
);
13785 child_die
= sibling_die (child_die
);
13789 inherit_abstract_dies (die
, cu
);
13791 /* If we have a DW_AT_specification, we might need to import using
13792 directives from the context of the specification DIE. See the
13793 comment in determine_prefix. */
13794 if (cu
->language
== language_cplus
13795 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13797 struct dwarf2_cu
*spec_cu
= cu
;
13798 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13802 child_die
= spec_die
->child
;
13803 while (child_die
&& child_die
->tag
)
13805 if (child_die
->tag
== DW_TAG_imported_module
)
13806 process_die (child_die
, spec_cu
);
13807 child_die
= sibling_die (child_die
);
13810 /* In some cases, GCC generates specification DIEs that
13811 themselves contain DW_AT_specification attributes. */
13812 spec_die
= die_specification (spec_die
, &spec_cu
);
13816 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13817 /* Make a block for the local symbols within. */
13818 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13819 cstk
.static_link
, lowpc
, highpc
);
13821 /* For C++, set the block's scope. */
13822 if ((cu
->language
== language_cplus
13823 || cu
->language
== language_fortran
13824 || cu
->language
== language_d
13825 || cu
->language
== language_rust
)
13826 && cu
->processing_has_namespace_info
)
13827 block_set_scope (block
, determine_prefix (die
, cu
),
13828 &objfile
->objfile_obstack
);
13830 /* If we have address ranges, record them. */
13831 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13833 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13835 /* Attach template arguments to function. */
13836 if (!template_args
.empty ())
13838 gdb_assert (templ_func
!= NULL
);
13840 templ_func
->n_template_arguments
= template_args
.size ();
13841 templ_func
->template_arguments
13842 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13843 templ_func
->n_template_arguments
);
13844 memcpy (templ_func
->template_arguments
,
13845 template_args
.data (),
13846 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13848 /* Make sure that the symtab is set on the new symbols. Even
13849 though they don't appear in this symtab directly, other parts
13850 of gdb assume that symbols do, and this is reasonably
13852 for (symbol
*sym
: template_args
)
13853 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13856 /* In C++, we can have functions nested inside functions (e.g., when
13857 a function declares a class that has methods). This means that
13858 when we finish processing a function scope, we may need to go
13859 back to building a containing block's symbol lists. */
13860 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13861 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13863 /* If we've finished processing a top-level function, subsequent
13864 symbols go in the file symbol list. */
13865 if (cu
->get_builder ()->outermost_context_p ())
13866 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13869 /* Process all the DIES contained within a lexical block scope. Start
13870 a new scope, process the dies, and then close the scope. */
13873 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13875 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13876 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13877 CORE_ADDR lowpc
, highpc
;
13878 struct die_info
*child_die
;
13879 CORE_ADDR baseaddr
;
13881 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13883 /* Ignore blocks with missing or invalid low and high pc attributes. */
13884 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13885 as multiple lexical blocks? Handling children in a sane way would
13886 be nasty. Might be easier to properly extend generic blocks to
13887 describe ranges. */
13888 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13890 case PC_BOUNDS_NOT_PRESENT
:
13891 /* DW_TAG_lexical_block has no attributes, process its children as if
13892 there was no wrapping by that DW_TAG_lexical_block.
13893 GCC does no longer produces such DWARF since GCC r224161. */
13894 for (child_die
= die
->child
;
13895 child_die
!= NULL
&& child_die
->tag
;
13896 child_die
= sibling_die (child_die
))
13897 process_die (child_die
, cu
);
13899 case PC_BOUNDS_INVALID
:
13902 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13903 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13905 cu
->get_builder ()->push_context (0, lowpc
);
13906 if (die
->child
!= NULL
)
13908 child_die
= die
->child
;
13909 while (child_die
&& child_die
->tag
)
13911 process_die (child_die
, cu
);
13912 child_die
= sibling_die (child_die
);
13915 inherit_abstract_dies (die
, cu
);
13916 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13918 if (*cu
->get_builder ()->get_local_symbols () != NULL
13919 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13921 struct block
*block
13922 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13923 cstk
.start_addr
, highpc
);
13925 /* Note that recording ranges after traversing children, as we
13926 do here, means that recording a parent's ranges entails
13927 walking across all its children's ranges as they appear in
13928 the address map, which is quadratic behavior.
13930 It would be nicer to record the parent's ranges before
13931 traversing its children, simply overriding whatever you find
13932 there. But since we don't even decide whether to create a
13933 block until after we've traversed its children, that's hard
13935 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13937 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13938 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13941 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13944 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13946 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13947 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13948 CORE_ADDR pc
, baseaddr
;
13949 struct attribute
*attr
;
13950 struct call_site
*call_site
, call_site_local
;
13953 struct die_info
*child_die
;
13955 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13957 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13960 /* This was a pre-DWARF-5 GNU extension alias
13961 for DW_AT_call_return_pc. */
13962 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13966 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13967 "DIE %s [in module %s]"),
13968 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13971 pc
= attr_value_as_address (attr
) + baseaddr
;
13972 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13974 if (cu
->call_site_htab
== NULL
)
13975 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13976 NULL
, &objfile
->objfile_obstack
,
13977 hashtab_obstack_allocate
, NULL
);
13978 call_site_local
.pc
= pc
;
13979 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13982 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13983 "DIE %s [in module %s]"),
13984 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13985 objfile_name (objfile
));
13989 /* Count parameters at the caller. */
13992 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13993 child_die
= sibling_die (child_die
))
13995 if (child_die
->tag
!= DW_TAG_call_site_parameter
13996 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13998 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13999 "DW_TAG_call_site child DIE %s [in module %s]"),
14000 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
14001 objfile_name (objfile
));
14009 = ((struct call_site
*)
14010 obstack_alloc (&objfile
->objfile_obstack
,
14011 sizeof (*call_site
)
14012 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14014 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14015 call_site
->pc
= pc
;
14017 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14018 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14020 struct die_info
*func_die
;
14022 /* Skip also over DW_TAG_inlined_subroutine. */
14023 for (func_die
= die
->parent
;
14024 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14025 && func_die
->tag
!= DW_TAG_subroutine_type
;
14026 func_die
= func_die
->parent
);
14028 /* DW_AT_call_all_calls is a superset
14029 of DW_AT_call_all_tail_calls. */
14031 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14032 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14033 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14034 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14036 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14037 not complete. But keep CALL_SITE for look ups via call_site_htab,
14038 both the initial caller containing the real return address PC and
14039 the final callee containing the current PC of a chain of tail
14040 calls do not need to have the tail call list complete. But any
14041 function candidate for a virtual tail call frame searched via
14042 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14043 determined unambiguously. */
14047 struct type
*func_type
= NULL
;
14050 func_type
= get_die_type (func_die
, cu
);
14051 if (func_type
!= NULL
)
14053 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14055 /* Enlist this call site to the function. */
14056 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14057 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14060 complaint (_("Cannot find function owning DW_TAG_call_site "
14061 "DIE %s [in module %s]"),
14062 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14066 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14068 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14070 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14073 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14074 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14076 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14077 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14078 /* Keep NULL DWARF_BLOCK. */;
14079 else if (attr_form_is_block (attr
))
14081 struct dwarf2_locexpr_baton
*dlbaton
;
14083 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14084 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14085 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14086 dlbaton
->per_cu
= cu
->per_cu
;
14088 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14090 else if (attr_form_is_ref (attr
))
14092 struct dwarf2_cu
*target_cu
= cu
;
14093 struct die_info
*target_die
;
14095 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14096 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14097 if (die_is_declaration (target_die
, target_cu
))
14099 const char *target_physname
;
14101 /* Prefer the mangled name; otherwise compute the demangled one. */
14102 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14103 if (target_physname
== NULL
)
14104 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14105 if (target_physname
== NULL
)
14106 complaint (_("DW_AT_call_target target DIE has invalid "
14107 "physname, for referencing DIE %s [in module %s]"),
14108 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14110 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14116 /* DW_AT_entry_pc should be preferred. */
14117 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14118 <= PC_BOUNDS_INVALID
)
14119 complaint (_("DW_AT_call_target target DIE has invalid "
14120 "low pc, for referencing DIE %s [in module %s]"),
14121 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14124 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14125 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14130 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14131 "block nor reference, for DIE %s [in module %s]"),
14132 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14134 call_site
->per_cu
= cu
->per_cu
;
14136 for (child_die
= die
->child
;
14137 child_die
&& child_die
->tag
;
14138 child_die
= sibling_die (child_die
))
14140 struct call_site_parameter
*parameter
;
14141 struct attribute
*loc
, *origin
;
14143 if (child_die
->tag
!= DW_TAG_call_site_parameter
14144 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14146 /* Already printed the complaint above. */
14150 gdb_assert (call_site
->parameter_count
< nparams
);
14151 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14153 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14154 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14155 register is contained in DW_AT_call_value. */
14157 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14158 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14159 if (origin
== NULL
)
14161 /* This was a pre-DWARF-5 GNU extension alias
14162 for DW_AT_call_parameter. */
14163 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14165 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14167 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14169 sect_offset sect_off
14170 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14171 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14173 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14174 binding can be done only inside one CU. Such referenced DIE
14175 therefore cannot be even moved to DW_TAG_partial_unit. */
14176 complaint (_("DW_AT_call_parameter offset is not in CU for "
14177 "DW_TAG_call_site child DIE %s [in module %s]"),
14178 sect_offset_str (child_die
->sect_off
),
14179 objfile_name (objfile
));
14182 parameter
->u
.param_cu_off
14183 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14185 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14187 complaint (_("No DW_FORM_block* DW_AT_location for "
14188 "DW_TAG_call_site child DIE %s [in module %s]"),
14189 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14194 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14195 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14196 if (parameter
->u
.dwarf_reg
!= -1)
14197 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14198 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14199 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14200 ¶meter
->u
.fb_offset
))
14201 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14204 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14205 "for DW_FORM_block* DW_AT_location is supported for "
14206 "DW_TAG_call_site child DIE %s "
14208 sect_offset_str (child_die
->sect_off
),
14209 objfile_name (objfile
));
14214 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14216 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14217 if (!attr_form_is_block (attr
))
14219 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14220 "DW_TAG_call_site child DIE %s [in module %s]"),
14221 sect_offset_str (child_die
->sect_off
),
14222 objfile_name (objfile
));
14225 parameter
->value
= DW_BLOCK (attr
)->data
;
14226 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14228 /* Parameters are not pre-cleared by memset above. */
14229 parameter
->data_value
= NULL
;
14230 parameter
->data_value_size
= 0;
14231 call_site
->parameter_count
++;
14233 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14235 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14238 if (!attr_form_is_block (attr
))
14239 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14240 "DW_TAG_call_site child DIE %s [in module %s]"),
14241 sect_offset_str (child_die
->sect_off
),
14242 objfile_name (objfile
));
14245 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14246 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14252 /* Helper function for read_variable. If DIE represents a virtual
14253 table, then return the type of the concrete object that is
14254 associated with the virtual table. Otherwise, return NULL. */
14256 static struct type
*
14257 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14259 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14263 /* Find the type DIE. */
14264 struct die_info
*type_die
= NULL
;
14265 struct dwarf2_cu
*type_cu
= cu
;
14267 if (attr_form_is_ref (attr
))
14268 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14269 if (type_die
== NULL
)
14272 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14274 return die_containing_type (type_die
, type_cu
);
14277 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14280 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14282 struct rust_vtable_symbol
*storage
= NULL
;
14284 if (cu
->language
== language_rust
)
14286 struct type
*containing_type
= rust_containing_type (die
, cu
);
14288 if (containing_type
!= NULL
)
14290 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14292 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14293 struct rust_vtable_symbol
);
14294 initialize_objfile_symbol (storage
);
14295 storage
->concrete_type
= containing_type
;
14296 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14300 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14301 struct attribute
*abstract_origin
14302 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14303 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14304 if (res
== NULL
&& loc
&& abstract_origin
)
14306 /* We have a variable without a name, but with a location and an abstract
14307 origin. This may be a concrete instance of an abstract variable
14308 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14310 struct dwarf2_cu
*origin_cu
= cu
;
14311 struct die_info
*origin_die
14312 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14313 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14314 dpo
->abstract_to_concrete
[origin_die
].push_back (die
);
14318 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14319 reading .debug_rnglists.
14320 Callback's type should be:
14321 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14322 Return true if the attributes are present and valid, otherwise,
14325 template <typename Callback
>
14327 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14328 Callback
&&callback
)
14330 struct dwarf2_per_objfile
*dwarf2_per_objfile
14331 = cu
->per_cu
->dwarf2_per_objfile
;
14332 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14333 bfd
*obfd
= objfile
->obfd
;
14334 /* Base address selection entry. */
14337 const gdb_byte
*buffer
;
14338 CORE_ADDR baseaddr
;
14339 bool overflow
= false;
14341 found_base
= cu
->base_known
;
14342 base
= cu
->base_address
;
14344 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14345 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14347 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14351 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14353 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14357 /* Initialize it due to a false compiler warning. */
14358 CORE_ADDR range_beginning
= 0, range_end
= 0;
14359 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14360 + dwarf2_per_objfile
->rnglists
.size
);
14361 unsigned int bytes_read
;
14363 if (buffer
== buf_end
)
14368 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14371 case DW_RLE_end_of_list
:
14373 case DW_RLE_base_address
:
14374 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14379 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14381 buffer
+= bytes_read
;
14383 case DW_RLE_start_length
:
14384 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14389 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14390 buffer
+= bytes_read
;
14391 range_end
= (range_beginning
14392 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14393 buffer
+= bytes_read
;
14394 if (buffer
> buf_end
)
14400 case DW_RLE_offset_pair
:
14401 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14402 buffer
+= bytes_read
;
14403 if (buffer
> buf_end
)
14408 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14409 buffer
+= bytes_read
;
14410 if (buffer
> buf_end
)
14416 case DW_RLE_start_end
:
14417 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14422 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14423 buffer
+= bytes_read
;
14424 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14425 buffer
+= bytes_read
;
14428 complaint (_("Invalid .debug_rnglists data (no base address)"));
14431 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14433 if (rlet
== DW_RLE_base_address
)
14438 /* We have no valid base address for the ranges
14440 complaint (_("Invalid .debug_rnglists data (no base address)"));
14444 if (range_beginning
> range_end
)
14446 /* Inverted range entries are invalid. */
14447 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14451 /* Empty range entries have no effect. */
14452 if (range_beginning
== range_end
)
14455 range_beginning
+= base
;
14458 /* A not-uncommon case of bad debug info.
14459 Don't pollute the addrmap with bad data. */
14460 if (range_beginning
+ baseaddr
== 0
14461 && !dwarf2_per_objfile
->has_section_at_zero
)
14463 complaint (_(".debug_rnglists entry has start address of zero"
14464 " [in module %s]"), objfile_name (objfile
));
14468 callback (range_beginning
, range_end
);
14473 complaint (_("Offset %d is not terminated "
14474 "for DW_AT_ranges attribute"),
14482 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14483 Callback's type should be:
14484 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14485 Return 1 if the attributes are present and valid, otherwise, return 0. */
14487 template <typename Callback
>
14489 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14490 Callback
&&callback
)
14492 struct dwarf2_per_objfile
*dwarf2_per_objfile
14493 = cu
->per_cu
->dwarf2_per_objfile
;
14494 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14495 struct comp_unit_head
*cu_header
= &cu
->header
;
14496 bfd
*obfd
= objfile
->obfd
;
14497 unsigned int addr_size
= cu_header
->addr_size
;
14498 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14499 /* Base address selection entry. */
14502 unsigned int dummy
;
14503 const gdb_byte
*buffer
;
14504 CORE_ADDR baseaddr
;
14506 if (cu_header
->version
>= 5)
14507 return dwarf2_rnglists_process (offset
, cu
, callback
);
14509 found_base
= cu
->base_known
;
14510 base
= cu
->base_address
;
14512 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14513 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14515 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14519 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14521 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14525 CORE_ADDR range_beginning
, range_end
;
14527 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14528 buffer
+= addr_size
;
14529 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14530 buffer
+= addr_size
;
14531 offset
+= 2 * addr_size
;
14533 /* An end of list marker is a pair of zero addresses. */
14534 if (range_beginning
== 0 && range_end
== 0)
14535 /* Found the end of list entry. */
14538 /* Each base address selection entry is a pair of 2 values.
14539 The first is the largest possible address, the second is
14540 the base address. Check for a base address here. */
14541 if ((range_beginning
& mask
) == mask
)
14543 /* If we found the largest possible address, then we already
14544 have the base address in range_end. */
14552 /* We have no valid base address for the ranges
14554 complaint (_("Invalid .debug_ranges data (no base address)"));
14558 if (range_beginning
> range_end
)
14560 /* Inverted range entries are invalid. */
14561 complaint (_("Invalid .debug_ranges data (inverted range)"));
14565 /* Empty range entries have no effect. */
14566 if (range_beginning
== range_end
)
14569 range_beginning
+= base
;
14572 /* A not-uncommon case of bad debug info.
14573 Don't pollute the addrmap with bad data. */
14574 if (range_beginning
+ baseaddr
== 0
14575 && !dwarf2_per_objfile
->has_section_at_zero
)
14577 complaint (_(".debug_ranges entry has start address of zero"
14578 " [in module %s]"), objfile_name (objfile
));
14582 callback (range_beginning
, range_end
);
14588 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14589 Return 1 if the attributes are present and valid, otherwise, return 0.
14590 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14593 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14594 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14595 struct partial_symtab
*ranges_pst
)
14597 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14598 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14599 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14600 SECT_OFF_TEXT (objfile
));
14603 CORE_ADDR high
= 0;
14606 retval
= dwarf2_ranges_process (offset
, cu
,
14607 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14609 if (ranges_pst
!= NULL
)
14614 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14615 range_beginning
+ baseaddr
)
14617 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14618 range_end
+ baseaddr
)
14620 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14621 lowpc
, highpc
- 1, ranges_pst
);
14624 /* FIXME: This is recording everything as a low-high
14625 segment of consecutive addresses. We should have a
14626 data structure for discontiguous block ranges
14630 low
= range_beginning
;
14636 if (range_beginning
< low
)
14637 low
= range_beginning
;
14638 if (range_end
> high
)
14646 /* If the first entry is an end-of-list marker, the range
14647 describes an empty scope, i.e. no instructions. */
14653 *high_return
= high
;
14657 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14658 definition for the return value. *LOWPC and *HIGHPC are set iff
14659 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14661 static enum pc_bounds_kind
14662 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14663 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14664 struct partial_symtab
*pst
)
14666 struct dwarf2_per_objfile
*dwarf2_per_objfile
14667 = cu
->per_cu
->dwarf2_per_objfile
;
14668 struct attribute
*attr
;
14669 struct attribute
*attr_high
;
14671 CORE_ADDR high
= 0;
14672 enum pc_bounds_kind ret
;
14674 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14677 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14680 low
= attr_value_as_address (attr
);
14681 high
= attr_value_as_address (attr_high
);
14682 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14686 /* Found high w/o low attribute. */
14687 return PC_BOUNDS_INVALID
;
14689 /* Found consecutive range of addresses. */
14690 ret
= PC_BOUNDS_HIGH_LOW
;
14694 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14697 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14698 We take advantage of the fact that DW_AT_ranges does not appear
14699 in DW_TAG_compile_unit of DWO files. */
14700 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14701 unsigned int ranges_offset
= (DW_UNSND (attr
)
14702 + (need_ranges_base
14706 /* Value of the DW_AT_ranges attribute is the offset in the
14707 .debug_ranges section. */
14708 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14709 return PC_BOUNDS_INVALID
;
14710 /* Found discontinuous range of addresses. */
14711 ret
= PC_BOUNDS_RANGES
;
14714 return PC_BOUNDS_NOT_PRESENT
;
14717 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14719 return PC_BOUNDS_INVALID
;
14721 /* When using the GNU linker, .gnu.linkonce. sections are used to
14722 eliminate duplicate copies of functions and vtables and such.
14723 The linker will arbitrarily choose one and discard the others.
14724 The AT_*_pc values for such functions refer to local labels in
14725 these sections. If the section from that file was discarded, the
14726 labels are not in the output, so the relocs get a value of 0.
14727 If this is a discarded function, mark the pc bounds as invalid,
14728 so that GDB will ignore it. */
14729 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14730 return PC_BOUNDS_INVALID
;
14738 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14739 its low and high PC addresses. Do nothing if these addresses could not
14740 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14741 and HIGHPC to the high address if greater than HIGHPC. */
14744 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14745 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14746 struct dwarf2_cu
*cu
)
14748 CORE_ADDR low
, high
;
14749 struct die_info
*child
= die
->child
;
14751 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14753 *lowpc
= std::min (*lowpc
, low
);
14754 *highpc
= std::max (*highpc
, high
);
14757 /* If the language does not allow nested subprograms (either inside
14758 subprograms or lexical blocks), we're done. */
14759 if (cu
->language
!= language_ada
)
14762 /* Check all the children of the given DIE. If it contains nested
14763 subprograms, then check their pc bounds. Likewise, we need to
14764 check lexical blocks as well, as they may also contain subprogram
14766 while (child
&& child
->tag
)
14768 if (child
->tag
== DW_TAG_subprogram
14769 || child
->tag
== DW_TAG_lexical_block
)
14770 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14771 child
= sibling_die (child
);
14775 /* Get the low and high pc's represented by the scope DIE, and store
14776 them in *LOWPC and *HIGHPC. If the correct values can't be
14777 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14780 get_scope_pc_bounds (struct die_info
*die
,
14781 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14782 struct dwarf2_cu
*cu
)
14784 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14785 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14786 CORE_ADDR current_low
, current_high
;
14788 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14789 >= PC_BOUNDS_RANGES
)
14791 best_low
= current_low
;
14792 best_high
= current_high
;
14796 struct die_info
*child
= die
->child
;
14798 while (child
&& child
->tag
)
14800 switch (child
->tag
) {
14801 case DW_TAG_subprogram
:
14802 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14804 case DW_TAG_namespace
:
14805 case DW_TAG_module
:
14806 /* FIXME: carlton/2004-01-16: Should we do this for
14807 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14808 that current GCC's always emit the DIEs corresponding
14809 to definitions of methods of classes as children of a
14810 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14811 the DIEs giving the declarations, which could be
14812 anywhere). But I don't see any reason why the
14813 standards says that they have to be there. */
14814 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14816 if (current_low
!= ((CORE_ADDR
) -1))
14818 best_low
= std::min (best_low
, current_low
);
14819 best_high
= std::max (best_high
, current_high
);
14827 child
= sibling_die (child
);
14832 *highpc
= best_high
;
14835 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14839 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14840 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14842 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14843 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14844 struct attribute
*attr
;
14845 struct attribute
*attr_high
;
14847 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14850 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14853 CORE_ADDR low
= attr_value_as_address (attr
);
14854 CORE_ADDR high
= attr_value_as_address (attr_high
);
14856 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14859 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14860 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14861 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14865 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14868 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14869 We take advantage of the fact that DW_AT_ranges does not appear
14870 in DW_TAG_compile_unit of DWO files. */
14871 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14873 /* The value of the DW_AT_ranges attribute is the offset of the
14874 address range list in the .debug_ranges section. */
14875 unsigned long offset
= (DW_UNSND (attr
)
14876 + (need_ranges_base
? cu
->ranges_base
: 0));
14878 std::vector
<blockrange
> blockvec
;
14879 dwarf2_ranges_process (offset
, cu
,
14880 [&] (CORE_ADDR start
, CORE_ADDR end
)
14884 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14885 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14886 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14887 blockvec
.emplace_back (start
, end
);
14890 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14894 /* Check whether the producer field indicates either of GCC < 4.6, or the
14895 Intel C/C++ compiler, and cache the result in CU. */
14898 check_producer (struct dwarf2_cu
*cu
)
14902 if (cu
->producer
== NULL
)
14904 /* For unknown compilers expect their behavior is DWARF version
14907 GCC started to support .debug_types sections by -gdwarf-4 since
14908 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14909 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14910 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14911 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14913 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14915 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14916 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14918 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14920 cu
->producer_is_icc
= true;
14921 cu
->producer_is_icc_lt_14
= major
< 14;
14923 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14924 cu
->producer_is_codewarrior
= true;
14927 /* For other non-GCC compilers, expect their behavior is DWARF version
14931 cu
->checked_producer
= true;
14934 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14935 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14936 during 4.6.0 experimental. */
14939 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14941 if (!cu
->checked_producer
)
14942 check_producer (cu
);
14944 return cu
->producer_is_gxx_lt_4_6
;
14948 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14949 with incorrect is_stmt attributes. */
14952 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14954 if (!cu
->checked_producer
)
14955 check_producer (cu
);
14957 return cu
->producer_is_codewarrior
;
14960 /* Return the default accessibility type if it is not overriden by
14961 DW_AT_accessibility. */
14963 static enum dwarf_access_attribute
14964 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14966 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14968 /* The default DWARF 2 accessibility for members is public, the default
14969 accessibility for inheritance is private. */
14971 if (die
->tag
!= DW_TAG_inheritance
)
14972 return DW_ACCESS_public
;
14974 return DW_ACCESS_private
;
14978 /* DWARF 3+ defines the default accessibility a different way. The same
14979 rules apply now for DW_TAG_inheritance as for the members and it only
14980 depends on the container kind. */
14982 if (die
->parent
->tag
== DW_TAG_class_type
)
14983 return DW_ACCESS_private
;
14985 return DW_ACCESS_public
;
14989 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14990 offset. If the attribute was not found return 0, otherwise return
14991 1. If it was found but could not properly be handled, set *OFFSET
14995 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14998 struct attribute
*attr
;
15000 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15005 /* Note that we do not check for a section offset first here.
15006 This is because DW_AT_data_member_location is new in DWARF 4,
15007 so if we see it, we can assume that a constant form is really
15008 a constant and not a section offset. */
15009 if (attr_form_is_constant (attr
))
15010 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15011 else if (attr_form_is_section_offset (attr
))
15012 dwarf2_complex_location_expr_complaint ();
15013 else if (attr_form_is_block (attr
))
15014 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15016 dwarf2_complex_location_expr_complaint ();
15024 /* Add an aggregate field to the field list. */
15027 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15028 struct dwarf2_cu
*cu
)
15030 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15031 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15032 struct nextfield
*new_field
;
15033 struct attribute
*attr
;
15035 const char *fieldname
= "";
15037 if (die
->tag
== DW_TAG_inheritance
)
15039 fip
->baseclasses
.emplace_back ();
15040 new_field
= &fip
->baseclasses
.back ();
15044 fip
->fields
.emplace_back ();
15045 new_field
= &fip
->fields
.back ();
15050 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15052 new_field
->accessibility
= DW_UNSND (attr
);
15054 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15055 if (new_field
->accessibility
!= DW_ACCESS_public
)
15056 fip
->non_public_fields
= 1;
15058 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15060 new_field
->virtuality
= DW_UNSND (attr
);
15062 new_field
->virtuality
= DW_VIRTUALITY_none
;
15064 fp
= &new_field
->field
;
15066 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15070 /* Data member other than a C++ static data member. */
15072 /* Get type of field. */
15073 fp
->type
= die_type (die
, cu
);
15075 SET_FIELD_BITPOS (*fp
, 0);
15077 /* Get bit size of field (zero if none). */
15078 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15081 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15085 FIELD_BITSIZE (*fp
) = 0;
15088 /* Get bit offset of field. */
15089 if (handle_data_member_location (die
, cu
, &offset
))
15090 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15091 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15094 if (gdbarch_bits_big_endian (gdbarch
))
15096 /* For big endian bits, the DW_AT_bit_offset gives the
15097 additional bit offset from the MSB of the containing
15098 anonymous object to the MSB of the field. We don't
15099 have to do anything special since we don't need to
15100 know the size of the anonymous object. */
15101 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15105 /* For little endian bits, compute the bit offset to the
15106 MSB of the anonymous object, subtract off the number of
15107 bits from the MSB of the field to the MSB of the
15108 object, and then subtract off the number of bits of
15109 the field itself. The result is the bit offset of
15110 the LSB of the field. */
15111 int anonymous_size
;
15112 int bit_offset
= DW_UNSND (attr
);
15114 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15117 /* The size of the anonymous object containing
15118 the bit field is explicit, so use the
15119 indicated size (in bytes). */
15120 anonymous_size
= DW_UNSND (attr
);
15124 /* The size of the anonymous object containing
15125 the bit field must be inferred from the type
15126 attribute of the data member containing the
15128 anonymous_size
= TYPE_LENGTH (fp
->type
);
15130 SET_FIELD_BITPOS (*fp
,
15131 (FIELD_BITPOS (*fp
)
15132 + anonymous_size
* bits_per_byte
15133 - bit_offset
- FIELD_BITSIZE (*fp
)));
15136 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15138 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15139 + dwarf2_get_attr_constant_value (attr
, 0)));
15141 /* Get name of field. */
15142 fieldname
= dwarf2_name (die
, cu
);
15143 if (fieldname
== NULL
)
15146 /* The name is already allocated along with this objfile, so we don't
15147 need to duplicate it for the type. */
15148 fp
->name
= fieldname
;
15150 /* Change accessibility for artificial fields (e.g. virtual table
15151 pointer or virtual base class pointer) to private. */
15152 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15154 FIELD_ARTIFICIAL (*fp
) = 1;
15155 new_field
->accessibility
= DW_ACCESS_private
;
15156 fip
->non_public_fields
= 1;
15159 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15161 /* C++ static member. */
15163 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15164 is a declaration, but all versions of G++ as of this writing
15165 (so through at least 3.2.1) incorrectly generate
15166 DW_TAG_variable tags. */
15168 const char *physname
;
15170 /* Get name of field. */
15171 fieldname
= dwarf2_name (die
, cu
);
15172 if (fieldname
== NULL
)
15175 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15177 /* Only create a symbol if this is an external value.
15178 new_symbol checks this and puts the value in the global symbol
15179 table, which we want. If it is not external, new_symbol
15180 will try to put the value in cu->list_in_scope which is wrong. */
15181 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15183 /* A static const member, not much different than an enum as far as
15184 we're concerned, except that we can support more types. */
15185 new_symbol (die
, NULL
, cu
);
15188 /* Get physical name. */
15189 physname
= dwarf2_physname (fieldname
, die
, cu
);
15191 /* The name is already allocated along with this objfile, so we don't
15192 need to duplicate it for the type. */
15193 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15194 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15195 FIELD_NAME (*fp
) = fieldname
;
15197 else if (die
->tag
== DW_TAG_inheritance
)
15201 /* C++ base class field. */
15202 if (handle_data_member_location (die
, cu
, &offset
))
15203 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15204 FIELD_BITSIZE (*fp
) = 0;
15205 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15206 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
15208 else if (die
->tag
== DW_TAG_variant_part
)
15210 /* process_structure_scope will treat this DIE as a union. */
15211 process_structure_scope (die
, cu
);
15213 /* The variant part is relative to the start of the enclosing
15215 SET_FIELD_BITPOS (*fp
, 0);
15216 fp
->type
= get_die_type (die
, cu
);
15217 fp
->artificial
= 1;
15218 fp
->name
= "<<variant>>";
15220 /* Normally a DW_TAG_variant_part won't have a size, but our
15221 representation requires one, so set it to the maximum of the
15223 if (TYPE_LENGTH (fp
->type
) == 0)
15226 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
15227 if (TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)) > max
)
15228 max
= TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
));
15229 TYPE_LENGTH (fp
->type
) = max
;
15233 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15236 /* Can the type given by DIE define another type? */
15239 type_can_define_types (const struct die_info
*die
)
15243 case DW_TAG_typedef
:
15244 case DW_TAG_class_type
:
15245 case DW_TAG_structure_type
:
15246 case DW_TAG_union_type
:
15247 case DW_TAG_enumeration_type
:
15255 /* Add a type definition defined in the scope of the FIP's class. */
15258 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15259 struct dwarf2_cu
*cu
)
15261 struct decl_field fp
;
15262 memset (&fp
, 0, sizeof (fp
));
15264 gdb_assert (type_can_define_types (die
));
15266 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15267 fp
.name
= dwarf2_name (die
, cu
);
15268 fp
.type
= read_type_die (die
, cu
);
15270 /* Save accessibility. */
15271 enum dwarf_access_attribute accessibility
;
15272 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15274 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15276 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15277 switch (accessibility
)
15279 case DW_ACCESS_public
:
15280 /* The assumed value if neither private nor protected. */
15282 case DW_ACCESS_private
:
15285 case DW_ACCESS_protected
:
15286 fp
.is_protected
= 1;
15289 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15292 if (die
->tag
== DW_TAG_typedef
)
15293 fip
->typedef_field_list
.push_back (fp
);
15295 fip
->nested_types_list
.push_back (fp
);
15298 /* Create the vector of fields, and attach it to the type. */
15301 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15302 struct dwarf2_cu
*cu
)
15304 int nfields
= fip
->nfields
;
15306 /* Record the field count, allocate space for the array of fields,
15307 and create blank accessibility bitfields if necessary. */
15308 TYPE_NFIELDS (type
) = nfields
;
15309 TYPE_FIELDS (type
) = (struct field
*)
15310 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15312 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15314 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15316 TYPE_FIELD_PRIVATE_BITS (type
) =
15317 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15318 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15320 TYPE_FIELD_PROTECTED_BITS (type
) =
15321 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15322 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15324 TYPE_FIELD_IGNORE_BITS (type
) =
15325 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15326 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15329 /* If the type has baseclasses, allocate and clear a bit vector for
15330 TYPE_FIELD_VIRTUAL_BITS. */
15331 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15333 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15334 unsigned char *pointer
;
15336 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15337 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15338 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15339 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15340 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15343 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15345 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15347 for (int index
= 0; index
< nfields
; ++index
)
15349 struct nextfield
&field
= fip
->fields
[index
];
15351 if (field
.variant
.is_discriminant
)
15352 di
->discriminant_index
= index
;
15353 else if (field
.variant
.default_branch
)
15354 di
->default_index
= index
;
15356 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15360 /* Copy the saved-up fields into the field vector. */
15361 for (int i
= 0; i
< nfields
; ++i
)
15363 struct nextfield
&field
15364 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15365 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15367 TYPE_FIELD (type
, i
) = field
.field
;
15368 switch (field
.accessibility
)
15370 case DW_ACCESS_private
:
15371 if (cu
->language
!= language_ada
)
15372 SET_TYPE_FIELD_PRIVATE (type
, i
);
15375 case DW_ACCESS_protected
:
15376 if (cu
->language
!= language_ada
)
15377 SET_TYPE_FIELD_PROTECTED (type
, i
);
15380 case DW_ACCESS_public
:
15384 /* Unknown accessibility. Complain and treat it as public. */
15386 complaint (_("unsupported accessibility %d"),
15387 field
.accessibility
);
15391 if (i
< fip
->baseclasses
.size ())
15393 switch (field
.virtuality
)
15395 case DW_VIRTUALITY_virtual
:
15396 case DW_VIRTUALITY_pure_virtual
:
15397 if (cu
->language
== language_ada
)
15398 error (_("unexpected virtuality in component of Ada type"));
15399 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15406 /* Return true if this member function is a constructor, false
15410 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15412 const char *fieldname
;
15413 const char *type_name
;
15416 if (die
->parent
== NULL
)
15419 if (die
->parent
->tag
!= DW_TAG_structure_type
15420 && die
->parent
->tag
!= DW_TAG_union_type
15421 && die
->parent
->tag
!= DW_TAG_class_type
)
15424 fieldname
= dwarf2_name (die
, cu
);
15425 type_name
= dwarf2_name (die
->parent
, cu
);
15426 if (fieldname
== NULL
|| type_name
== NULL
)
15429 len
= strlen (fieldname
);
15430 return (strncmp (fieldname
, type_name
, len
) == 0
15431 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15434 /* Add a member function to the proper fieldlist. */
15437 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15438 struct type
*type
, struct dwarf2_cu
*cu
)
15440 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15441 struct attribute
*attr
;
15443 struct fnfieldlist
*flp
= nullptr;
15444 struct fn_field
*fnp
;
15445 const char *fieldname
;
15446 struct type
*this_type
;
15447 enum dwarf_access_attribute accessibility
;
15449 if (cu
->language
== language_ada
)
15450 error (_("unexpected member function in Ada type"));
15452 /* Get name of member function. */
15453 fieldname
= dwarf2_name (die
, cu
);
15454 if (fieldname
== NULL
)
15457 /* Look up member function name in fieldlist. */
15458 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15460 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15462 flp
= &fip
->fnfieldlists
[i
];
15467 /* Create a new fnfieldlist if necessary. */
15468 if (flp
== nullptr)
15470 fip
->fnfieldlists
.emplace_back ();
15471 flp
= &fip
->fnfieldlists
.back ();
15472 flp
->name
= fieldname
;
15473 i
= fip
->fnfieldlists
.size () - 1;
15476 /* Create a new member function field and add it to the vector of
15478 flp
->fnfields
.emplace_back ();
15479 fnp
= &flp
->fnfields
.back ();
15481 /* Delay processing of the physname until later. */
15482 if (cu
->language
== language_cplus
)
15483 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15487 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15488 fnp
->physname
= physname
? physname
: "";
15491 fnp
->type
= alloc_type (objfile
);
15492 this_type
= read_type_die (die
, cu
);
15493 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15495 int nparams
= TYPE_NFIELDS (this_type
);
15497 /* TYPE is the domain of this method, and THIS_TYPE is the type
15498 of the method itself (TYPE_CODE_METHOD). */
15499 smash_to_method_type (fnp
->type
, type
,
15500 TYPE_TARGET_TYPE (this_type
),
15501 TYPE_FIELDS (this_type
),
15502 TYPE_NFIELDS (this_type
),
15503 TYPE_VARARGS (this_type
));
15505 /* Handle static member functions.
15506 Dwarf2 has no clean way to discern C++ static and non-static
15507 member functions. G++ helps GDB by marking the first
15508 parameter for non-static member functions (which is the this
15509 pointer) as artificial. We obtain this information from
15510 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15511 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15512 fnp
->voffset
= VOFFSET_STATIC
;
15515 complaint (_("member function type missing for '%s'"),
15516 dwarf2_full_name (fieldname
, die
, cu
));
15518 /* Get fcontext from DW_AT_containing_type if present. */
15519 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15520 fnp
->fcontext
= die_containing_type (die
, cu
);
15522 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15523 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15525 /* Get accessibility. */
15526 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15528 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15530 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15531 switch (accessibility
)
15533 case DW_ACCESS_private
:
15534 fnp
->is_private
= 1;
15536 case DW_ACCESS_protected
:
15537 fnp
->is_protected
= 1;
15541 /* Check for artificial methods. */
15542 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15543 if (attr
&& DW_UNSND (attr
) != 0)
15544 fnp
->is_artificial
= 1;
15546 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15548 /* Get index in virtual function table if it is a virtual member
15549 function. For older versions of GCC, this is an offset in the
15550 appropriate virtual table, as specified by DW_AT_containing_type.
15551 For everyone else, it is an expression to be evaluated relative
15552 to the object address. */
15554 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15557 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15559 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15561 /* Old-style GCC. */
15562 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15564 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15565 || (DW_BLOCK (attr
)->size
> 1
15566 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15567 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15569 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15570 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15571 dwarf2_complex_location_expr_complaint ();
15573 fnp
->voffset
/= cu
->header
.addr_size
;
15577 dwarf2_complex_location_expr_complaint ();
15579 if (!fnp
->fcontext
)
15581 /* If there is no `this' field and no DW_AT_containing_type,
15582 we cannot actually find a base class context for the
15584 if (TYPE_NFIELDS (this_type
) == 0
15585 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15587 complaint (_("cannot determine context for virtual member "
15588 "function \"%s\" (offset %s)"),
15589 fieldname
, sect_offset_str (die
->sect_off
));
15594 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15598 else if (attr_form_is_section_offset (attr
))
15600 dwarf2_complex_location_expr_complaint ();
15604 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15610 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15611 if (attr
&& DW_UNSND (attr
))
15613 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15614 complaint (_("Member function \"%s\" (offset %s) is virtual "
15615 "but the vtable offset is not specified"),
15616 fieldname
, sect_offset_str (die
->sect_off
));
15617 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15618 TYPE_CPLUS_DYNAMIC (type
) = 1;
15623 /* Create the vector of member function fields, and attach it to the type. */
15626 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15627 struct dwarf2_cu
*cu
)
15629 if (cu
->language
== language_ada
)
15630 error (_("unexpected member functions in Ada type"));
15632 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15633 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15635 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15637 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15639 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15640 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15642 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15643 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15644 fn_flp
->fn_fields
= (struct fn_field
*)
15645 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15647 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15648 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15651 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15654 /* Returns non-zero if NAME is the name of a vtable member in CU's
15655 language, zero otherwise. */
15657 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15659 static const char vptr
[] = "_vptr";
15661 /* Look for the C++ form of the vtable. */
15662 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15668 /* GCC outputs unnamed structures that are really pointers to member
15669 functions, with the ABI-specified layout. If TYPE describes
15670 such a structure, smash it into a member function type.
15672 GCC shouldn't do this; it should just output pointer to member DIEs.
15673 This is GCC PR debug/28767. */
15676 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15678 struct type
*pfn_type
, *self_type
, *new_type
;
15680 /* Check for a structure with no name and two children. */
15681 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15684 /* Check for __pfn and __delta members. */
15685 if (TYPE_FIELD_NAME (type
, 0) == NULL
15686 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15687 || TYPE_FIELD_NAME (type
, 1) == NULL
15688 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15691 /* Find the type of the method. */
15692 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15693 if (pfn_type
== NULL
15694 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15695 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15698 /* Look for the "this" argument. */
15699 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15700 if (TYPE_NFIELDS (pfn_type
) == 0
15701 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15702 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15705 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15706 new_type
= alloc_type (objfile
);
15707 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15708 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15709 TYPE_VARARGS (pfn_type
));
15710 smash_to_methodptr_type (type
, new_type
);
15713 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15714 appropriate error checking and issuing complaints if there is a
15718 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15720 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15722 if (attr
== nullptr)
15725 if (!attr_form_is_constant (attr
))
15727 complaint (_("DW_AT_alignment must have constant form"
15728 " - DIE at %s [in module %s]"),
15729 sect_offset_str (die
->sect_off
),
15730 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15735 if (attr
->form
== DW_FORM_sdata
)
15737 LONGEST val
= DW_SND (attr
);
15740 complaint (_("DW_AT_alignment value must not be negative"
15741 " - DIE at %s [in module %s]"),
15742 sect_offset_str (die
->sect_off
),
15743 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15749 align
= DW_UNSND (attr
);
15753 complaint (_("DW_AT_alignment value must not be zero"
15754 " - DIE at %s [in module %s]"),
15755 sect_offset_str (die
->sect_off
),
15756 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15759 if ((align
& (align
- 1)) != 0)
15761 complaint (_("DW_AT_alignment value must be a power of 2"
15762 " - DIE at %s [in module %s]"),
15763 sect_offset_str (die
->sect_off
),
15764 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15771 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15772 the alignment for TYPE. */
15775 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15778 if (!set_type_align (type
, get_alignment (cu
, die
)))
15779 complaint (_("DW_AT_alignment value too large"
15780 " - DIE at %s [in module %s]"),
15781 sect_offset_str (die
->sect_off
),
15782 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15785 /* Called when we find the DIE that starts a structure or union scope
15786 (definition) to create a type for the structure or union. Fill in
15787 the type's name and general properties; the members will not be
15788 processed until process_structure_scope. A symbol table entry for
15789 the type will also not be done until process_structure_scope (assuming
15790 the type has a name).
15792 NOTE: we need to call these functions regardless of whether or not the
15793 DIE has a DW_AT_name attribute, since it might be an anonymous
15794 structure or union. This gets the type entered into our set of
15795 user defined types. */
15797 static struct type
*
15798 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15800 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15802 struct attribute
*attr
;
15805 /* If the definition of this type lives in .debug_types, read that type.
15806 Don't follow DW_AT_specification though, that will take us back up
15807 the chain and we want to go down. */
15808 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15811 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15813 /* The type's CU may not be the same as CU.
15814 Ensure TYPE is recorded with CU in die_type_hash. */
15815 return set_die_type (die
, type
, cu
);
15818 type
= alloc_type (objfile
);
15819 INIT_CPLUS_SPECIFIC (type
);
15821 name
= dwarf2_name (die
, cu
);
15824 if (cu
->language
== language_cplus
15825 || cu
->language
== language_d
15826 || cu
->language
== language_rust
)
15828 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15830 /* dwarf2_full_name might have already finished building the DIE's
15831 type. If so, there is no need to continue. */
15832 if (get_die_type (die
, cu
) != NULL
)
15833 return get_die_type (die
, cu
);
15835 TYPE_NAME (type
) = full_name
;
15839 /* The name is already allocated along with this objfile, so
15840 we don't need to duplicate it for the type. */
15841 TYPE_NAME (type
) = name
;
15845 if (die
->tag
== DW_TAG_structure_type
)
15847 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15849 else if (die
->tag
== DW_TAG_union_type
)
15851 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15853 else if (die
->tag
== DW_TAG_variant_part
)
15855 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15856 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15860 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15863 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15864 TYPE_DECLARED_CLASS (type
) = 1;
15866 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15869 if (attr_form_is_constant (attr
))
15870 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15873 /* For the moment, dynamic type sizes are not supported
15874 by GDB's struct type. The actual size is determined
15875 on-demand when resolving the type of a given object,
15876 so set the type's length to zero for now. Otherwise,
15877 we record an expression as the length, and that expression
15878 could lead to a very large value, which could eventually
15879 lead to us trying to allocate that much memory when creating
15880 a value of that type. */
15881 TYPE_LENGTH (type
) = 0;
15886 TYPE_LENGTH (type
) = 0;
15889 maybe_set_alignment (cu
, die
, type
);
15891 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15893 /* ICC<14 does not output the required DW_AT_declaration on
15894 incomplete types, but gives them a size of zero. */
15895 TYPE_STUB (type
) = 1;
15898 TYPE_STUB_SUPPORTED (type
) = 1;
15900 if (die_is_declaration (die
, cu
))
15901 TYPE_STUB (type
) = 1;
15902 else if (attr
== NULL
&& die
->child
== NULL
15903 && producer_is_realview (cu
->producer
))
15904 /* RealView does not output the required DW_AT_declaration
15905 on incomplete types. */
15906 TYPE_STUB (type
) = 1;
15908 /* We need to add the type field to the die immediately so we don't
15909 infinitely recurse when dealing with pointers to the structure
15910 type within the structure itself. */
15911 set_die_type (die
, type
, cu
);
15913 /* set_die_type should be already done. */
15914 set_descriptive_type (type
, die
, cu
);
15919 /* A helper for process_structure_scope that handles a single member
15923 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15924 struct field_info
*fi
,
15925 std::vector
<struct symbol
*> *template_args
,
15926 struct dwarf2_cu
*cu
)
15928 if (child_die
->tag
== DW_TAG_member
15929 || child_die
->tag
== DW_TAG_variable
15930 || child_die
->tag
== DW_TAG_variant_part
)
15932 /* NOTE: carlton/2002-11-05: A C++ static data member
15933 should be a DW_TAG_member that is a declaration, but
15934 all versions of G++ as of this writing (so through at
15935 least 3.2.1) incorrectly generate DW_TAG_variable
15936 tags for them instead. */
15937 dwarf2_add_field (fi
, child_die
, cu
);
15939 else if (child_die
->tag
== DW_TAG_subprogram
)
15941 /* Rust doesn't have member functions in the C++ sense.
15942 However, it does emit ordinary functions as children
15943 of a struct DIE. */
15944 if (cu
->language
== language_rust
)
15945 read_func_scope (child_die
, cu
);
15948 /* C++ member function. */
15949 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15952 else if (child_die
->tag
== DW_TAG_inheritance
)
15954 /* C++ base class field. */
15955 dwarf2_add_field (fi
, child_die
, cu
);
15957 else if (type_can_define_types (child_die
))
15958 dwarf2_add_type_defn (fi
, child_die
, cu
);
15959 else if (child_die
->tag
== DW_TAG_template_type_param
15960 || child_die
->tag
== DW_TAG_template_value_param
)
15962 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15965 template_args
->push_back (arg
);
15967 else if (child_die
->tag
== DW_TAG_variant
)
15969 /* In a variant we want to get the discriminant and also add a
15970 field for our sole member child. */
15971 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15973 for (struct die_info
*variant_child
= child_die
->child
;
15974 variant_child
!= NULL
;
15975 variant_child
= sibling_die (variant_child
))
15977 if (variant_child
->tag
== DW_TAG_member
)
15979 handle_struct_member_die (variant_child
, type
, fi
,
15980 template_args
, cu
);
15981 /* Only handle the one. */
15986 /* We don't handle this but we might as well report it if we see
15988 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15989 complaint (_("DW_AT_discr_list is not supported yet"
15990 " - DIE at %s [in module %s]"),
15991 sect_offset_str (child_die
->sect_off
),
15992 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15994 /* The first field was just added, so we can stash the
15995 discriminant there. */
15996 gdb_assert (!fi
->fields
.empty ());
15998 fi
->fields
.back ().variant
.default_branch
= true;
16000 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16004 /* Finish creating a structure or union type, including filling in
16005 its members and creating a symbol for it. */
16008 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16010 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16011 struct die_info
*child_die
;
16014 type
= get_die_type (die
, cu
);
16016 type
= read_structure_type (die
, cu
);
16018 /* When reading a DW_TAG_variant_part, we need to notice when we
16019 read the discriminant member, so we can record it later in the
16020 discriminant_info. */
16021 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16022 sect_offset discr_offset
;
16023 bool has_template_parameters
= false;
16025 if (is_variant_part
)
16027 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16030 /* Maybe it's a univariant form, an extension we support.
16031 In this case arrange not to check the offset. */
16032 is_variant_part
= false;
16034 else if (attr_form_is_ref (discr
))
16036 struct dwarf2_cu
*target_cu
= cu
;
16037 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16039 discr_offset
= target_die
->sect_off
;
16043 complaint (_("DW_AT_discr does not have DIE reference form"
16044 " - DIE at %s [in module %s]"),
16045 sect_offset_str (die
->sect_off
),
16046 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16047 is_variant_part
= false;
16051 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16053 struct field_info fi
;
16054 std::vector
<struct symbol
*> template_args
;
16056 child_die
= die
->child
;
16058 while (child_die
&& child_die
->tag
)
16060 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16062 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16063 fi
.fields
.back ().variant
.is_discriminant
= true;
16065 child_die
= sibling_die (child_die
);
16068 /* Attach template arguments to type. */
16069 if (!template_args
.empty ())
16071 has_template_parameters
= true;
16072 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16073 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16074 TYPE_TEMPLATE_ARGUMENTS (type
)
16075 = XOBNEWVEC (&objfile
->objfile_obstack
,
16077 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16078 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16079 template_args
.data (),
16080 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16081 * sizeof (struct symbol
*)));
16084 /* Attach fields and member functions to the type. */
16086 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16087 if (!fi
.fnfieldlists
.empty ())
16089 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16091 /* Get the type which refers to the base class (possibly this
16092 class itself) which contains the vtable pointer for the current
16093 class from the DW_AT_containing_type attribute. This use of
16094 DW_AT_containing_type is a GNU extension. */
16096 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16098 struct type
*t
= die_containing_type (die
, cu
);
16100 set_type_vptr_basetype (type
, t
);
16105 /* Our own class provides vtbl ptr. */
16106 for (i
= TYPE_NFIELDS (t
) - 1;
16107 i
>= TYPE_N_BASECLASSES (t
);
16110 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16112 if (is_vtable_name (fieldname
, cu
))
16114 set_type_vptr_fieldno (type
, i
);
16119 /* Complain if virtual function table field not found. */
16120 if (i
< TYPE_N_BASECLASSES (t
))
16121 complaint (_("virtual function table pointer "
16122 "not found when defining class '%s'"),
16123 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16127 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16130 else if (cu
->producer
16131 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16133 /* The IBM XLC compiler does not provide direct indication
16134 of the containing type, but the vtable pointer is
16135 always named __vfp. */
16139 for (i
= TYPE_NFIELDS (type
) - 1;
16140 i
>= TYPE_N_BASECLASSES (type
);
16143 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16145 set_type_vptr_fieldno (type
, i
);
16146 set_type_vptr_basetype (type
, type
);
16153 /* Copy fi.typedef_field_list linked list elements content into the
16154 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16155 if (!fi
.typedef_field_list
.empty ())
16157 int count
= fi
.typedef_field_list
.size ();
16159 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16160 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16161 = ((struct decl_field
*)
16163 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16164 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16166 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16167 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16170 /* Copy fi.nested_types_list linked list elements content into the
16171 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16172 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16174 int count
= fi
.nested_types_list
.size ();
16176 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16177 TYPE_NESTED_TYPES_ARRAY (type
)
16178 = ((struct decl_field
*)
16179 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16180 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16182 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16183 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16187 quirk_gcc_member_function_pointer (type
, objfile
);
16188 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16189 cu
->rust_unions
.push_back (type
);
16191 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16192 snapshots) has been known to create a die giving a declaration
16193 for a class that has, as a child, a die giving a definition for a
16194 nested class. So we have to process our children even if the
16195 current die is a declaration. Normally, of course, a declaration
16196 won't have any children at all. */
16198 child_die
= die
->child
;
16200 while (child_die
!= NULL
&& child_die
->tag
)
16202 if (child_die
->tag
== DW_TAG_member
16203 || child_die
->tag
== DW_TAG_variable
16204 || child_die
->tag
== DW_TAG_inheritance
16205 || child_die
->tag
== DW_TAG_template_value_param
16206 || child_die
->tag
== DW_TAG_template_type_param
)
16211 process_die (child_die
, cu
);
16213 child_die
= sibling_die (child_die
);
16216 /* Do not consider external references. According to the DWARF standard,
16217 these DIEs are identified by the fact that they have no byte_size
16218 attribute, and a declaration attribute. */
16219 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16220 || !die_is_declaration (die
, cu
))
16222 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16224 if (has_template_parameters
)
16226 /* Make sure that the symtab is set on the new symbols.
16227 Even though they don't appear in this symtab directly,
16228 other parts of gdb assume that symbols do, and this is
16229 reasonably true. */
16230 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16231 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
),
16232 symbol_symtab (sym
));
16237 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16238 update TYPE using some information only available in DIE's children. */
16241 update_enumeration_type_from_children (struct die_info
*die
,
16243 struct dwarf2_cu
*cu
)
16245 struct die_info
*child_die
;
16246 int unsigned_enum
= 1;
16250 auto_obstack obstack
;
16252 for (child_die
= die
->child
;
16253 child_die
!= NULL
&& child_die
->tag
;
16254 child_die
= sibling_die (child_die
))
16256 struct attribute
*attr
;
16258 const gdb_byte
*bytes
;
16259 struct dwarf2_locexpr_baton
*baton
;
16262 if (child_die
->tag
!= DW_TAG_enumerator
)
16265 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16269 name
= dwarf2_name (child_die
, cu
);
16271 name
= "<anonymous enumerator>";
16273 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16274 &value
, &bytes
, &baton
);
16280 else if ((mask
& value
) != 0)
16285 /* If we already know that the enum type is neither unsigned, nor
16286 a flag type, no need to look at the rest of the enumerates. */
16287 if (!unsigned_enum
&& !flag_enum
)
16292 TYPE_UNSIGNED (type
) = 1;
16294 TYPE_FLAG_ENUM (type
) = 1;
16297 /* Given a DW_AT_enumeration_type die, set its type. We do not
16298 complete the type's fields yet, or create any symbols. */
16300 static struct type
*
16301 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16303 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16305 struct attribute
*attr
;
16308 /* If the definition of this type lives in .debug_types, read that type.
16309 Don't follow DW_AT_specification though, that will take us back up
16310 the chain and we want to go down. */
16311 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16314 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16316 /* The type's CU may not be the same as CU.
16317 Ensure TYPE is recorded with CU in die_type_hash. */
16318 return set_die_type (die
, type
, cu
);
16321 type
= alloc_type (objfile
);
16323 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16324 name
= dwarf2_full_name (NULL
, die
, cu
);
16326 TYPE_NAME (type
) = name
;
16328 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16331 struct type
*underlying_type
= die_type (die
, cu
);
16333 TYPE_TARGET_TYPE (type
) = underlying_type
;
16336 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16339 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16343 TYPE_LENGTH (type
) = 0;
16346 maybe_set_alignment (cu
, die
, type
);
16348 /* The enumeration DIE can be incomplete. In Ada, any type can be
16349 declared as private in the package spec, and then defined only
16350 inside the package body. Such types are known as Taft Amendment
16351 Types. When another package uses such a type, an incomplete DIE
16352 may be generated by the compiler. */
16353 if (die_is_declaration (die
, cu
))
16354 TYPE_STUB (type
) = 1;
16356 /* Finish the creation of this type by using the enum's children.
16357 We must call this even when the underlying type has been provided
16358 so that we can determine if we're looking at a "flag" enum. */
16359 update_enumeration_type_from_children (die
, type
, cu
);
16361 /* If this type has an underlying type that is not a stub, then we
16362 may use its attributes. We always use the "unsigned" attribute
16363 in this situation, because ordinarily we guess whether the type
16364 is unsigned -- but the guess can be wrong and the underlying type
16365 can tell us the reality. However, we defer to a local size
16366 attribute if one exists, because this lets the compiler override
16367 the underlying type if needed. */
16368 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16370 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16371 if (TYPE_LENGTH (type
) == 0)
16372 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16373 if (TYPE_RAW_ALIGN (type
) == 0
16374 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16375 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16378 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16380 return set_die_type (die
, type
, cu
);
16383 /* Given a pointer to a die which begins an enumeration, process all
16384 the dies that define the members of the enumeration, and create the
16385 symbol for the enumeration type.
16387 NOTE: We reverse the order of the element list. */
16390 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16392 struct type
*this_type
;
16394 this_type
= get_die_type (die
, cu
);
16395 if (this_type
== NULL
)
16396 this_type
= read_enumeration_type (die
, cu
);
16398 if (die
->child
!= NULL
)
16400 struct die_info
*child_die
;
16401 struct symbol
*sym
;
16402 struct field
*fields
= NULL
;
16403 int num_fields
= 0;
16406 child_die
= die
->child
;
16407 while (child_die
&& child_die
->tag
)
16409 if (child_die
->tag
!= DW_TAG_enumerator
)
16411 process_die (child_die
, cu
);
16415 name
= dwarf2_name (child_die
, cu
);
16418 sym
= new_symbol (child_die
, this_type
, cu
);
16420 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16422 fields
= (struct field
*)
16424 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16425 * sizeof (struct field
));
16428 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16429 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16430 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16431 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16437 child_die
= sibling_die (child_die
);
16442 TYPE_NFIELDS (this_type
) = num_fields
;
16443 TYPE_FIELDS (this_type
) = (struct field
*)
16444 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16445 memcpy (TYPE_FIELDS (this_type
), fields
,
16446 sizeof (struct field
) * num_fields
);
16451 /* If we are reading an enum from a .debug_types unit, and the enum
16452 is a declaration, and the enum is not the signatured type in the
16453 unit, then we do not want to add a symbol for it. Adding a
16454 symbol would in some cases obscure the true definition of the
16455 enum, giving users an incomplete type when the definition is
16456 actually available. Note that we do not want to do this for all
16457 enums which are just declarations, because C++0x allows forward
16458 enum declarations. */
16459 if (cu
->per_cu
->is_debug_types
16460 && die_is_declaration (die
, cu
))
16462 struct signatured_type
*sig_type
;
16464 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16465 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16466 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16470 new_symbol (die
, this_type
, cu
);
16473 /* Extract all information from a DW_TAG_array_type DIE and put it in
16474 the DIE's type field. For now, this only handles one dimensional
16477 static struct type
*
16478 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16480 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16481 struct die_info
*child_die
;
16483 struct type
*element_type
, *range_type
, *index_type
;
16484 struct attribute
*attr
;
16486 struct dynamic_prop
*byte_stride_prop
= NULL
;
16487 unsigned int bit_stride
= 0;
16489 element_type
= die_type (die
, cu
);
16491 /* The die_type call above may have already set the type for this DIE. */
16492 type
= get_die_type (die
, cu
);
16496 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16502 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16503 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
);
16506 complaint (_("unable to read array DW_AT_byte_stride "
16507 " - DIE at %s [in module %s]"),
16508 sect_offset_str (die
->sect_off
),
16509 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16510 /* Ignore this attribute. We will likely not be able to print
16511 arrays of this type correctly, but there is little we can do
16512 to help if we cannot read the attribute's value. */
16513 byte_stride_prop
= NULL
;
16517 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16519 bit_stride
= DW_UNSND (attr
);
16521 /* Irix 6.2 native cc creates array types without children for
16522 arrays with unspecified length. */
16523 if (die
->child
== NULL
)
16525 index_type
= objfile_type (objfile
)->builtin_int
;
16526 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16527 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16528 byte_stride_prop
, bit_stride
);
16529 return set_die_type (die
, type
, cu
);
16532 std::vector
<struct type
*> range_types
;
16533 child_die
= die
->child
;
16534 while (child_die
&& child_die
->tag
)
16536 if (child_die
->tag
== DW_TAG_subrange_type
)
16538 struct type
*child_type
= read_type_die (child_die
, cu
);
16540 if (child_type
!= NULL
)
16542 /* The range type was succesfully read. Save it for the
16543 array type creation. */
16544 range_types
.push_back (child_type
);
16547 child_die
= sibling_die (child_die
);
16550 /* Dwarf2 dimensions are output from left to right, create the
16551 necessary array types in backwards order. */
16553 type
= element_type
;
16555 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16559 while (i
< range_types
.size ())
16560 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16561 byte_stride_prop
, bit_stride
);
16565 size_t ndim
= range_types
.size ();
16567 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16568 byte_stride_prop
, bit_stride
);
16571 /* Understand Dwarf2 support for vector types (like they occur on
16572 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16573 array type. This is not part of the Dwarf2/3 standard yet, but a
16574 custom vendor extension. The main difference between a regular
16575 array and the vector variant is that vectors are passed by value
16577 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16579 make_vector_type (type
);
16581 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16582 implementation may choose to implement triple vectors using this
16584 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16587 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16588 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16590 complaint (_("DW_AT_byte_size for array type smaller "
16591 "than the total size of elements"));
16594 name
= dwarf2_name (die
, cu
);
16596 TYPE_NAME (type
) = name
;
16598 maybe_set_alignment (cu
, die
, type
);
16600 /* Install the type in the die. */
16601 set_die_type (die
, type
, cu
);
16603 /* set_die_type should be already done. */
16604 set_descriptive_type (type
, die
, cu
);
16609 static enum dwarf_array_dim_ordering
16610 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16612 struct attribute
*attr
;
16614 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16617 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16619 /* GNU F77 is a special case, as at 08/2004 array type info is the
16620 opposite order to the dwarf2 specification, but data is still
16621 laid out as per normal fortran.
16623 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16624 version checking. */
16626 if (cu
->language
== language_fortran
16627 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16629 return DW_ORD_row_major
;
16632 switch (cu
->language_defn
->la_array_ordering
)
16634 case array_column_major
:
16635 return DW_ORD_col_major
;
16636 case array_row_major
:
16638 return DW_ORD_row_major
;
16642 /* Extract all information from a DW_TAG_set_type DIE and put it in
16643 the DIE's type field. */
16645 static struct type
*
16646 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16648 struct type
*domain_type
, *set_type
;
16649 struct attribute
*attr
;
16651 domain_type
= die_type (die
, cu
);
16653 /* The die_type call above may have already set the type for this DIE. */
16654 set_type
= get_die_type (die
, cu
);
16658 set_type
= create_set_type (NULL
, domain_type
);
16660 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16662 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16664 maybe_set_alignment (cu
, die
, set_type
);
16666 return set_die_type (die
, set_type
, cu
);
16669 /* A helper for read_common_block that creates a locexpr baton.
16670 SYM is the symbol which we are marking as computed.
16671 COMMON_DIE is the DIE for the common block.
16672 COMMON_LOC is the location expression attribute for the common
16674 MEMBER_LOC is the location expression attribute for the particular
16675 member of the common block that we are processing.
16676 CU is the CU from which the above come. */
16679 mark_common_block_symbol_computed (struct symbol
*sym
,
16680 struct die_info
*common_die
,
16681 struct attribute
*common_loc
,
16682 struct attribute
*member_loc
,
16683 struct dwarf2_cu
*cu
)
16685 struct dwarf2_per_objfile
*dwarf2_per_objfile
16686 = cu
->per_cu
->dwarf2_per_objfile
;
16687 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16688 struct dwarf2_locexpr_baton
*baton
;
16690 unsigned int cu_off
;
16691 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16692 LONGEST offset
= 0;
16694 gdb_assert (common_loc
&& member_loc
);
16695 gdb_assert (attr_form_is_block (common_loc
));
16696 gdb_assert (attr_form_is_block (member_loc
)
16697 || attr_form_is_constant (member_loc
));
16699 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16700 baton
->per_cu
= cu
->per_cu
;
16701 gdb_assert (baton
->per_cu
);
16703 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16705 if (attr_form_is_constant (member_loc
))
16707 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16708 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16711 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16713 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16716 *ptr
++ = DW_OP_call4
;
16717 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16718 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16721 if (attr_form_is_constant (member_loc
))
16723 *ptr
++ = DW_OP_addr
;
16724 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16725 ptr
+= cu
->header
.addr_size
;
16729 /* We have to copy the data here, because DW_OP_call4 will only
16730 use a DW_AT_location attribute. */
16731 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16732 ptr
+= DW_BLOCK (member_loc
)->size
;
16735 *ptr
++ = DW_OP_plus
;
16736 gdb_assert (ptr
- baton
->data
== baton
->size
);
16738 SYMBOL_LOCATION_BATON (sym
) = baton
;
16739 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16742 /* Create appropriate locally-scoped variables for all the
16743 DW_TAG_common_block entries. Also create a struct common_block
16744 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16745 is used to sepate the common blocks name namespace from regular
16749 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16751 struct attribute
*attr
;
16753 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16756 /* Support the .debug_loc offsets. */
16757 if (attr_form_is_block (attr
))
16761 else if (attr_form_is_section_offset (attr
))
16763 dwarf2_complex_location_expr_complaint ();
16768 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16769 "common block member");
16774 if (die
->child
!= NULL
)
16776 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16777 struct die_info
*child_die
;
16778 size_t n_entries
= 0, size
;
16779 struct common_block
*common_block
;
16780 struct symbol
*sym
;
16782 for (child_die
= die
->child
;
16783 child_die
&& child_die
->tag
;
16784 child_die
= sibling_die (child_die
))
16787 size
= (sizeof (struct common_block
)
16788 + (n_entries
- 1) * sizeof (struct symbol
*));
16790 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16792 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16793 common_block
->n_entries
= 0;
16795 for (child_die
= die
->child
;
16796 child_die
&& child_die
->tag
;
16797 child_die
= sibling_die (child_die
))
16799 /* Create the symbol in the DW_TAG_common_block block in the current
16801 sym
= new_symbol (child_die
, NULL
, cu
);
16804 struct attribute
*member_loc
;
16806 common_block
->contents
[common_block
->n_entries
++] = sym
;
16808 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16812 /* GDB has handled this for a long time, but it is
16813 not specified by DWARF. It seems to have been
16814 emitted by gfortran at least as recently as:
16815 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16816 complaint (_("Variable in common block has "
16817 "DW_AT_data_member_location "
16818 "- DIE at %s [in module %s]"),
16819 sect_offset_str (child_die
->sect_off
),
16820 objfile_name (objfile
));
16822 if (attr_form_is_section_offset (member_loc
))
16823 dwarf2_complex_location_expr_complaint ();
16824 else if (attr_form_is_constant (member_loc
)
16825 || attr_form_is_block (member_loc
))
16828 mark_common_block_symbol_computed (sym
, die
, attr
,
16832 dwarf2_complex_location_expr_complaint ();
16837 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16838 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16842 /* Create a type for a C++ namespace. */
16844 static struct type
*
16845 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16847 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16848 const char *previous_prefix
, *name
;
16852 /* For extensions, reuse the type of the original namespace. */
16853 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16855 struct die_info
*ext_die
;
16856 struct dwarf2_cu
*ext_cu
= cu
;
16858 ext_die
= dwarf2_extension (die
, &ext_cu
);
16859 type
= read_type_die (ext_die
, ext_cu
);
16861 /* EXT_CU may not be the same as CU.
16862 Ensure TYPE is recorded with CU in die_type_hash. */
16863 return set_die_type (die
, type
, cu
);
16866 name
= namespace_name (die
, &is_anonymous
, cu
);
16868 /* Now build the name of the current namespace. */
16870 previous_prefix
= determine_prefix (die
, cu
);
16871 if (previous_prefix
[0] != '\0')
16872 name
= typename_concat (&objfile
->objfile_obstack
,
16873 previous_prefix
, name
, 0, cu
);
16875 /* Create the type. */
16876 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16878 return set_die_type (die
, type
, cu
);
16881 /* Read a namespace scope. */
16884 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16886 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16889 /* Add a symbol associated to this if we haven't seen the namespace
16890 before. Also, add a using directive if it's an anonymous
16893 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16897 type
= read_type_die (die
, cu
);
16898 new_symbol (die
, type
, cu
);
16900 namespace_name (die
, &is_anonymous
, cu
);
16903 const char *previous_prefix
= determine_prefix (die
, cu
);
16905 std::vector
<const char *> excludes
;
16906 add_using_directive (using_directives (cu
),
16907 previous_prefix
, TYPE_NAME (type
), NULL
,
16908 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16912 if (die
->child
!= NULL
)
16914 struct die_info
*child_die
= die
->child
;
16916 while (child_die
&& child_die
->tag
)
16918 process_die (child_die
, cu
);
16919 child_die
= sibling_die (child_die
);
16924 /* Read a Fortran module as type. This DIE can be only a declaration used for
16925 imported module. Still we need that type as local Fortran "use ... only"
16926 declaration imports depend on the created type in determine_prefix. */
16928 static struct type
*
16929 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16931 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16932 const char *module_name
;
16935 module_name
= dwarf2_name (die
, cu
);
16937 complaint (_("DW_TAG_module has no name, offset %s"),
16938 sect_offset_str (die
->sect_off
));
16939 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16941 return set_die_type (die
, type
, cu
);
16944 /* Read a Fortran module. */
16947 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16949 struct die_info
*child_die
= die
->child
;
16952 type
= read_type_die (die
, cu
);
16953 new_symbol (die
, type
, cu
);
16955 while (child_die
&& child_die
->tag
)
16957 process_die (child_die
, cu
);
16958 child_die
= sibling_die (child_die
);
16962 /* Return the name of the namespace represented by DIE. Set
16963 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16966 static const char *
16967 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16969 struct die_info
*current_die
;
16970 const char *name
= NULL
;
16972 /* Loop through the extensions until we find a name. */
16974 for (current_die
= die
;
16975 current_die
!= NULL
;
16976 current_die
= dwarf2_extension (die
, &cu
))
16978 /* We don't use dwarf2_name here so that we can detect the absence
16979 of a name -> anonymous namespace. */
16980 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16986 /* Is it an anonymous namespace? */
16988 *is_anonymous
= (name
== NULL
);
16990 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16995 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16996 the user defined type vector. */
16998 static struct type
*
16999 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17001 struct gdbarch
*gdbarch
17002 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17003 struct comp_unit_head
*cu_header
= &cu
->header
;
17005 struct attribute
*attr_byte_size
;
17006 struct attribute
*attr_address_class
;
17007 int byte_size
, addr_class
;
17008 struct type
*target_type
;
17010 target_type
= die_type (die
, cu
);
17012 /* The die_type call above may have already set the type for this DIE. */
17013 type
= get_die_type (die
, cu
);
17017 type
= lookup_pointer_type (target_type
);
17019 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17020 if (attr_byte_size
)
17021 byte_size
= DW_UNSND (attr_byte_size
);
17023 byte_size
= cu_header
->addr_size
;
17025 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17026 if (attr_address_class
)
17027 addr_class
= DW_UNSND (attr_address_class
);
17029 addr_class
= DW_ADDR_none
;
17031 ULONGEST alignment
= get_alignment (cu
, die
);
17033 /* If the pointer size, alignment, or address class is different
17034 than the default, create a type variant marked as such and set
17035 the length accordingly. */
17036 if (TYPE_LENGTH (type
) != byte_size
17037 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17038 && alignment
!= TYPE_RAW_ALIGN (type
))
17039 || addr_class
!= DW_ADDR_none
)
17041 if (gdbarch_address_class_type_flags_p (gdbarch
))
17045 type_flags
= gdbarch_address_class_type_flags
17046 (gdbarch
, byte_size
, addr_class
);
17047 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17049 type
= make_type_with_address_space (type
, type_flags
);
17051 else if (TYPE_LENGTH (type
) != byte_size
)
17053 complaint (_("invalid pointer size %d"), byte_size
);
17055 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17057 complaint (_("Invalid DW_AT_alignment"
17058 " - DIE at %s [in module %s]"),
17059 sect_offset_str (die
->sect_off
),
17060 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17064 /* Should we also complain about unhandled address classes? */
17068 TYPE_LENGTH (type
) = byte_size
;
17069 set_type_align (type
, alignment
);
17070 return set_die_type (die
, type
, cu
);
17073 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17074 the user defined type vector. */
17076 static struct type
*
17077 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17080 struct type
*to_type
;
17081 struct type
*domain
;
17083 to_type
= die_type (die
, cu
);
17084 domain
= die_containing_type (die
, cu
);
17086 /* The calls above may have already set the type for this DIE. */
17087 type
= get_die_type (die
, cu
);
17091 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17092 type
= lookup_methodptr_type (to_type
);
17093 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17095 struct type
*new_type
17096 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17098 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17099 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17100 TYPE_VARARGS (to_type
));
17101 type
= lookup_methodptr_type (new_type
);
17104 type
= lookup_memberptr_type (to_type
, domain
);
17106 return set_die_type (die
, type
, cu
);
17109 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17110 the user defined type vector. */
17112 static struct type
*
17113 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17114 enum type_code refcode
)
17116 struct comp_unit_head
*cu_header
= &cu
->header
;
17117 struct type
*type
, *target_type
;
17118 struct attribute
*attr
;
17120 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17122 target_type
= die_type (die
, cu
);
17124 /* The die_type call above may have already set the type for this DIE. */
17125 type
= get_die_type (die
, cu
);
17129 type
= lookup_reference_type (target_type
, refcode
);
17130 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17133 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17137 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17139 maybe_set_alignment (cu
, die
, type
);
17140 return set_die_type (die
, type
, cu
);
17143 /* Add the given cv-qualifiers to the element type of the array. GCC
17144 outputs DWARF type qualifiers that apply to an array, not the
17145 element type. But GDB relies on the array element type to carry
17146 the cv-qualifiers. This mimics section 6.7.3 of the C99
17149 static struct type
*
17150 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17151 struct type
*base_type
, int cnst
, int voltl
)
17153 struct type
*el_type
, *inner_array
;
17155 base_type
= copy_type (base_type
);
17156 inner_array
= base_type
;
17158 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17160 TYPE_TARGET_TYPE (inner_array
) =
17161 copy_type (TYPE_TARGET_TYPE (inner_array
));
17162 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17165 el_type
= TYPE_TARGET_TYPE (inner_array
);
17166 cnst
|= TYPE_CONST (el_type
);
17167 voltl
|= TYPE_VOLATILE (el_type
);
17168 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17170 return set_die_type (die
, base_type
, cu
);
17173 static struct type
*
17174 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17176 struct type
*base_type
, *cv_type
;
17178 base_type
= die_type (die
, cu
);
17180 /* The die_type call above may have already set the type for this DIE. */
17181 cv_type
= get_die_type (die
, cu
);
17185 /* In case the const qualifier is applied to an array type, the element type
17186 is so qualified, not the array type (section 6.7.3 of C99). */
17187 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17188 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17190 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17191 return set_die_type (die
, cv_type
, cu
);
17194 static struct type
*
17195 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17197 struct type
*base_type
, *cv_type
;
17199 base_type
= die_type (die
, cu
);
17201 /* The die_type call above may have already set the type for this DIE. */
17202 cv_type
= get_die_type (die
, cu
);
17206 /* In case the volatile qualifier is applied to an array type, the
17207 element type is so qualified, not the array type (section 6.7.3
17209 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17210 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17212 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17213 return set_die_type (die
, cv_type
, cu
);
17216 /* Handle DW_TAG_restrict_type. */
17218 static struct type
*
17219 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17221 struct type
*base_type
, *cv_type
;
17223 base_type
= die_type (die
, cu
);
17225 /* The die_type call above may have already set the type for this DIE. */
17226 cv_type
= get_die_type (die
, cu
);
17230 cv_type
= make_restrict_type (base_type
);
17231 return set_die_type (die
, cv_type
, cu
);
17234 /* Handle DW_TAG_atomic_type. */
17236 static struct type
*
17237 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17239 struct type
*base_type
, *cv_type
;
17241 base_type
= die_type (die
, cu
);
17243 /* The die_type call above may have already set the type for this DIE. */
17244 cv_type
= get_die_type (die
, cu
);
17248 cv_type
= make_atomic_type (base_type
);
17249 return set_die_type (die
, cv_type
, cu
);
17252 /* Extract all information from a DW_TAG_string_type DIE and add to
17253 the user defined type vector. It isn't really a user defined type,
17254 but it behaves like one, with other DIE's using an AT_user_def_type
17255 attribute to reference it. */
17257 static struct type
*
17258 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17260 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17261 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17262 struct type
*type
, *range_type
, *index_type
, *char_type
;
17263 struct attribute
*attr
;
17264 unsigned int length
;
17266 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17269 length
= DW_UNSND (attr
);
17273 /* Check for the DW_AT_byte_size attribute. */
17274 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17277 length
= DW_UNSND (attr
);
17285 index_type
= objfile_type (objfile
)->builtin_int
;
17286 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17287 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17288 type
= create_string_type (NULL
, char_type
, range_type
);
17290 return set_die_type (die
, type
, cu
);
17293 /* Assuming that DIE corresponds to a function, returns nonzero
17294 if the function is prototyped. */
17297 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17299 struct attribute
*attr
;
17301 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17302 if (attr
&& (DW_UNSND (attr
) != 0))
17305 /* The DWARF standard implies that the DW_AT_prototyped attribute
17306 is only meaninful for C, but the concept also extends to other
17307 languages that allow unprototyped functions (Eg: Objective C).
17308 For all other languages, assume that functions are always
17310 if (cu
->language
!= language_c
17311 && cu
->language
!= language_objc
17312 && cu
->language
!= language_opencl
)
17315 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17316 prototyped and unprototyped functions; default to prototyped,
17317 since that is more common in modern code (and RealView warns
17318 about unprototyped functions). */
17319 if (producer_is_realview (cu
->producer
))
17325 /* Handle DIES due to C code like:
17329 int (*funcp)(int a, long l);
17333 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17335 static struct type
*
17336 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17338 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17339 struct type
*type
; /* Type that this function returns. */
17340 struct type
*ftype
; /* Function that returns above type. */
17341 struct attribute
*attr
;
17343 type
= die_type (die
, cu
);
17345 /* The die_type call above may have already set the type for this DIE. */
17346 ftype
= get_die_type (die
, cu
);
17350 ftype
= lookup_function_type (type
);
17352 if (prototyped_function_p (die
, cu
))
17353 TYPE_PROTOTYPED (ftype
) = 1;
17355 /* Store the calling convention in the type if it's available in
17356 the subroutine die. Otherwise set the calling convention to
17357 the default value DW_CC_normal. */
17358 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17360 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17361 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17362 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17364 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17366 /* Record whether the function returns normally to its caller or not
17367 if the DWARF producer set that information. */
17368 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17369 if (attr
&& (DW_UNSND (attr
) != 0))
17370 TYPE_NO_RETURN (ftype
) = 1;
17372 /* We need to add the subroutine type to the die immediately so
17373 we don't infinitely recurse when dealing with parameters
17374 declared as the same subroutine type. */
17375 set_die_type (die
, ftype
, cu
);
17377 if (die
->child
!= NULL
)
17379 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17380 struct die_info
*child_die
;
17381 int nparams
, iparams
;
17383 /* Count the number of parameters.
17384 FIXME: GDB currently ignores vararg functions, but knows about
17385 vararg member functions. */
17387 child_die
= die
->child
;
17388 while (child_die
&& child_die
->tag
)
17390 if (child_die
->tag
== DW_TAG_formal_parameter
)
17392 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17393 TYPE_VARARGS (ftype
) = 1;
17394 child_die
= sibling_die (child_die
);
17397 /* Allocate storage for parameters and fill them in. */
17398 TYPE_NFIELDS (ftype
) = nparams
;
17399 TYPE_FIELDS (ftype
) = (struct field
*)
17400 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17402 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17403 even if we error out during the parameters reading below. */
17404 for (iparams
= 0; iparams
< nparams
; iparams
++)
17405 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17408 child_die
= die
->child
;
17409 while (child_die
&& child_die
->tag
)
17411 if (child_die
->tag
== DW_TAG_formal_parameter
)
17413 struct type
*arg_type
;
17415 /* DWARF version 2 has no clean way to discern C++
17416 static and non-static member functions. G++ helps
17417 GDB by marking the first parameter for non-static
17418 member functions (which is the this pointer) as
17419 artificial. We pass this information to
17420 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17422 DWARF version 3 added DW_AT_object_pointer, which GCC
17423 4.5 does not yet generate. */
17424 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17426 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17428 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17429 arg_type
= die_type (child_die
, cu
);
17431 /* RealView does not mark THIS as const, which the testsuite
17432 expects. GCC marks THIS as const in method definitions,
17433 but not in the class specifications (GCC PR 43053). */
17434 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17435 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17438 struct dwarf2_cu
*arg_cu
= cu
;
17439 const char *name
= dwarf2_name (child_die
, cu
);
17441 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17444 /* If the compiler emits this, use it. */
17445 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17448 else if (name
&& strcmp (name
, "this") == 0)
17449 /* Function definitions will have the argument names. */
17451 else if (name
== NULL
&& iparams
== 0)
17452 /* Declarations may not have the names, so like
17453 elsewhere in GDB, assume an artificial first
17454 argument is "this". */
17458 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17462 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17465 child_die
= sibling_die (child_die
);
17472 static struct type
*
17473 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17475 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17476 const char *name
= NULL
;
17477 struct type
*this_type
, *target_type
;
17479 name
= dwarf2_full_name (NULL
, die
, cu
);
17480 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17481 TYPE_TARGET_STUB (this_type
) = 1;
17482 set_die_type (die
, this_type
, cu
);
17483 target_type
= die_type (die
, cu
);
17484 if (target_type
!= this_type
)
17485 TYPE_TARGET_TYPE (this_type
) = target_type
;
17488 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17489 spec and cause infinite loops in GDB. */
17490 complaint (_("Self-referential DW_TAG_typedef "
17491 "- DIE at %s [in module %s]"),
17492 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17493 TYPE_TARGET_TYPE (this_type
) = NULL
;
17498 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17499 (which may be different from NAME) to the architecture back-end to allow
17500 it to guess the correct format if necessary. */
17502 static struct type
*
17503 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17504 const char *name_hint
)
17506 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17507 const struct floatformat
**format
;
17510 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17512 type
= init_float_type (objfile
, bits
, name
, format
);
17514 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17519 /* Allocate an integer type of size BITS and name NAME. */
17521 static struct type
*
17522 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17523 int bits
, int unsigned_p
, const char *name
)
17527 /* Versions of Intel's C Compiler generate an integer type called "void"
17528 instead of using DW_TAG_unspecified_type. This has been seen on
17529 at least versions 14, 17, and 18. */
17530 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17531 && strcmp (name
, "void") == 0)
17532 type
= objfile_type (objfile
)->builtin_void
;
17534 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17539 /* Initialise and return a floating point type of size BITS suitable for
17540 use as a component of a complex number. The NAME_HINT is passed through
17541 when initialising the floating point type and is the name of the complex
17544 As DWARF doesn't currently provide an explicit name for the components
17545 of a complex number, but it can be helpful to have these components
17546 named, we try to select a suitable name based on the size of the
17548 static struct type
*
17549 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17550 struct objfile
*objfile
,
17551 int bits
, const char *name_hint
)
17553 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17554 struct type
*tt
= nullptr;
17559 tt
= builtin_type (gdbarch
)->builtin_float
;
17562 tt
= builtin_type (gdbarch
)->builtin_double
;
17565 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17569 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17570 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
);
17573 /* Find a representation of a given base type and install
17574 it in the TYPE field of the die. */
17576 static struct type
*
17577 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17579 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17581 struct attribute
*attr
;
17582 int encoding
= 0, bits
= 0;
17585 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17588 encoding
= DW_UNSND (attr
);
17590 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17593 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17595 name
= dwarf2_name (die
, cu
);
17598 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17603 case DW_ATE_address
:
17604 /* Turn DW_ATE_address into a void * pointer. */
17605 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17606 type
= init_pointer_type (objfile
, bits
, name
, type
);
17608 case DW_ATE_boolean
:
17609 type
= init_boolean_type (objfile
, bits
, 1, name
);
17611 case DW_ATE_complex_float
:
17612 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
);
17613 type
= init_complex_type (objfile
, name
, type
);
17615 case DW_ATE_decimal_float
:
17616 type
= init_decfloat_type (objfile
, bits
, name
);
17619 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17621 case DW_ATE_signed
:
17622 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17624 case DW_ATE_unsigned
:
17625 if (cu
->language
== language_fortran
17627 && startswith (name
, "character("))
17628 type
= init_character_type (objfile
, bits
, 1, name
);
17630 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17632 case DW_ATE_signed_char
:
17633 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17634 || cu
->language
== language_pascal
17635 || cu
->language
== language_fortran
)
17636 type
= init_character_type (objfile
, bits
, 0, name
);
17638 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17640 case DW_ATE_unsigned_char
:
17641 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17642 || cu
->language
== language_pascal
17643 || cu
->language
== language_fortran
17644 || cu
->language
== language_rust
)
17645 type
= init_character_type (objfile
, bits
, 1, name
);
17647 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17651 gdbarch
*arch
= get_objfile_arch (objfile
);
17654 type
= builtin_type (arch
)->builtin_char16
;
17655 else if (bits
== 32)
17656 type
= builtin_type (arch
)->builtin_char32
;
17659 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17661 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17663 return set_die_type (die
, type
, cu
);
17668 complaint (_("unsupported DW_AT_encoding: '%s'"),
17669 dwarf_type_encoding_name (encoding
));
17670 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17674 if (name
&& strcmp (name
, "char") == 0)
17675 TYPE_NOSIGN (type
) = 1;
17677 maybe_set_alignment (cu
, die
, type
);
17679 return set_die_type (die
, type
, cu
);
17682 /* Parse dwarf attribute if it's a block, reference or constant and put the
17683 resulting value of the attribute into struct bound_prop.
17684 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17687 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17688 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
17690 struct dwarf2_property_baton
*baton
;
17691 struct obstack
*obstack
17692 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17694 if (attr
== NULL
|| prop
== NULL
)
17697 if (attr_form_is_block (attr
))
17699 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17700 baton
->referenced_type
= NULL
;
17701 baton
->locexpr
.per_cu
= cu
->per_cu
;
17702 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17703 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17704 prop
->data
.baton
= baton
;
17705 prop
->kind
= PROP_LOCEXPR
;
17706 gdb_assert (prop
->data
.baton
!= NULL
);
17708 else if (attr_form_is_ref (attr
))
17710 struct dwarf2_cu
*target_cu
= cu
;
17711 struct die_info
*target_die
;
17712 struct attribute
*target_attr
;
17714 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17715 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17716 if (target_attr
== NULL
)
17717 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17719 if (target_attr
== NULL
)
17722 switch (target_attr
->name
)
17724 case DW_AT_location
:
17725 if (attr_form_is_section_offset (target_attr
))
17727 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17728 baton
->referenced_type
= die_type (target_die
, target_cu
);
17729 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17730 prop
->data
.baton
= baton
;
17731 prop
->kind
= PROP_LOCLIST
;
17732 gdb_assert (prop
->data
.baton
!= NULL
);
17734 else if (attr_form_is_block (target_attr
))
17736 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17737 baton
->referenced_type
= die_type (target_die
, target_cu
);
17738 baton
->locexpr
.per_cu
= cu
->per_cu
;
17739 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17740 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17741 prop
->data
.baton
= baton
;
17742 prop
->kind
= PROP_LOCEXPR
;
17743 gdb_assert (prop
->data
.baton
!= NULL
);
17747 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17748 "dynamic property");
17752 case DW_AT_data_member_location
:
17756 if (!handle_data_member_location (target_die
, target_cu
,
17760 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17761 baton
->referenced_type
= read_type_die (target_die
->parent
,
17763 baton
->offset_info
.offset
= offset
;
17764 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17765 prop
->data
.baton
= baton
;
17766 prop
->kind
= PROP_ADDR_OFFSET
;
17771 else if (attr_form_is_constant (attr
))
17773 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17774 prop
->kind
= PROP_CONST
;
17778 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17779 dwarf2_name (die
, cu
));
17786 /* Read the given DW_AT_subrange DIE. */
17788 static struct type
*
17789 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17791 struct type
*base_type
, *orig_base_type
;
17792 struct type
*range_type
;
17793 struct attribute
*attr
;
17794 struct dynamic_prop low
, high
;
17795 int low_default_is_valid
;
17796 int high_bound_is_count
= 0;
17798 ULONGEST negative_mask
;
17800 orig_base_type
= die_type (die
, cu
);
17801 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17802 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17803 creating the range type, but we use the result of check_typedef
17804 when examining properties of the type. */
17805 base_type
= check_typedef (orig_base_type
);
17807 /* The die_type call above may have already set the type for this DIE. */
17808 range_type
= get_die_type (die
, cu
);
17812 low
.kind
= PROP_CONST
;
17813 high
.kind
= PROP_CONST
;
17814 high
.data
.const_val
= 0;
17816 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17817 omitting DW_AT_lower_bound. */
17818 switch (cu
->language
)
17821 case language_cplus
:
17822 low
.data
.const_val
= 0;
17823 low_default_is_valid
= 1;
17825 case language_fortran
:
17826 low
.data
.const_val
= 1;
17827 low_default_is_valid
= 1;
17830 case language_objc
:
17831 case language_rust
:
17832 low
.data
.const_val
= 0;
17833 low_default_is_valid
= (cu
->header
.version
>= 4);
17837 case language_pascal
:
17838 low
.data
.const_val
= 1;
17839 low_default_is_valid
= (cu
->header
.version
>= 4);
17842 low
.data
.const_val
= 0;
17843 low_default_is_valid
= 0;
17847 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17849 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
17850 else if (!low_default_is_valid
)
17851 complaint (_("Missing DW_AT_lower_bound "
17852 "- DIE at %s [in module %s]"),
17853 sect_offset_str (die
->sect_off
),
17854 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17856 struct attribute
*attr_ub
, *attr_count
;
17857 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17858 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17860 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17861 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17863 /* If bounds are constant do the final calculation here. */
17864 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17865 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17867 high_bound_is_count
= 1;
17871 if (attr_ub
!= NULL
)
17872 complaint (_("Unresolved DW_AT_upper_bound "
17873 "- DIE at %s [in module %s]"),
17874 sect_offset_str (die
->sect_off
),
17875 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17876 if (attr_count
!= NULL
)
17877 complaint (_("Unresolved DW_AT_count "
17878 "- DIE at %s [in module %s]"),
17879 sect_offset_str (die
->sect_off
),
17880 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17885 /* Dwarf-2 specifications explicitly allows to create subrange types
17886 without specifying a base type.
17887 In that case, the base type must be set to the type of
17888 the lower bound, upper bound or count, in that order, if any of these
17889 three attributes references an object that has a type.
17890 If no base type is found, the Dwarf-2 specifications say that
17891 a signed integer type of size equal to the size of an address should
17893 For the following C code: `extern char gdb_int [];'
17894 GCC produces an empty range DIE.
17895 FIXME: muller/2010-05-28: Possible references to object for low bound,
17896 high bound or count are not yet handled by this code. */
17897 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
17899 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17900 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17901 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
17902 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
17904 /* Test "int", "long int", and "long long int" objfile types,
17905 and select the first one having a size above or equal to the
17906 architecture address size. */
17907 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17908 base_type
= int_type
;
17911 int_type
= objfile_type (objfile
)->builtin_long
;
17912 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17913 base_type
= int_type
;
17916 int_type
= objfile_type (objfile
)->builtin_long_long
;
17917 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17918 base_type
= int_type
;
17923 /* Normally, the DWARF producers are expected to use a signed
17924 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17925 But this is unfortunately not always the case, as witnessed
17926 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17927 is used instead. To work around that ambiguity, we treat
17928 the bounds as signed, and thus sign-extend their values, when
17929 the base type is signed. */
17931 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17932 if (low
.kind
== PROP_CONST
17933 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17934 low
.data
.const_val
|= negative_mask
;
17935 if (high
.kind
== PROP_CONST
17936 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17937 high
.data
.const_val
|= negative_mask
;
17939 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
17941 if (high_bound_is_count
)
17942 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17944 /* Ada expects an empty array on no boundary attributes. */
17945 if (attr
== NULL
&& cu
->language
!= language_ada
)
17946 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17948 name
= dwarf2_name (die
, cu
);
17950 TYPE_NAME (range_type
) = name
;
17952 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17954 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17956 maybe_set_alignment (cu
, die
, range_type
);
17958 set_die_type (die
, range_type
, cu
);
17960 /* set_die_type should be already done. */
17961 set_descriptive_type (range_type
, die
, cu
);
17966 static struct type
*
17967 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17971 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17973 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17975 /* In Ada, an unspecified type is typically used when the description
17976 of the type is defered to a different unit. When encountering
17977 such a type, we treat it as a stub, and try to resolve it later on,
17979 if (cu
->language
== language_ada
)
17980 TYPE_STUB (type
) = 1;
17982 return set_die_type (die
, type
, cu
);
17985 /* Read a single die and all its descendents. Set the die's sibling
17986 field to NULL; set other fields in the die correctly, and set all
17987 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17988 location of the info_ptr after reading all of those dies. PARENT
17989 is the parent of the die in question. */
17991 static struct die_info
*
17992 read_die_and_children (const struct die_reader_specs
*reader
,
17993 const gdb_byte
*info_ptr
,
17994 const gdb_byte
**new_info_ptr
,
17995 struct die_info
*parent
)
17997 struct die_info
*die
;
17998 const gdb_byte
*cur_ptr
;
18001 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18004 *new_info_ptr
= cur_ptr
;
18007 store_in_ref_table (die
, reader
->cu
);
18010 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18014 *new_info_ptr
= cur_ptr
;
18017 die
->sibling
= NULL
;
18018 die
->parent
= parent
;
18022 /* Read a die, all of its descendents, and all of its siblings; set
18023 all of the fields of all of the dies correctly. Arguments are as
18024 in read_die_and_children. */
18026 static struct die_info
*
18027 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18028 const gdb_byte
*info_ptr
,
18029 const gdb_byte
**new_info_ptr
,
18030 struct die_info
*parent
)
18032 struct die_info
*first_die
, *last_sibling
;
18033 const gdb_byte
*cur_ptr
;
18035 cur_ptr
= info_ptr
;
18036 first_die
= last_sibling
= NULL
;
18040 struct die_info
*die
18041 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18045 *new_info_ptr
= cur_ptr
;
18052 last_sibling
->sibling
= die
;
18054 last_sibling
= die
;
18058 /* Read a die, all of its descendents, and all of its siblings; set
18059 all of the fields of all of the dies correctly. Arguments are as
18060 in read_die_and_children.
18061 This the main entry point for reading a DIE and all its children. */
18063 static struct die_info
*
18064 read_die_and_siblings (const struct die_reader_specs
*reader
,
18065 const gdb_byte
*info_ptr
,
18066 const gdb_byte
**new_info_ptr
,
18067 struct die_info
*parent
)
18069 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18070 new_info_ptr
, parent
);
18072 if (dwarf_die_debug
)
18074 fprintf_unfiltered (gdb_stdlog
,
18075 "Read die from %s@0x%x of %s:\n",
18076 get_section_name (reader
->die_section
),
18077 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18078 bfd_get_filename (reader
->abfd
));
18079 dump_die (die
, dwarf_die_debug
);
18085 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18087 The caller is responsible for filling in the extra attributes
18088 and updating (*DIEP)->num_attrs.
18089 Set DIEP to point to a newly allocated die with its information,
18090 except for its child, sibling, and parent fields.
18091 Set HAS_CHILDREN to tell whether the die has children or not. */
18093 static const gdb_byte
*
18094 read_full_die_1 (const struct die_reader_specs
*reader
,
18095 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18096 int *has_children
, int num_extra_attrs
)
18098 unsigned int abbrev_number
, bytes_read
, i
;
18099 struct abbrev_info
*abbrev
;
18100 struct die_info
*die
;
18101 struct dwarf2_cu
*cu
= reader
->cu
;
18102 bfd
*abfd
= reader
->abfd
;
18104 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18105 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18106 info_ptr
+= bytes_read
;
18107 if (!abbrev_number
)
18114 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18116 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18118 bfd_get_filename (abfd
));
18120 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18121 die
->sect_off
= sect_off
;
18122 die
->tag
= abbrev
->tag
;
18123 die
->abbrev
= abbrev_number
;
18125 /* Make the result usable.
18126 The caller needs to update num_attrs after adding the extra
18128 die
->num_attrs
= abbrev
->num_attrs
;
18130 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18131 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18135 *has_children
= abbrev
->has_children
;
18139 /* Read a die and all its attributes.
18140 Set DIEP to point to a newly allocated die with its information,
18141 except for its child, sibling, and parent fields.
18142 Set HAS_CHILDREN to tell whether the die has children or not. */
18144 static const gdb_byte
*
18145 read_full_die (const struct die_reader_specs
*reader
,
18146 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18149 const gdb_byte
*result
;
18151 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18153 if (dwarf_die_debug
)
18155 fprintf_unfiltered (gdb_stdlog
,
18156 "Read die from %s@0x%x of %s:\n",
18157 get_section_name (reader
->die_section
),
18158 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18159 bfd_get_filename (reader
->abfd
));
18160 dump_die (*diep
, dwarf_die_debug
);
18166 /* Abbreviation tables.
18168 In DWARF version 2, the description of the debugging information is
18169 stored in a separate .debug_abbrev section. Before we read any
18170 dies from a section we read in all abbreviations and install them
18171 in a hash table. */
18173 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18175 struct abbrev_info
*
18176 abbrev_table::alloc_abbrev ()
18178 struct abbrev_info
*abbrev
;
18180 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18181 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18186 /* Add an abbreviation to the table. */
18189 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18190 struct abbrev_info
*abbrev
)
18192 unsigned int hash_number
;
18194 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18195 abbrev
->next
= m_abbrevs
[hash_number
];
18196 m_abbrevs
[hash_number
] = abbrev
;
18199 /* Look up an abbrev in the table.
18200 Returns NULL if the abbrev is not found. */
18202 struct abbrev_info
*
18203 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18205 unsigned int hash_number
;
18206 struct abbrev_info
*abbrev
;
18208 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18209 abbrev
= m_abbrevs
[hash_number
];
18213 if (abbrev
->number
== abbrev_number
)
18215 abbrev
= abbrev
->next
;
18220 /* Read in an abbrev table. */
18222 static abbrev_table_up
18223 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18224 struct dwarf2_section_info
*section
,
18225 sect_offset sect_off
)
18227 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18228 bfd
*abfd
= get_section_bfd_owner (section
);
18229 const gdb_byte
*abbrev_ptr
;
18230 struct abbrev_info
*cur_abbrev
;
18231 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18232 unsigned int abbrev_form
;
18233 struct attr_abbrev
*cur_attrs
;
18234 unsigned int allocated_attrs
;
18236 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18238 dwarf2_read_section (objfile
, section
);
18239 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18240 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18241 abbrev_ptr
+= bytes_read
;
18243 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18244 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18246 /* Loop until we reach an abbrev number of 0. */
18247 while (abbrev_number
)
18249 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18251 /* read in abbrev header */
18252 cur_abbrev
->number
= abbrev_number
;
18254 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18255 abbrev_ptr
+= bytes_read
;
18256 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18259 /* now read in declarations */
18262 LONGEST implicit_const
;
18264 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18265 abbrev_ptr
+= bytes_read
;
18266 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18267 abbrev_ptr
+= bytes_read
;
18268 if (abbrev_form
== DW_FORM_implicit_const
)
18270 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18272 abbrev_ptr
+= bytes_read
;
18276 /* Initialize it due to a false compiler warning. */
18277 implicit_const
= -1;
18280 if (abbrev_name
== 0)
18283 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18285 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18287 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18290 cur_attrs
[cur_abbrev
->num_attrs
].name
18291 = (enum dwarf_attribute
) abbrev_name
;
18292 cur_attrs
[cur_abbrev
->num_attrs
].form
18293 = (enum dwarf_form
) abbrev_form
;
18294 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18295 ++cur_abbrev
->num_attrs
;
18298 cur_abbrev
->attrs
=
18299 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18300 cur_abbrev
->num_attrs
);
18301 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18302 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18304 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18306 /* Get next abbreviation.
18307 Under Irix6 the abbreviations for a compilation unit are not
18308 always properly terminated with an abbrev number of 0.
18309 Exit loop if we encounter an abbreviation which we have
18310 already read (which means we are about to read the abbreviations
18311 for the next compile unit) or if the end of the abbreviation
18312 table is reached. */
18313 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18315 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18316 abbrev_ptr
+= bytes_read
;
18317 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18322 return abbrev_table
;
18325 /* Returns nonzero if TAG represents a type that we might generate a partial
18329 is_type_tag_for_partial (int tag
)
18334 /* Some types that would be reasonable to generate partial symbols for,
18335 that we don't at present. */
18336 case DW_TAG_array_type
:
18337 case DW_TAG_file_type
:
18338 case DW_TAG_ptr_to_member_type
:
18339 case DW_TAG_set_type
:
18340 case DW_TAG_string_type
:
18341 case DW_TAG_subroutine_type
:
18343 case DW_TAG_base_type
:
18344 case DW_TAG_class_type
:
18345 case DW_TAG_interface_type
:
18346 case DW_TAG_enumeration_type
:
18347 case DW_TAG_structure_type
:
18348 case DW_TAG_subrange_type
:
18349 case DW_TAG_typedef
:
18350 case DW_TAG_union_type
:
18357 /* Load all DIEs that are interesting for partial symbols into memory. */
18359 static struct partial_die_info
*
18360 load_partial_dies (const struct die_reader_specs
*reader
,
18361 const gdb_byte
*info_ptr
, int building_psymtab
)
18363 struct dwarf2_cu
*cu
= reader
->cu
;
18364 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18365 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18366 unsigned int bytes_read
;
18367 unsigned int load_all
= 0;
18368 int nesting_level
= 1;
18373 gdb_assert (cu
->per_cu
!= NULL
);
18374 if (cu
->per_cu
->load_all_dies
)
18378 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18382 &cu
->comp_unit_obstack
,
18383 hashtab_obstack_allocate
,
18384 dummy_obstack_deallocate
);
18388 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18390 /* A NULL abbrev means the end of a series of children. */
18391 if (abbrev
== NULL
)
18393 if (--nesting_level
== 0)
18396 info_ptr
+= bytes_read
;
18397 last_die
= parent_die
;
18398 parent_die
= parent_die
->die_parent
;
18402 /* Check for template arguments. We never save these; if
18403 they're seen, we just mark the parent, and go on our way. */
18404 if (parent_die
!= NULL
18405 && cu
->language
== language_cplus
18406 && (abbrev
->tag
== DW_TAG_template_type_param
18407 || abbrev
->tag
== DW_TAG_template_value_param
))
18409 parent_die
->has_template_arguments
= 1;
18413 /* We don't need a partial DIE for the template argument. */
18414 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18419 /* We only recurse into c++ subprograms looking for template arguments.
18420 Skip their other children. */
18422 && cu
->language
== language_cplus
18423 && parent_die
!= NULL
18424 && parent_die
->tag
== DW_TAG_subprogram
)
18426 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18430 /* Check whether this DIE is interesting enough to save. Normally
18431 we would not be interested in members here, but there may be
18432 later variables referencing them via DW_AT_specification (for
18433 static members). */
18435 && !is_type_tag_for_partial (abbrev
->tag
)
18436 && abbrev
->tag
!= DW_TAG_constant
18437 && abbrev
->tag
!= DW_TAG_enumerator
18438 && abbrev
->tag
!= DW_TAG_subprogram
18439 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18440 && abbrev
->tag
!= DW_TAG_lexical_block
18441 && abbrev
->tag
!= DW_TAG_variable
18442 && abbrev
->tag
!= DW_TAG_namespace
18443 && abbrev
->tag
!= DW_TAG_module
18444 && abbrev
->tag
!= DW_TAG_member
18445 && abbrev
->tag
!= DW_TAG_imported_unit
18446 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18448 /* Otherwise we skip to the next sibling, if any. */
18449 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18453 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18456 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18458 /* This two-pass algorithm for processing partial symbols has a
18459 high cost in cache pressure. Thus, handle some simple cases
18460 here which cover the majority of C partial symbols. DIEs
18461 which neither have specification tags in them, nor could have
18462 specification tags elsewhere pointing at them, can simply be
18463 processed and discarded.
18465 This segment is also optional; scan_partial_symbols and
18466 add_partial_symbol will handle these DIEs if we chain
18467 them in normally. When compilers which do not emit large
18468 quantities of duplicate debug information are more common,
18469 this code can probably be removed. */
18471 /* Any complete simple types at the top level (pretty much all
18472 of them, for a language without namespaces), can be processed
18474 if (parent_die
== NULL
18475 && pdi
.has_specification
== 0
18476 && pdi
.is_declaration
== 0
18477 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18478 || pdi
.tag
== DW_TAG_base_type
18479 || pdi
.tag
== DW_TAG_subrange_type
))
18481 if (building_psymtab
&& pdi
.name
!= NULL
)
18482 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18483 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18484 psymbol_placement::STATIC
,
18485 0, cu
->language
, objfile
);
18486 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18490 /* The exception for DW_TAG_typedef with has_children above is
18491 a workaround of GCC PR debug/47510. In the case of this complaint
18492 type_name_or_error will error on such types later.
18494 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18495 it could not find the child DIEs referenced later, this is checked
18496 above. In correct DWARF DW_TAG_typedef should have no children. */
18498 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18499 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18500 "- DIE at %s [in module %s]"),
18501 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18503 /* If we're at the second level, and we're an enumerator, and
18504 our parent has no specification (meaning possibly lives in a
18505 namespace elsewhere), then we can add the partial symbol now
18506 instead of queueing it. */
18507 if (pdi
.tag
== DW_TAG_enumerator
18508 && parent_die
!= NULL
18509 && parent_die
->die_parent
== NULL
18510 && parent_die
->tag
== DW_TAG_enumeration_type
18511 && parent_die
->has_specification
== 0)
18513 if (pdi
.name
== NULL
)
18514 complaint (_("malformed enumerator DIE ignored"));
18515 else if (building_psymtab
)
18516 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18517 VAR_DOMAIN
, LOC_CONST
, -1,
18518 cu
->language
== language_cplus
18519 ? psymbol_placement::GLOBAL
18520 : psymbol_placement::STATIC
,
18521 0, cu
->language
, objfile
);
18523 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18527 struct partial_die_info
*part_die
18528 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18530 /* We'll save this DIE so link it in. */
18531 part_die
->die_parent
= parent_die
;
18532 part_die
->die_sibling
= NULL
;
18533 part_die
->die_child
= NULL
;
18535 if (last_die
&& last_die
== parent_die
)
18536 last_die
->die_child
= part_die
;
18538 last_die
->die_sibling
= part_die
;
18540 last_die
= part_die
;
18542 if (first_die
== NULL
)
18543 first_die
= part_die
;
18545 /* Maybe add the DIE to the hash table. Not all DIEs that we
18546 find interesting need to be in the hash table, because we
18547 also have the parent/sibling/child chains; only those that we
18548 might refer to by offset later during partial symbol reading.
18550 For now this means things that might have be the target of a
18551 DW_AT_specification, DW_AT_abstract_origin, or
18552 DW_AT_extension. DW_AT_extension will refer only to
18553 namespaces; DW_AT_abstract_origin refers to functions (and
18554 many things under the function DIE, but we do not recurse
18555 into function DIEs during partial symbol reading) and
18556 possibly variables as well; DW_AT_specification refers to
18557 declarations. Declarations ought to have the DW_AT_declaration
18558 flag. It happens that GCC forgets to put it in sometimes, but
18559 only for functions, not for types.
18561 Adding more things than necessary to the hash table is harmless
18562 except for the performance cost. Adding too few will result in
18563 wasted time in find_partial_die, when we reread the compilation
18564 unit with load_all_dies set. */
18567 || abbrev
->tag
== DW_TAG_constant
18568 || abbrev
->tag
== DW_TAG_subprogram
18569 || abbrev
->tag
== DW_TAG_variable
18570 || abbrev
->tag
== DW_TAG_namespace
18571 || part_die
->is_declaration
)
18575 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18576 to_underlying (part_die
->sect_off
),
18581 /* For some DIEs we want to follow their children (if any). For C
18582 we have no reason to follow the children of structures; for other
18583 languages we have to, so that we can get at method physnames
18584 to infer fully qualified class names, for DW_AT_specification,
18585 and for C++ template arguments. For C++, we also look one level
18586 inside functions to find template arguments (if the name of the
18587 function does not already contain the template arguments).
18589 For Ada, we need to scan the children of subprograms and lexical
18590 blocks as well because Ada allows the definition of nested
18591 entities that could be interesting for the debugger, such as
18592 nested subprograms for instance. */
18593 if (last_die
->has_children
18595 || last_die
->tag
== DW_TAG_namespace
18596 || last_die
->tag
== DW_TAG_module
18597 || last_die
->tag
== DW_TAG_enumeration_type
18598 || (cu
->language
== language_cplus
18599 && last_die
->tag
== DW_TAG_subprogram
18600 && (last_die
->name
== NULL
18601 || strchr (last_die
->name
, '<') == NULL
))
18602 || (cu
->language
!= language_c
18603 && (last_die
->tag
== DW_TAG_class_type
18604 || last_die
->tag
== DW_TAG_interface_type
18605 || last_die
->tag
== DW_TAG_structure_type
18606 || last_die
->tag
== DW_TAG_union_type
))
18607 || (cu
->language
== language_ada
18608 && (last_die
->tag
== DW_TAG_subprogram
18609 || last_die
->tag
== DW_TAG_lexical_block
))))
18612 parent_die
= last_die
;
18616 /* Otherwise we skip to the next sibling, if any. */
18617 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18619 /* Back to the top, do it again. */
18623 partial_die_info::partial_die_info (sect_offset sect_off_
,
18624 struct abbrev_info
*abbrev
)
18625 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18629 /* Read a minimal amount of information into the minimal die structure.
18630 INFO_PTR should point just after the initial uleb128 of a DIE. */
18633 partial_die_info::read (const struct die_reader_specs
*reader
,
18634 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18636 struct dwarf2_cu
*cu
= reader
->cu
;
18637 struct dwarf2_per_objfile
*dwarf2_per_objfile
18638 = cu
->per_cu
->dwarf2_per_objfile
;
18640 int has_low_pc_attr
= 0;
18641 int has_high_pc_attr
= 0;
18642 int high_pc_relative
= 0;
18644 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18646 struct attribute attr
;
18648 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18650 /* Store the data if it is of an attribute we want to keep in a
18651 partial symbol table. */
18657 case DW_TAG_compile_unit
:
18658 case DW_TAG_partial_unit
:
18659 case DW_TAG_type_unit
:
18660 /* Compilation units have a DW_AT_name that is a filename, not
18661 a source language identifier. */
18662 case DW_TAG_enumeration_type
:
18663 case DW_TAG_enumerator
:
18664 /* These tags always have simple identifiers already; no need
18665 to canonicalize them. */
18666 name
= DW_STRING (&attr
);
18670 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18673 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18674 &objfile
->per_bfd
->storage_obstack
);
18679 case DW_AT_linkage_name
:
18680 case DW_AT_MIPS_linkage_name
:
18681 /* Note that both forms of linkage name might appear. We
18682 assume they will be the same, and we only store the last
18684 if (cu
->language
== language_ada
)
18685 name
= DW_STRING (&attr
);
18686 linkage_name
= DW_STRING (&attr
);
18689 has_low_pc_attr
= 1;
18690 lowpc
= attr_value_as_address (&attr
);
18692 case DW_AT_high_pc
:
18693 has_high_pc_attr
= 1;
18694 highpc
= attr_value_as_address (&attr
);
18695 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18696 high_pc_relative
= 1;
18698 case DW_AT_location
:
18699 /* Support the .debug_loc offsets. */
18700 if (attr_form_is_block (&attr
))
18702 d
.locdesc
= DW_BLOCK (&attr
);
18704 else if (attr_form_is_section_offset (&attr
))
18706 dwarf2_complex_location_expr_complaint ();
18710 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18711 "partial symbol information");
18714 case DW_AT_external
:
18715 is_external
= DW_UNSND (&attr
);
18717 case DW_AT_declaration
:
18718 is_declaration
= DW_UNSND (&attr
);
18723 case DW_AT_abstract_origin
:
18724 case DW_AT_specification
:
18725 case DW_AT_extension
:
18726 has_specification
= 1;
18727 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18728 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18729 || cu
->per_cu
->is_dwz
);
18731 case DW_AT_sibling
:
18732 /* Ignore absolute siblings, they might point outside of
18733 the current compile unit. */
18734 if (attr
.form
== DW_FORM_ref_addr
)
18735 complaint (_("ignoring absolute DW_AT_sibling"));
18738 const gdb_byte
*buffer
= reader
->buffer
;
18739 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18740 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18742 if (sibling_ptr
< info_ptr
)
18743 complaint (_("DW_AT_sibling points backwards"));
18744 else if (sibling_ptr
> reader
->buffer_end
)
18745 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18747 sibling
= sibling_ptr
;
18750 case DW_AT_byte_size
:
18753 case DW_AT_const_value
:
18754 has_const_value
= 1;
18756 case DW_AT_calling_convention
:
18757 /* DWARF doesn't provide a way to identify a program's source-level
18758 entry point. DW_AT_calling_convention attributes are only meant
18759 to describe functions' calling conventions.
18761 However, because it's a necessary piece of information in
18762 Fortran, and before DWARF 4 DW_CC_program was the only
18763 piece of debugging information whose definition refers to
18764 a 'main program' at all, several compilers marked Fortran
18765 main programs with DW_CC_program --- even when those
18766 functions use the standard calling conventions.
18768 Although DWARF now specifies a way to provide this
18769 information, we support this practice for backward
18771 if (DW_UNSND (&attr
) == DW_CC_program
18772 && cu
->language
== language_fortran
)
18773 main_subprogram
= 1;
18776 if (DW_UNSND (&attr
) == DW_INL_inlined
18777 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18778 may_be_inlined
= 1;
18782 if (tag
== DW_TAG_imported_unit
)
18784 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18785 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18786 || cu
->per_cu
->is_dwz
);
18790 case DW_AT_main_subprogram
:
18791 main_subprogram
= DW_UNSND (&attr
);
18796 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18797 but that requires a full DIE, so instead we just
18799 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18800 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18801 + (need_ranges_base
18805 /* Value of the DW_AT_ranges attribute is the offset in the
18806 .debug_ranges section. */
18807 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18818 if (high_pc_relative
)
18821 if (has_low_pc_attr
&& has_high_pc_attr
)
18823 /* When using the GNU linker, .gnu.linkonce. sections are used to
18824 eliminate duplicate copies of functions and vtables and such.
18825 The linker will arbitrarily choose one and discard the others.
18826 The AT_*_pc values for such functions refer to local labels in
18827 these sections. If the section from that file was discarded, the
18828 labels are not in the output, so the relocs get a value of 0.
18829 If this is a discarded function, mark the pc bounds as invalid,
18830 so that GDB will ignore it. */
18831 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18833 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18834 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18836 complaint (_("DW_AT_low_pc %s is zero "
18837 "for DIE at %s [in module %s]"),
18838 paddress (gdbarch
, lowpc
),
18839 sect_offset_str (sect_off
),
18840 objfile_name (objfile
));
18842 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18843 else if (lowpc
>= highpc
)
18845 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18846 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18848 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18849 "for DIE at %s [in module %s]"),
18850 paddress (gdbarch
, lowpc
),
18851 paddress (gdbarch
, highpc
),
18852 sect_offset_str (sect_off
),
18853 objfile_name (objfile
));
18862 /* Find a cached partial DIE at OFFSET in CU. */
18864 struct partial_die_info
*
18865 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18867 struct partial_die_info
*lookup_die
= NULL
;
18868 struct partial_die_info
part_die (sect_off
);
18870 lookup_die
= ((struct partial_die_info
*)
18871 htab_find_with_hash (partial_dies
, &part_die
,
18872 to_underlying (sect_off
)));
18877 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18878 except in the case of .debug_types DIEs which do not reference
18879 outside their CU (they do however referencing other types via
18880 DW_FORM_ref_sig8). */
18882 static struct partial_die_info
*
18883 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18885 struct dwarf2_per_objfile
*dwarf2_per_objfile
18886 = cu
->per_cu
->dwarf2_per_objfile
;
18887 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18888 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18889 struct partial_die_info
*pd
= NULL
;
18891 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18892 && offset_in_cu_p (&cu
->header
, sect_off
))
18894 pd
= cu
->find_partial_die (sect_off
);
18897 /* We missed recording what we needed.
18898 Load all dies and try again. */
18899 per_cu
= cu
->per_cu
;
18903 /* TUs don't reference other CUs/TUs (except via type signatures). */
18904 if (cu
->per_cu
->is_debug_types
)
18906 error (_("Dwarf Error: Type Unit at offset %s contains"
18907 " external reference to offset %s [in module %s].\n"),
18908 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18909 bfd_get_filename (objfile
->obfd
));
18911 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18912 dwarf2_per_objfile
);
18914 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18915 load_partial_comp_unit (per_cu
);
18917 per_cu
->cu
->last_used
= 0;
18918 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18921 /* If we didn't find it, and not all dies have been loaded,
18922 load them all and try again. */
18924 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18926 per_cu
->load_all_dies
= 1;
18928 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18929 THIS_CU->cu may already be in use. So we can't just free it and
18930 replace its DIEs with the ones we read in. Instead, we leave those
18931 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18932 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18934 load_partial_comp_unit (per_cu
);
18936 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18940 internal_error (__FILE__
, __LINE__
,
18941 _("could not find partial DIE %s "
18942 "in cache [from module %s]\n"),
18943 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18947 /* See if we can figure out if the class lives in a namespace. We do
18948 this by looking for a member function; its demangled name will
18949 contain namespace info, if there is any. */
18952 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18953 struct dwarf2_cu
*cu
)
18955 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18956 what template types look like, because the demangler
18957 frequently doesn't give the same name as the debug info. We
18958 could fix this by only using the demangled name to get the
18959 prefix (but see comment in read_structure_type). */
18961 struct partial_die_info
*real_pdi
;
18962 struct partial_die_info
*child_pdi
;
18964 /* If this DIE (this DIE's specification, if any) has a parent, then
18965 we should not do this. We'll prepend the parent's fully qualified
18966 name when we create the partial symbol. */
18968 real_pdi
= struct_pdi
;
18969 while (real_pdi
->has_specification
)
18970 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
18971 real_pdi
->spec_is_dwz
, cu
);
18973 if (real_pdi
->die_parent
!= NULL
)
18976 for (child_pdi
= struct_pdi
->die_child
;
18978 child_pdi
= child_pdi
->die_sibling
)
18980 if (child_pdi
->tag
== DW_TAG_subprogram
18981 && child_pdi
->linkage_name
!= NULL
)
18983 char *actual_class_name
18984 = language_class_name_from_physname (cu
->language_defn
,
18985 child_pdi
->linkage_name
);
18986 if (actual_class_name
!= NULL
)
18988 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18991 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18993 strlen (actual_class_name
)));
18994 xfree (actual_class_name
);
19002 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19004 /* Once we've fixed up a die, there's no point in doing so again.
19005 This also avoids a memory leak if we were to call
19006 guess_partial_die_structure_name multiple times. */
19010 /* If we found a reference attribute and the DIE has no name, try
19011 to find a name in the referred to DIE. */
19013 if (name
== NULL
&& has_specification
)
19015 struct partial_die_info
*spec_die
;
19017 spec_die
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19019 spec_die
->fixup (cu
);
19021 if (spec_die
->name
)
19023 name
= spec_die
->name
;
19025 /* Copy DW_AT_external attribute if it is set. */
19026 if (spec_die
->is_external
)
19027 is_external
= spec_die
->is_external
;
19031 /* Set default names for some unnamed DIEs. */
19033 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19034 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19036 /* If there is no parent die to provide a namespace, and there are
19037 children, see if we can determine the namespace from their linkage
19039 if (cu
->language
== language_cplus
19040 && !VEC_empty (dwarf2_section_info_def
,
19041 cu
->per_cu
->dwarf2_per_objfile
->types
)
19042 && die_parent
== NULL
19044 && (tag
== DW_TAG_class_type
19045 || tag
== DW_TAG_structure_type
19046 || tag
== DW_TAG_union_type
))
19047 guess_partial_die_structure_name (this, cu
);
19049 /* GCC might emit a nameless struct or union that has a linkage
19050 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19052 && (tag
== DW_TAG_class_type
19053 || tag
== DW_TAG_interface_type
19054 || tag
== DW_TAG_structure_type
19055 || tag
== DW_TAG_union_type
)
19056 && linkage_name
!= NULL
)
19060 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
19065 /* Strip any leading namespaces/classes, keep only the base name.
19066 DW_AT_name for named DIEs does not contain the prefixes. */
19067 base
= strrchr (demangled
, ':');
19068 if (base
&& base
> demangled
&& base
[-1] == ':')
19073 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19076 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
19077 base
, strlen (base
)));
19085 /* Read an attribute value described by an attribute form. */
19087 static const gdb_byte
*
19088 read_attribute_value (const struct die_reader_specs
*reader
,
19089 struct attribute
*attr
, unsigned form
,
19090 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19092 struct dwarf2_cu
*cu
= reader
->cu
;
19093 struct dwarf2_per_objfile
*dwarf2_per_objfile
19094 = cu
->per_cu
->dwarf2_per_objfile
;
19095 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19096 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19097 bfd
*abfd
= reader
->abfd
;
19098 struct comp_unit_head
*cu_header
= &cu
->header
;
19099 unsigned int bytes_read
;
19100 struct dwarf_block
*blk
;
19102 attr
->form
= (enum dwarf_form
) form
;
19105 case DW_FORM_ref_addr
:
19106 if (cu
->header
.version
== 2)
19107 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19109 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19110 &cu
->header
, &bytes_read
);
19111 info_ptr
+= bytes_read
;
19113 case DW_FORM_GNU_ref_alt
:
19114 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19115 info_ptr
+= bytes_read
;
19118 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19119 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19120 info_ptr
+= bytes_read
;
19122 case DW_FORM_block2
:
19123 blk
= dwarf_alloc_block (cu
);
19124 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19126 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19127 info_ptr
+= blk
->size
;
19128 DW_BLOCK (attr
) = blk
;
19130 case DW_FORM_block4
:
19131 blk
= dwarf_alloc_block (cu
);
19132 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19134 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19135 info_ptr
+= blk
->size
;
19136 DW_BLOCK (attr
) = blk
;
19138 case DW_FORM_data2
:
19139 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19142 case DW_FORM_data4
:
19143 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19146 case DW_FORM_data8
:
19147 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19150 case DW_FORM_data16
:
19151 blk
= dwarf_alloc_block (cu
);
19153 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19155 DW_BLOCK (attr
) = blk
;
19157 case DW_FORM_sec_offset
:
19158 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19159 info_ptr
+= bytes_read
;
19161 case DW_FORM_string
:
19162 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19163 DW_STRING_IS_CANONICAL (attr
) = 0;
19164 info_ptr
+= bytes_read
;
19167 if (!cu
->per_cu
->is_dwz
)
19169 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19170 abfd
, info_ptr
, cu_header
,
19172 DW_STRING_IS_CANONICAL (attr
) = 0;
19173 info_ptr
+= bytes_read
;
19177 case DW_FORM_line_strp
:
19178 if (!cu
->per_cu
->is_dwz
)
19180 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19182 cu_header
, &bytes_read
);
19183 DW_STRING_IS_CANONICAL (attr
) = 0;
19184 info_ptr
+= bytes_read
;
19188 case DW_FORM_GNU_strp_alt
:
19190 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19191 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19194 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19196 DW_STRING_IS_CANONICAL (attr
) = 0;
19197 info_ptr
+= bytes_read
;
19200 case DW_FORM_exprloc
:
19201 case DW_FORM_block
:
19202 blk
= dwarf_alloc_block (cu
);
19203 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19204 info_ptr
+= bytes_read
;
19205 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19206 info_ptr
+= blk
->size
;
19207 DW_BLOCK (attr
) = blk
;
19209 case DW_FORM_block1
:
19210 blk
= dwarf_alloc_block (cu
);
19211 blk
->size
= read_1_byte (abfd
, info_ptr
);
19213 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19214 info_ptr
+= blk
->size
;
19215 DW_BLOCK (attr
) = blk
;
19217 case DW_FORM_data1
:
19218 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19222 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19225 case DW_FORM_flag_present
:
19226 DW_UNSND (attr
) = 1;
19228 case DW_FORM_sdata
:
19229 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19230 info_ptr
+= bytes_read
;
19232 case DW_FORM_udata
:
19233 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19234 info_ptr
+= bytes_read
;
19237 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19238 + read_1_byte (abfd
, info_ptr
));
19242 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19243 + read_2_bytes (abfd
, info_ptr
));
19247 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19248 + read_4_bytes (abfd
, info_ptr
));
19252 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19253 + read_8_bytes (abfd
, info_ptr
));
19256 case DW_FORM_ref_sig8
:
19257 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19260 case DW_FORM_ref_udata
:
19261 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19262 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19263 info_ptr
+= bytes_read
;
19265 case DW_FORM_indirect
:
19266 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19267 info_ptr
+= bytes_read
;
19268 if (form
== DW_FORM_implicit_const
)
19270 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19271 info_ptr
+= bytes_read
;
19273 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19276 case DW_FORM_implicit_const
:
19277 DW_SND (attr
) = implicit_const
;
19279 case DW_FORM_GNU_addr_index
:
19280 if (reader
->dwo_file
== NULL
)
19282 /* For now flag a hard error.
19283 Later we can turn this into a complaint. */
19284 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19285 dwarf_form_name (form
),
19286 bfd_get_filename (abfd
));
19288 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19289 info_ptr
+= bytes_read
;
19291 case DW_FORM_GNU_str_index
:
19292 if (reader
->dwo_file
== NULL
)
19294 /* For now flag a hard error.
19295 Later we can turn this into a complaint if warranted. */
19296 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19297 dwarf_form_name (form
),
19298 bfd_get_filename (abfd
));
19301 ULONGEST str_index
=
19302 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19304 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19305 DW_STRING_IS_CANONICAL (attr
) = 0;
19306 info_ptr
+= bytes_read
;
19310 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19311 dwarf_form_name (form
),
19312 bfd_get_filename (abfd
));
19316 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19317 attr
->form
= DW_FORM_GNU_ref_alt
;
19319 /* We have seen instances where the compiler tried to emit a byte
19320 size attribute of -1 which ended up being encoded as an unsigned
19321 0xffffffff. Although 0xffffffff is technically a valid size value,
19322 an object of this size seems pretty unlikely so we can relatively
19323 safely treat these cases as if the size attribute was invalid and
19324 treat them as zero by default. */
19325 if (attr
->name
== DW_AT_byte_size
19326 && form
== DW_FORM_data4
19327 && DW_UNSND (attr
) >= 0xffffffff)
19330 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19331 hex_string (DW_UNSND (attr
)));
19332 DW_UNSND (attr
) = 0;
19338 /* Read an attribute described by an abbreviated attribute. */
19340 static const gdb_byte
*
19341 read_attribute (const struct die_reader_specs
*reader
,
19342 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19343 const gdb_byte
*info_ptr
)
19345 attr
->name
= abbrev
->name
;
19346 return read_attribute_value (reader
, attr
, abbrev
->form
,
19347 abbrev
->implicit_const
, info_ptr
);
19350 /* Read dwarf information from a buffer. */
19352 static unsigned int
19353 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19355 return bfd_get_8 (abfd
, buf
);
19359 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19361 return bfd_get_signed_8 (abfd
, buf
);
19364 static unsigned int
19365 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19367 return bfd_get_16 (abfd
, buf
);
19371 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19373 return bfd_get_signed_16 (abfd
, buf
);
19376 static unsigned int
19377 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19379 return bfd_get_32 (abfd
, buf
);
19383 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19385 return bfd_get_signed_32 (abfd
, buf
);
19389 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19391 return bfd_get_64 (abfd
, buf
);
19395 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19396 unsigned int *bytes_read
)
19398 struct comp_unit_head
*cu_header
= &cu
->header
;
19399 CORE_ADDR retval
= 0;
19401 if (cu_header
->signed_addr_p
)
19403 switch (cu_header
->addr_size
)
19406 retval
= bfd_get_signed_16 (abfd
, buf
);
19409 retval
= bfd_get_signed_32 (abfd
, buf
);
19412 retval
= bfd_get_signed_64 (abfd
, buf
);
19415 internal_error (__FILE__
, __LINE__
,
19416 _("read_address: bad switch, signed [in module %s]"),
19417 bfd_get_filename (abfd
));
19422 switch (cu_header
->addr_size
)
19425 retval
= bfd_get_16 (abfd
, buf
);
19428 retval
= bfd_get_32 (abfd
, buf
);
19431 retval
= bfd_get_64 (abfd
, buf
);
19434 internal_error (__FILE__
, __LINE__
,
19435 _("read_address: bad switch, "
19436 "unsigned [in module %s]"),
19437 bfd_get_filename (abfd
));
19441 *bytes_read
= cu_header
->addr_size
;
19445 /* Read the initial length from a section. The (draft) DWARF 3
19446 specification allows the initial length to take up either 4 bytes
19447 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19448 bytes describe the length and all offsets will be 8 bytes in length
19451 An older, non-standard 64-bit format is also handled by this
19452 function. The older format in question stores the initial length
19453 as an 8-byte quantity without an escape value. Lengths greater
19454 than 2^32 aren't very common which means that the initial 4 bytes
19455 is almost always zero. Since a length value of zero doesn't make
19456 sense for the 32-bit format, this initial zero can be considered to
19457 be an escape value which indicates the presence of the older 64-bit
19458 format. As written, the code can't detect (old format) lengths
19459 greater than 4GB. If it becomes necessary to handle lengths
19460 somewhat larger than 4GB, we could allow other small values (such
19461 as the non-sensical values of 1, 2, and 3) to also be used as
19462 escape values indicating the presence of the old format.
19464 The value returned via bytes_read should be used to increment the
19465 relevant pointer after calling read_initial_length().
19467 [ Note: read_initial_length() and read_offset() are based on the
19468 document entitled "DWARF Debugging Information Format", revision
19469 3, draft 8, dated November 19, 2001. This document was obtained
19472 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19474 This document is only a draft and is subject to change. (So beware.)
19476 Details regarding the older, non-standard 64-bit format were
19477 determined empirically by examining 64-bit ELF files produced by
19478 the SGI toolchain on an IRIX 6.5 machine.
19480 - Kevin, July 16, 2002
19484 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19486 LONGEST length
= bfd_get_32 (abfd
, buf
);
19488 if (length
== 0xffffffff)
19490 length
= bfd_get_64 (abfd
, buf
+ 4);
19493 else if (length
== 0)
19495 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19496 length
= bfd_get_64 (abfd
, buf
);
19507 /* Cover function for read_initial_length.
19508 Returns the length of the object at BUF, and stores the size of the
19509 initial length in *BYTES_READ and stores the size that offsets will be in
19511 If the initial length size is not equivalent to that specified in
19512 CU_HEADER then issue a complaint.
19513 This is useful when reading non-comp-unit headers. */
19516 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19517 const struct comp_unit_head
*cu_header
,
19518 unsigned int *bytes_read
,
19519 unsigned int *offset_size
)
19521 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19523 gdb_assert (cu_header
->initial_length_size
== 4
19524 || cu_header
->initial_length_size
== 8
19525 || cu_header
->initial_length_size
== 12);
19527 if (cu_header
->initial_length_size
!= *bytes_read
)
19528 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19530 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19534 /* Read an offset from the data stream. The size of the offset is
19535 given by cu_header->offset_size. */
19538 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19539 const struct comp_unit_head
*cu_header
,
19540 unsigned int *bytes_read
)
19542 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19544 *bytes_read
= cu_header
->offset_size
;
19548 /* Read an offset from the data stream. */
19551 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19553 LONGEST retval
= 0;
19555 switch (offset_size
)
19558 retval
= bfd_get_32 (abfd
, buf
);
19561 retval
= bfd_get_64 (abfd
, buf
);
19564 internal_error (__FILE__
, __LINE__
,
19565 _("read_offset_1: bad switch [in module %s]"),
19566 bfd_get_filename (abfd
));
19572 static const gdb_byte
*
19573 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19575 /* If the size of a host char is 8 bits, we can return a pointer
19576 to the buffer, otherwise we have to copy the data to a buffer
19577 allocated on the temporary obstack. */
19578 gdb_assert (HOST_CHAR_BIT
== 8);
19582 static const char *
19583 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19584 unsigned int *bytes_read_ptr
)
19586 /* If the size of a host char is 8 bits, we can return a pointer
19587 to the string, otherwise we have to copy the string to a buffer
19588 allocated on the temporary obstack. */
19589 gdb_assert (HOST_CHAR_BIT
== 8);
19592 *bytes_read_ptr
= 1;
19595 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19596 return (const char *) buf
;
19599 /* Return pointer to string at section SECT offset STR_OFFSET with error
19600 reporting strings FORM_NAME and SECT_NAME. */
19602 static const char *
19603 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19604 bfd
*abfd
, LONGEST str_offset
,
19605 struct dwarf2_section_info
*sect
,
19606 const char *form_name
,
19607 const char *sect_name
)
19609 dwarf2_read_section (objfile
, sect
);
19610 if (sect
->buffer
== NULL
)
19611 error (_("%s used without %s section [in module %s]"),
19612 form_name
, sect_name
, bfd_get_filename (abfd
));
19613 if (str_offset
>= sect
->size
)
19614 error (_("%s pointing outside of %s section [in module %s]"),
19615 form_name
, sect_name
, bfd_get_filename (abfd
));
19616 gdb_assert (HOST_CHAR_BIT
== 8);
19617 if (sect
->buffer
[str_offset
] == '\0')
19619 return (const char *) (sect
->buffer
+ str_offset
);
19622 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19624 static const char *
19625 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19626 bfd
*abfd
, LONGEST str_offset
)
19628 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19630 &dwarf2_per_objfile
->str
,
19631 "DW_FORM_strp", ".debug_str");
19634 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19636 static const char *
19637 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19638 bfd
*abfd
, LONGEST str_offset
)
19640 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19642 &dwarf2_per_objfile
->line_str
,
19643 "DW_FORM_line_strp",
19644 ".debug_line_str");
19647 /* Read a string at offset STR_OFFSET in the .debug_str section from
19648 the .dwz file DWZ. Throw an error if the offset is too large. If
19649 the string consists of a single NUL byte, return NULL; otherwise
19650 return a pointer to the string. */
19652 static const char *
19653 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19654 LONGEST str_offset
)
19656 dwarf2_read_section (objfile
, &dwz
->str
);
19658 if (dwz
->str
.buffer
== NULL
)
19659 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19660 "section [in module %s]"),
19661 bfd_get_filename (dwz
->dwz_bfd
));
19662 if (str_offset
>= dwz
->str
.size
)
19663 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19664 ".debug_str section [in module %s]"),
19665 bfd_get_filename (dwz
->dwz_bfd
));
19666 gdb_assert (HOST_CHAR_BIT
== 8);
19667 if (dwz
->str
.buffer
[str_offset
] == '\0')
19669 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19672 /* Return pointer to string at .debug_str offset as read from BUF.
19673 BUF is assumed to be in a compilation unit described by CU_HEADER.
19674 Return *BYTES_READ_PTR count of bytes read from BUF. */
19676 static const char *
19677 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19678 const gdb_byte
*buf
,
19679 const struct comp_unit_head
*cu_header
,
19680 unsigned int *bytes_read_ptr
)
19682 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19684 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19687 /* Return pointer to string at .debug_line_str offset as read from BUF.
19688 BUF is assumed to be in a compilation unit described by CU_HEADER.
19689 Return *BYTES_READ_PTR count of bytes read from BUF. */
19691 static const char *
19692 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19693 bfd
*abfd
, const gdb_byte
*buf
,
19694 const struct comp_unit_head
*cu_header
,
19695 unsigned int *bytes_read_ptr
)
19697 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19699 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19704 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19705 unsigned int *bytes_read_ptr
)
19708 unsigned int num_read
;
19710 unsigned char byte
;
19717 byte
= bfd_get_8 (abfd
, buf
);
19720 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19721 if ((byte
& 128) == 0)
19727 *bytes_read_ptr
= num_read
;
19732 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19733 unsigned int *bytes_read_ptr
)
19736 int shift
, num_read
;
19737 unsigned char byte
;
19744 byte
= bfd_get_8 (abfd
, buf
);
19747 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19749 if ((byte
& 128) == 0)
19754 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19755 result
|= -(((ULONGEST
) 1) << shift
);
19756 *bytes_read_ptr
= num_read
;
19760 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19761 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
19762 ADDR_SIZE is the size of addresses from the CU header. */
19765 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19766 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
19768 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19769 bfd
*abfd
= objfile
->obfd
;
19770 const gdb_byte
*info_ptr
;
19772 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
19773 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19774 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19775 objfile_name (objfile
));
19776 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
19777 error (_("DW_FORM_addr_index pointing outside of "
19778 ".debug_addr section [in module %s]"),
19779 objfile_name (objfile
));
19780 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19781 + addr_base
+ addr_index
* addr_size
);
19782 if (addr_size
== 4)
19783 return bfd_get_32 (abfd
, info_ptr
);
19785 return bfd_get_64 (abfd
, info_ptr
);
19788 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19791 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19793 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19794 cu
->addr_base
, cu
->header
.addr_size
);
19797 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19800 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19801 unsigned int *bytes_read
)
19803 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19804 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19806 return read_addr_index (cu
, addr_index
);
19809 /* Data structure to pass results from dwarf2_read_addr_index_reader
19810 back to dwarf2_read_addr_index. */
19812 struct dwarf2_read_addr_index_data
19814 ULONGEST addr_base
;
19818 /* die_reader_func for dwarf2_read_addr_index. */
19821 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
19822 const gdb_byte
*info_ptr
,
19823 struct die_info
*comp_unit_die
,
19827 struct dwarf2_cu
*cu
= reader
->cu
;
19828 struct dwarf2_read_addr_index_data
*aidata
=
19829 (struct dwarf2_read_addr_index_data
*) data
;
19831 aidata
->addr_base
= cu
->addr_base
;
19832 aidata
->addr_size
= cu
->header
.addr_size
;
19835 /* Given an index in .debug_addr, fetch the value.
19836 NOTE: This can be called during dwarf expression evaluation,
19837 long after the debug information has been read, and thus per_cu->cu
19838 may no longer exist. */
19841 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19842 unsigned int addr_index
)
19844 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19845 struct dwarf2_cu
*cu
= per_cu
->cu
;
19846 ULONGEST addr_base
;
19849 /* We need addr_base and addr_size.
19850 If we don't have PER_CU->cu, we have to get it.
19851 Nasty, but the alternative is storing the needed info in PER_CU,
19852 which at this point doesn't seem justified: it's not clear how frequently
19853 it would get used and it would increase the size of every PER_CU.
19854 Entry points like dwarf2_per_cu_addr_size do a similar thing
19855 so we're not in uncharted territory here.
19856 Alas we need to be a bit more complicated as addr_base is contained
19859 We don't need to read the entire CU(/TU).
19860 We just need the header and top level die.
19862 IWBN to use the aging mechanism to let us lazily later discard the CU.
19863 For now we skip this optimization. */
19867 addr_base
= cu
->addr_base
;
19868 addr_size
= cu
->header
.addr_size
;
19872 struct dwarf2_read_addr_index_data aidata
;
19874 /* Note: We can't use init_cutu_and_read_dies_simple here,
19875 we need addr_base. */
19876 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0, false,
19877 dwarf2_read_addr_index_reader
, &aidata
);
19878 addr_base
= aidata
.addr_base
;
19879 addr_size
= aidata
.addr_size
;
19882 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19886 /* Given a DW_FORM_GNU_str_index, fetch the string.
19887 This is only used by the Fission support. */
19889 static const char *
19890 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19892 struct dwarf2_cu
*cu
= reader
->cu
;
19893 struct dwarf2_per_objfile
*dwarf2_per_objfile
19894 = cu
->per_cu
->dwarf2_per_objfile
;
19895 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19896 const char *objf_name
= objfile_name (objfile
);
19897 bfd
*abfd
= objfile
->obfd
;
19898 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
19899 struct dwarf2_section_info
*str_offsets_section
=
19900 &reader
->dwo_file
->sections
.str_offsets
;
19901 const gdb_byte
*info_ptr
;
19902 ULONGEST str_offset
;
19903 static const char form_name
[] = "DW_FORM_GNU_str_index";
19905 dwarf2_read_section (objfile
, str_section
);
19906 dwarf2_read_section (objfile
, str_offsets_section
);
19907 if (str_section
->buffer
== NULL
)
19908 error (_("%s used without .debug_str.dwo section"
19909 " in CU at offset %s [in module %s]"),
19910 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19911 if (str_offsets_section
->buffer
== NULL
)
19912 error (_("%s used without .debug_str_offsets.dwo section"
19913 " in CU at offset %s [in module %s]"),
19914 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19915 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
19916 error (_("%s pointing outside of .debug_str_offsets.dwo"
19917 " section in CU at offset %s [in module %s]"),
19918 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19919 info_ptr
= (str_offsets_section
->buffer
19920 + str_index
* cu
->header
.offset_size
);
19921 if (cu
->header
.offset_size
== 4)
19922 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19924 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19925 if (str_offset
>= str_section
->size
)
19926 error (_("Offset from %s pointing outside of"
19927 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19928 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19929 return (const char *) (str_section
->buffer
+ str_offset
);
19932 /* Return the length of an LEB128 number in BUF. */
19935 leb128_size (const gdb_byte
*buf
)
19937 const gdb_byte
*begin
= buf
;
19943 if ((byte
& 128) == 0)
19944 return buf
- begin
;
19949 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19958 cu
->language
= language_c
;
19961 case DW_LANG_C_plus_plus
:
19962 case DW_LANG_C_plus_plus_11
:
19963 case DW_LANG_C_plus_plus_14
:
19964 cu
->language
= language_cplus
;
19967 cu
->language
= language_d
;
19969 case DW_LANG_Fortran77
:
19970 case DW_LANG_Fortran90
:
19971 case DW_LANG_Fortran95
:
19972 case DW_LANG_Fortran03
:
19973 case DW_LANG_Fortran08
:
19974 cu
->language
= language_fortran
;
19977 cu
->language
= language_go
;
19979 case DW_LANG_Mips_Assembler
:
19980 cu
->language
= language_asm
;
19982 case DW_LANG_Ada83
:
19983 case DW_LANG_Ada95
:
19984 cu
->language
= language_ada
;
19986 case DW_LANG_Modula2
:
19987 cu
->language
= language_m2
;
19989 case DW_LANG_Pascal83
:
19990 cu
->language
= language_pascal
;
19993 cu
->language
= language_objc
;
19996 case DW_LANG_Rust_old
:
19997 cu
->language
= language_rust
;
19999 case DW_LANG_Cobol74
:
20000 case DW_LANG_Cobol85
:
20002 cu
->language
= language_minimal
;
20005 cu
->language_defn
= language_def (cu
->language
);
20008 /* Return the named attribute or NULL if not there. */
20010 static struct attribute
*
20011 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20016 struct attribute
*spec
= NULL
;
20018 for (i
= 0; i
< die
->num_attrs
; ++i
)
20020 if (die
->attrs
[i
].name
== name
)
20021 return &die
->attrs
[i
];
20022 if (die
->attrs
[i
].name
== DW_AT_specification
20023 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20024 spec
= &die
->attrs
[i
];
20030 die
= follow_die_ref (die
, spec
, &cu
);
20036 /* Return the named attribute or NULL if not there,
20037 but do not follow DW_AT_specification, etc.
20038 This is for use in contexts where we're reading .debug_types dies.
20039 Following DW_AT_specification, DW_AT_abstract_origin will take us
20040 back up the chain, and we want to go down. */
20042 static struct attribute
*
20043 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20047 for (i
= 0; i
< die
->num_attrs
; ++i
)
20048 if (die
->attrs
[i
].name
== name
)
20049 return &die
->attrs
[i
];
20054 /* Return the string associated with a string-typed attribute, or NULL if it
20055 is either not found or is of an incorrect type. */
20057 static const char *
20058 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20060 struct attribute
*attr
;
20061 const char *str
= NULL
;
20063 attr
= dwarf2_attr (die
, name
, cu
);
20067 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20068 || attr
->form
== DW_FORM_string
20069 || attr
->form
== DW_FORM_GNU_str_index
20070 || attr
->form
== DW_FORM_GNU_strp_alt
)
20071 str
= DW_STRING (attr
);
20073 complaint (_("string type expected for attribute %s for "
20074 "DIE at %s in module %s"),
20075 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20076 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20082 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20083 and holds a non-zero value. This function should only be used for
20084 DW_FORM_flag or DW_FORM_flag_present attributes. */
20087 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20089 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20091 return (attr
&& DW_UNSND (attr
));
20095 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20097 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20098 which value is non-zero. However, we have to be careful with
20099 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20100 (via dwarf2_flag_true_p) follows this attribute. So we may
20101 end up accidently finding a declaration attribute that belongs
20102 to a different DIE referenced by the specification attribute,
20103 even though the given DIE does not have a declaration attribute. */
20104 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20105 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20108 /* Return the die giving the specification for DIE, if there is
20109 one. *SPEC_CU is the CU containing DIE on input, and the CU
20110 containing the return value on output. If there is no
20111 specification, but there is an abstract origin, that is
20114 static struct die_info
*
20115 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20117 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20120 if (spec_attr
== NULL
)
20121 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20123 if (spec_attr
== NULL
)
20126 return follow_die_ref (die
, spec_attr
, spec_cu
);
20129 /* Stub for free_line_header to match void * callback types. */
20132 free_line_header_voidp (void *arg
)
20134 struct line_header
*lh
= (struct line_header
*) arg
;
20140 line_header::add_include_dir (const char *include_dir
)
20142 if (dwarf_line_debug
>= 2)
20143 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20144 include_dirs
.size () + 1, include_dir
);
20146 include_dirs
.push_back (include_dir
);
20150 line_header::add_file_name (const char *name
,
20152 unsigned int mod_time
,
20153 unsigned int length
)
20155 if (dwarf_line_debug
>= 2)
20156 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
20157 (unsigned) file_names
.size () + 1, name
);
20159 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20162 /* A convenience function to find the proper .debug_line section for a CU. */
20164 static struct dwarf2_section_info
*
20165 get_debug_line_section (struct dwarf2_cu
*cu
)
20167 struct dwarf2_section_info
*section
;
20168 struct dwarf2_per_objfile
*dwarf2_per_objfile
20169 = cu
->per_cu
->dwarf2_per_objfile
;
20171 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20173 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20174 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20175 else if (cu
->per_cu
->is_dwz
)
20177 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20179 section
= &dwz
->line
;
20182 section
= &dwarf2_per_objfile
->line
;
20187 /* Read directory or file name entry format, starting with byte of
20188 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20189 entries count and the entries themselves in the described entry
20193 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20194 bfd
*abfd
, const gdb_byte
**bufp
,
20195 struct line_header
*lh
,
20196 const struct comp_unit_head
*cu_header
,
20197 void (*callback
) (struct line_header
*lh
,
20200 unsigned int mod_time
,
20201 unsigned int length
))
20203 gdb_byte format_count
, formati
;
20204 ULONGEST data_count
, datai
;
20205 const gdb_byte
*buf
= *bufp
;
20206 const gdb_byte
*format_header_data
;
20207 unsigned int bytes_read
;
20209 format_count
= read_1_byte (abfd
, buf
);
20211 format_header_data
= buf
;
20212 for (formati
= 0; formati
< format_count
; formati
++)
20214 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20216 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20220 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20222 for (datai
= 0; datai
< data_count
; datai
++)
20224 const gdb_byte
*format
= format_header_data
;
20225 struct file_entry fe
;
20227 for (formati
= 0; formati
< format_count
; formati
++)
20229 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20230 format
+= bytes_read
;
20232 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20233 format
+= bytes_read
;
20235 gdb::optional
<const char *> string
;
20236 gdb::optional
<unsigned int> uint
;
20240 case DW_FORM_string
:
20241 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20245 case DW_FORM_line_strp
:
20246 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20253 case DW_FORM_data1
:
20254 uint
.emplace (read_1_byte (abfd
, buf
));
20258 case DW_FORM_data2
:
20259 uint
.emplace (read_2_bytes (abfd
, buf
));
20263 case DW_FORM_data4
:
20264 uint
.emplace (read_4_bytes (abfd
, buf
));
20268 case DW_FORM_data8
:
20269 uint
.emplace (read_8_bytes (abfd
, buf
));
20273 case DW_FORM_udata
:
20274 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20278 case DW_FORM_block
:
20279 /* It is valid only for DW_LNCT_timestamp which is ignored by
20284 switch (content_type
)
20287 if (string
.has_value ())
20290 case DW_LNCT_directory_index
:
20291 if (uint
.has_value ())
20292 fe
.d_index
= (dir_index
) *uint
;
20294 case DW_LNCT_timestamp
:
20295 if (uint
.has_value ())
20296 fe
.mod_time
= *uint
;
20299 if (uint
.has_value ())
20305 complaint (_("Unknown format content type %s"),
20306 pulongest (content_type
));
20310 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20316 /* Read the statement program header starting at OFFSET in
20317 .debug_line, or .debug_line.dwo. Return a pointer
20318 to a struct line_header, allocated using xmalloc.
20319 Returns NULL if there is a problem reading the header, e.g., if it
20320 has a version we don't understand.
20322 NOTE: the strings in the include directory and file name tables of
20323 the returned object point into the dwarf line section buffer,
20324 and must not be freed. */
20326 static line_header_up
20327 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20329 const gdb_byte
*line_ptr
;
20330 unsigned int bytes_read
, offset_size
;
20332 const char *cur_dir
, *cur_file
;
20333 struct dwarf2_section_info
*section
;
20335 struct dwarf2_per_objfile
*dwarf2_per_objfile
20336 = cu
->per_cu
->dwarf2_per_objfile
;
20338 section
= get_debug_line_section (cu
);
20339 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20340 if (section
->buffer
== NULL
)
20342 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20343 complaint (_("missing .debug_line.dwo section"));
20345 complaint (_("missing .debug_line section"));
20349 /* We can't do this until we know the section is non-empty.
20350 Only then do we know we have such a section. */
20351 abfd
= get_section_bfd_owner (section
);
20353 /* Make sure that at least there's room for the total_length field.
20354 That could be 12 bytes long, but we're just going to fudge that. */
20355 if (to_underlying (sect_off
) + 4 >= section
->size
)
20357 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20361 line_header_up
lh (new line_header ());
20363 lh
->sect_off
= sect_off
;
20364 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20366 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20368 /* Read in the header. */
20370 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20371 &bytes_read
, &offset_size
);
20372 line_ptr
+= bytes_read
;
20373 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20375 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20378 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20379 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20381 if (lh
->version
> 5)
20383 /* This is a version we don't understand. The format could have
20384 changed in ways we don't handle properly so just punt. */
20385 complaint (_("unsupported version in .debug_line section"));
20388 if (lh
->version
>= 5)
20390 gdb_byte segment_selector_size
;
20392 /* Skip address size. */
20393 read_1_byte (abfd
, line_ptr
);
20396 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20398 if (segment_selector_size
!= 0)
20400 complaint (_("unsupported segment selector size %u "
20401 "in .debug_line section"),
20402 segment_selector_size
);
20406 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20407 line_ptr
+= offset_size
;
20408 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20410 if (lh
->version
>= 4)
20412 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20416 lh
->maximum_ops_per_instruction
= 1;
20418 if (lh
->maximum_ops_per_instruction
== 0)
20420 lh
->maximum_ops_per_instruction
= 1;
20421 complaint (_("invalid maximum_ops_per_instruction "
20422 "in `.debug_line' section"));
20425 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20427 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20429 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20431 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20433 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20435 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20436 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20438 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20442 if (lh
->version
>= 5)
20444 /* Read directory table. */
20445 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20447 [] (struct line_header
*header
, const char *name
,
20448 dir_index d_index
, unsigned int mod_time
,
20449 unsigned int length
)
20451 header
->add_include_dir (name
);
20454 /* Read file name table. */
20455 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20457 [] (struct line_header
*header
, const char *name
,
20458 dir_index d_index
, unsigned int mod_time
,
20459 unsigned int length
)
20461 header
->add_file_name (name
, d_index
, mod_time
, length
);
20466 /* Read directory table. */
20467 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20469 line_ptr
+= bytes_read
;
20470 lh
->add_include_dir (cur_dir
);
20472 line_ptr
+= bytes_read
;
20474 /* Read file name table. */
20475 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20477 unsigned int mod_time
, length
;
20480 line_ptr
+= bytes_read
;
20481 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20482 line_ptr
+= bytes_read
;
20483 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20484 line_ptr
+= bytes_read
;
20485 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20486 line_ptr
+= bytes_read
;
20488 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20490 line_ptr
+= bytes_read
;
20492 lh
->statement_program_start
= line_ptr
;
20494 if (line_ptr
> (section
->buffer
+ section
->size
))
20495 complaint (_("line number info header doesn't "
20496 "fit in `.debug_line' section"));
20501 /* Subroutine of dwarf_decode_lines to simplify it.
20502 Return the file name of the psymtab for included file FILE_INDEX
20503 in line header LH of PST.
20504 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20505 If space for the result is malloc'd, *NAME_HOLDER will be set.
20506 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20508 static const char *
20509 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20510 const struct partial_symtab
*pst
,
20511 const char *comp_dir
,
20512 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20514 const file_entry
&fe
= lh
->file_names
[file_index
];
20515 const char *include_name
= fe
.name
;
20516 const char *include_name_to_compare
= include_name
;
20517 const char *pst_filename
;
20520 const char *dir_name
= fe
.include_dir (lh
);
20522 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20523 if (!IS_ABSOLUTE_PATH (include_name
)
20524 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20526 /* Avoid creating a duplicate psymtab for PST.
20527 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20528 Before we do the comparison, however, we need to account
20529 for DIR_NAME and COMP_DIR.
20530 First prepend dir_name (if non-NULL). If we still don't
20531 have an absolute path prepend comp_dir (if non-NULL).
20532 However, the directory we record in the include-file's
20533 psymtab does not contain COMP_DIR (to match the
20534 corresponding symtab(s)).
20539 bash$ gcc -g ./hello.c
20540 include_name = "hello.c"
20542 DW_AT_comp_dir = comp_dir = "/tmp"
20543 DW_AT_name = "./hello.c"
20547 if (dir_name
!= NULL
)
20549 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20550 include_name
, (char *) NULL
));
20551 include_name
= name_holder
->get ();
20552 include_name_to_compare
= include_name
;
20554 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20556 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20557 include_name
, (char *) NULL
));
20558 include_name_to_compare
= hold_compare
.get ();
20562 pst_filename
= pst
->filename
;
20563 gdb::unique_xmalloc_ptr
<char> copied_name
;
20564 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20566 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20567 pst_filename
, (char *) NULL
));
20568 pst_filename
= copied_name
.get ();
20571 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20575 return include_name
;
20578 /* State machine to track the state of the line number program. */
20580 class lnp_state_machine
20583 /* Initialize a machine state for the start of a line number
20585 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20586 bool record_lines_p
);
20588 file_entry
*current_file ()
20590 /* lh->file_names is 0-based, but the file name numbers in the
20591 statement program are 1-based. */
20592 return m_line_header
->file_name_at (m_file
);
20595 /* Record the line in the state machine. END_SEQUENCE is true if
20596 we're processing the end of a sequence. */
20597 void record_line (bool end_sequence
);
20599 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
20600 nop-out rest of the lines in this sequence. */
20601 void check_line_address (struct dwarf2_cu
*cu
,
20602 const gdb_byte
*line_ptr
,
20603 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20605 void handle_set_discriminator (unsigned int discriminator
)
20607 m_discriminator
= discriminator
;
20608 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20611 /* Handle DW_LNE_set_address. */
20612 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20615 address
+= baseaddr
;
20616 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20619 /* Handle DW_LNS_advance_pc. */
20620 void handle_advance_pc (CORE_ADDR adjust
);
20622 /* Handle a special opcode. */
20623 void handle_special_opcode (unsigned char op_code
);
20625 /* Handle DW_LNS_advance_line. */
20626 void handle_advance_line (int line_delta
)
20628 advance_line (line_delta
);
20631 /* Handle DW_LNS_set_file. */
20632 void handle_set_file (file_name_index file
);
20634 /* Handle DW_LNS_negate_stmt. */
20635 void handle_negate_stmt ()
20637 m_is_stmt
= !m_is_stmt
;
20640 /* Handle DW_LNS_const_add_pc. */
20641 void handle_const_add_pc ();
20643 /* Handle DW_LNS_fixed_advance_pc. */
20644 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20646 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20650 /* Handle DW_LNS_copy. */
20651 void handle_copy ()
20653 record_line (false);
20654 m_discriminator
= 0;
20657 /* Handle DW_LNE_end_sequence. */
20658 void handle_end_sequence ()
20660 m_currently_recording_lines
= true;
20664 /* Advance the line by LINE_DELTA. */
20665 void advance_line (int line_delta
)
20667 m_line
+= line_delta
;
20669 if (line_delta
!= 0)
20670 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20673 struct dwarf2_cu
*m_cu
;
20675 gdbarch
*m_gdbarch
;
20677 /* True if we're recording lines.
20678 Otherwise we're building partial symtabs and are just interested in
20679 finding include files mentioned by the line number program. */
20680 bool m_record_lines_p
;
20682 /* The line number header. */
20683 line_header
*m_line_header
;
20685 /* These are part of the standard DWARF line number state machine,
20686 and initialized according to the DWARF spec. */
20688 unsigned char m_op_index
= 0;
20689 /* The line table index (1-based) of the current file. */
20690 file_name_index m_file
= (file_name_index
) 1;
20691 unsigned int m_line
= 1;
20693 /* These are initialized in the constructor. */
20695 CORE_ADDR m_address
;
20697 unsigned int m_discriminator
;
20699 /* Additional bits of state we need to track. */
20701 /* The last file that we called dwarf2_start_subfile for.
20702 This is only used for TLLs. */
20703 unsigned int m_last_file
= 0;
20704 /* The last file a line number was recorded for. */
20705 struct subfile
*m_last_subfile
= NULL
;
20707 /* When true, record the lines we decode. */
20708 bool m_currently_recording_lines
= false;
20710 /* The last line number that was recorded, used to coalesce
20711 consecutive entries for the same line. This can happen, for
20712 example, when discriminators are present. PR 17276. */
20713 unsigned int m_last_line
= 0;
20714 bool m_line_has_non_zero_discriminator
= false;
20718 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20720 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20721 / m_line_header
->maximum_ops_per_instruction
)
20722 * m_line_header
->minimum_instruction_length
);
20723 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20724 m_op_index
= ((m_op_index
+ adjust
)
20725 % m_line_header
->maximum_ops_per_instruction
);
20729 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20731 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20732 CORE_ADDR addr_adj
= (((m_op_index
20733 + (adj_opcode
/ m_line_header
->line_range
))
20734 / m_line_header
->maximum_ops_per_instruction
)
20735 * m_line_header
->minimum_instruction_length
);
20736 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20737 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20738 % m_line_header
->maximum_ops_per_instruction
);
20740 int line_delta
= (m_line_header
->line_base
20741 + (adj_opcode
% m_line_header
->line_range
));
20742 advance_line (line_delta
);
20743 record_line (false);
20744 m_discriminator
= 0;
20748 lnp_state_machine::handle_set_file (file_name_index file
)
20752 const file_entry
*fe
= current_file ();
20754 dwarf2_debug_line_missing_file_complaint ();
20755 else if (m_record_lines_p
)
20757 const char *dir
= fe
->include_dir (m_line_header
);
20759 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20760 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20761 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20766 lnp_state_machine::handle_const_add_pc ()
20769 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20772 = (((m_op_index
+ adjust
)
20773 / m_line_header
->maximum_ops_per_instruction
)
20774 * m_line_header
->minimum_instruction_length
);
20776 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20777 m_op_index
= ((m_op_index
+ adjust
)
20778 % m_line_header
->maximum_ops_per_instruction
);
20781 /* Return non-zero if we should add LINE to the line number table.
20782 LINE is the line to add, LAST_LINE is the last line that was added,
20783 LAST_SUBFILE is the subfile for LAST_LINE.
20784 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20785 had a non-zero discriminator.
20787 We have to be careful in the presence of discriminators.
20788 E.g., for this line:
20790 for (i = 0; i < 100000; i++);
20792 clang can emit four line number entries for that one line,
20793 each with a different discriminator.
20794 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20796 However, we want gdb to coalesce all four entries into one.
20797 Otherwise the user could stepi into the middle of the line and
20798 gdb would get confused about whether the pc really was in the
20799 middle of the line.
20801 Things are further complicated by the fact that two consecutive
20802 line number entries for the same line is a heuristic used by gcc
20803 to denote the end of the prologue. So we can't just discard duplicate
20804 entries, we have to be selective about it. The heuristic we use is
20805 that we only collapse consecutive entries for the same line if at least
20806 one of those entries has a non-zero discriminator. PR 17276.
20808 Note: Addresses in the line number state machine can never go backwards
20809 within one sequence, thus this coalescing is ok. */
20812 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20813 unsigned int line
, unsigned int last_line
,
20814 int line_has_non_zero_discriminator
,
20815 struct subfile
*last_subfile
)
20817 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20819 if (line
!= last_line
)
20821 /* Same line for the same file that we've seen already.
20822 As a last check, for pr 17276, only record the line if the line
20823 has never had a non-zero discriminator. */
20824 if (!line_has_non_zero_discriminator
)
20829 /* Use the CU's builder to record line number LINE beginning at
20830 address ADDRESS in the line table of subfile SUBFILE. */
20833 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20834 unsigned int line
, CORE_ADDR address
,
20835 struct dwarf2_cu
*cu
)
20837 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20839 if (dwarf_line_debug
)
20841 fprintf_unfiltered (gdb_stdlog
,
20842 "Recording line %u, file %s, address %s\n",
20843 line
, lbasename (subfile
->name
),
20844 paddress (gdbarch
, address
));
20848 cu
->get_builder ()->record_line (subfile
, line
, addr
);
20851 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20852 Mark the end of a set of line number records.
20853 The arguments are the same as for dwarf_record_line_1.
20854 If SUBFILE is NULL the request is ignored. */
20857 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20858 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20860 if (subfile
== NULL
)
20863 if (dwarf_line_debug
)
20865 fprintf_unfiltered (gdb_stdlog
,
20866 "Finishing current line, file %s, address %s\n",
20867 lbasename (subfile
->name
),
20868 paddress (gdbarch
, address
));
20871 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
20875 lnp_state_machine::record_line (bool end_sequence
)
20877 if (dwarf_line_debug
)
20879 fprintf_unfiltered (gdb_stdlog
,
20880 "Processing actual line %u: file %u,"
20881 " address %s, is_stmt %u, discrim %u\n",
20882 m_line
, to_underlying (m_file
),
20883 paddress (m_gdbarch
, m_address
),
20884 m_is_stmt
, m_discriminator
);
20887 file_entry
*fe
= current_file ();
20890 dwarf2_debug_line_missing_file_complaint ();
20891 /* For now we ignore lines not starting on an instruction boundary.
20892 But not when processing end_sequence for compatibility with the
20893 previous version of the code. */
20894 else if (m_op_index
== 0 || end_sequence
)
20896 fe
->included_p
= 1;
20897 if (m_record_lines_p
&& (producer_is_codewarrior (m_cu
) || m_is_stmt
))
20899 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20902 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20903 m_currently_recording_lines
? m_cu
: nullptr);
20908 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20909 m_line_has_non_zero_discriminator
,
20912 buildsym_compunit
*builder
= m_cu
->get_builder ();
20913 dwarf_record_line_1 (m_gdbarch
,
20914 builder
->get_current_subfile (),
20916 m_currently_recording_lines
? m_cu
: nullptr);
20918 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20919 m_last_line
= m_line
;
20925 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20926 line_header
*lh
, bool record_lines_p
)
20930 m_record_lines_p
= record_lines_p
;
20931 m_line_header
= lh
;
20933 m_currently_recording_lines
= true;
20935 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20936 was a line entry for it so that the backend has a chance to adjust it
20937 and also record it in case it needs it. This is currently used by MIPS
20938 code, cf. `mips_adjust_dwarf2_line'. */
20939 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20940 m_is_stmt
= lh
->default_is_stmt
;
20941 m_discriminator
= 0;
20945 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20946 const gdb_byte
*line_ptr
,
20947 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20949 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20950 the pc range of the CU. However, we restrict the test to only ADDRESS
20951 values of zero to preserve GDB's previous behaviour which is to handle
20952 the specific case of a function being GC'd by the linker. */
20954 if (address
== 0 && address
< unrelocated_lowpc
)
20956 /* This line table is for a function which has been
20957 GCd by the linker. Ignore it. PR gdb/12528 */
20959 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20960 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20962 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20963 line_offset
, objfile_name (objfile
));
20964 m_currently_recording_lines
= false;
20965 /* Note: m_currently_recording_lines is left as false until we see
20966 DW_LNE_end_sequence. */
20970 /* Subroutine of dwarf_decode_lines to simplify it.
20971 Process the line number information in LH.
20972 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20973 program in order to set included_p for every referenced header. */
20976 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20977 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20979 const gdb_byte
*line_ptr
, *extended_end
;
20980 const gdb_byte
*line_end
;
20981 unsigned int bytes_read
, extended_len
;
20982 unsigned char op_code
, extended_op
;
20983 CORE_ADDR baseaddr
;
20984 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20985 bfd
*abfd
= objfile
->obfd
;
20986 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20987 /* True if we're recording line info (as opposed to building partial
20988 symtabs and just interested in finding include files mentioned by
20989 the line number program). */
20990 bool record_lines_p
= !decode_for_pst_p
;
20992 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
20994 line_ptr
= lh
->statement_program_start
;
20995 line_end
= lh
->statement_program_end
;
20997 /* Read the statement sequences until there's nothing left. */
20998 while (line_ptr
< line_end
)
21000 /* The DWARF line number program state machine. Reset the state
21001 machine at the start of each sequence. */
21002 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21003 bool end_sequence
= false;
21005 if (record_lines_p
)
21007 /* Start a subfile for the current file of the state
21009 const file_entry
*fe
= state_machine
.current_file ();
21012 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21015 /* Decode the table. */
21016 while (line_ptr
< line_end
&& !end_sequence
)
21018 op_code
= read_1_byte (abfd
, line_ptr
);
21021 if (op_code
>= lh
->opcode_base
)
21023 /* Special opcode. */
21024 state_machine
.handle_special_opcode (op_code
);
21026 else switch (op_code
)
21028 case DW_LNS_extended_op
:
21029 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21031 line_ptr
+= bytes_read
;
21032 extended_end
= line_ptr
+ extended_len
;
21033 extended_op
= read_1_byte (abfd
, line_ptr
);
21035 switch (extended_op
)
21037 case DW_LNE_end_sequence
:
21038 state_machine
.handle_end_sequence ();
21039 end_sequence
= true;
21041 case DW_LNE_set_address
:
21044 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21045 line_ptr
+= bytes_read
;
21047 state_machine
.check_line_address (cu
, line_ptr
,
21048 lowpc
- baseaddr
, address
);
21049 state_machine
.handle_set_address (baseaddr
, address
);
21052 case DW_LNE_define_file
:
21054 const char *cur_file
;
21055 unsigned int mod_time
, length
;
21058 cur_file
= read_direct_string (abfd
, line_ptr
,
21060 line_ptr
+= bytes_read
;
21061 dindex
= (dir_index
)
21062 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21063 line_ptr
+= bytes_read
;
21065 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21066 line_ptr
+= bytes_read
;
21068 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21069 line_ptr
+= bytes_read
;
21070 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21073 case DW_LNE_set_discriminator
:
21075 /* The discriminator is not interesting to the
21076 debugger; just ignore it. We still need to
21077 check its value though:
21078 if there are consecutive entries for the same
21079 (non-prologue) line we want to coalesce them.
21082 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21083 line_ptr
+= bytes_read
;
21085 state_machine
.handle_set_discriminator (discr
);
21089 complaint (_("mangled .debug_line section"));
21092 /* Make sure that we parsed the extended op correctly. If e.g.
21093 we expected a different address size than the producer used,
21094 we may have read the wrong number of bytes. */
21095 if (line_ptr
!= extended_end
)
21097 complaint (_("mangled .debug_line section"));
21102 state_machine
.handle_copy ();
21104 case DW_LNS_advance_pc
:
21107 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21108 line_ptr
+= bytes_read
;
21110 state_machine
.handle_advance_pc (adjust
);
21113 case DW_LNS_advance_line
:
21116 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21117 line_ptr
+= bytes_read
;
21119 state_machine
.handle_advance_line (line_delta
);
21122 case DW_LNS_set_file
:
21124 file_name_index file
21125 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21127 line_ptr
+= bytes_read
;
21129 state_machine
.handle_set_file (file
);
21132 case DW_LNS_set_column
:
21133 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21134 line_ptr
+= bytes_read
;
21136 case DW_LNS_negate_stmt
:
21137 state_machine
.handle_negate_stmt ();
21139 case DW_LNS_set_basic_block
:
21141 /* Add to the address register of the state machine the
21142 address increment value corresponding to special opcode
21143 255. I.e., this value is scaled by the minimum
21144 instruction length since special opcode 255 would have
21145 scaled the increment. */
21146 case DW_LNS_const_add_pc
:
21147 state_machine
.handle_const_add_pc ();
21149 case DW_LNS_fixed_advance_pc
:
21151 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21154 state_machine
.handle_fixed_advance_pc (addr_adj
);
21159 /* Unknown standard opcode, ignore it. */
21162 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21164 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21165 line_ptr
+= bytes_read
;
21172 dwarf2_debug_line_missing_end_sequence_complaint ();
21174 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21175 in which case we still finish recording the last line). */
21176 state_machine
.record_line (true);
21180 /* Decode the Line Number Program (LNP) for the given line_header
21181 structure and CU. The actual information extracted and the type
21182 of structures created from the LNP depends on the value of PST.
21184 1. If PST is NULL, then this procedure uses the data from the program
21185 to create all necessary symbol tables, and their linetables.
21187 2. If PST is not NULL, this procedure reads the program to determine
21188 the list of files included by the unit represented by PST, and
21189 builds all the associated partial symbol tables.
21191 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21192 It is used for relative paths in the line table.
21193 NOTE: When processing partial symtabs (pst != NULL),
21194 comp_dir == pst->dirname.
21196 NOTE: It is important that psymtabs have the same file name (via strcmp)
21197 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21198 symtab we don't use it in the name of the psymtabs we create.
21199 E.g. expand_line_sal requires this when finding psymtabs to expand.
21200 A good testcase for this is mb-inline.exp.
21202 LOWPC is the lowest address in CU (or 0 if not known).
21204 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21205 for its PC<->lines mapping information. Otherwise only the filename
21206 table is read in. */
21209 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21210 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21211 CORE_ADDR lowpc
, int decode_mapping
)
21213 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21214 const int decode_for_pst_p
= (pst
!= NULL
);
21216 if (decode_mapping
)
21217 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21219 if (decode_for_pst_p
)
21223 /* Now that we're done scanning the Line Header Program, we can
21224 create the psymtab of each included file. */
21225 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
21226 if (lh
->file_names
[file_index
].included_p
== 1)
21228 gdb::unique_xmalloc_ptr
<char> name_holder
;
21229 const char *include_name
=
21230 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
21232 if (include_name
!= NULL
)
21233 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21238 /* Make sure a symtab is created for every file, even files
21239 which contain only variables (i.e. no code with associated
21241 buildsym_compunit
*builder
= cu
->get_builder ();
21242 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21245 for (i
= 0; i
< lh
->file_names
.size (); i
++)
21247 file_entry
&fe
= lh
->file_names
[i
];
21249 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21251 if (builder
->get_current_subfile ()->symtab
== NULL
)
21253 builder
->get_current_subfile ()->symtab
21254 = allocate_symtab (cust
,
21255 builder
->get_current_subfile ()->name
);
21257 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21262 /* Start a subfile for DWARF. FILENAME is the name of the file and
21263 DIRNAME the name of the source directory which contains FILENAME
21264 or NULL if not known.
21265 This routine tries to keep line numbers from identical absolute and
21266 relative file names in a common subfile.
21268 Using the `list' example from the GDB testsuite, which resides in
21269 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21270 of /srcdir/list0.c yields the following debugging information for list0.c:
21272 DW_AT_name: /srcdir/list0.c
21273 DW_AT_comp_dir: /compdir
21274 files.files[0].name: list0.h
21275 files.files[0].dir: /srcdir
21276 files.files[1].name: list0.c
21277 files.files[1].dir: /srcdir
21279 The line number information for list0.c has to end up in a single
21280 subfile, so that `break /srcdir/list0.c:1' works as expected.
21281 start_subfile will ensure that this happens provided that we pass the
21282 concatenation of files.files[1].dir and files.files[1].name as the
21286 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21287 const char *dirname
)
21291 /* In order not to lose the line information directory,
21292 we concatenate it to the filename when it makes sense.
21293 Note that the Dwarf3 standard says (speaking of filenames in line
21294 information): ``The directory index is ignored for file names
21295 that represent full path names''. Thus ignoring dirname in the
21296 `else' branch below isn't an issue. */
21298 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21300 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21304 cu
->get_builder ()->start_subfile (filename
);
21310 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21311 buildsym_compunit constructor. */
21313 struct compunit_symtab
*
21314 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21317 gdb_assert (m_builder
== nullptr);
21319 m_builder
.reset (new struct buildsym_compunit
21320 (per_cu
->dwarf2_per_objfile
->objfile
,
21321 name
, comp_dir
, language
, low_pc
));
21323 list_in_scope
= get_builder ()->get_file_symbols ();
21325 get_builder ()->record_debugformat ("DWARF 2");
21326 get_builder ()->record_producer (producer
);
21328 processing_has_namespace_info
= false;
21330 return get_builder ()->get_compunit_symtab ();
21334 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21335 struct dwarf2_cu
*cu
)
21337 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21338 struct comp_unit_head
*cu_header
= &cu
->header
;
21340 /* NOTE drow/2003-01-30: There used to be a comment and some special
21341 code here to turn a symbol with DW_AT_external and a
21342 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21343 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21344 with some versions of binutils) where shared libraries could have
21345 relocations against symbols in their debug information - the
21346 minimal symbol would have the right address, but the debug info
21347 would not. It's no longer necessary, because we will explicitly
21348 apply relocations when we read in the debug information now. */
21350 /* A DW_AT_location attribute with no contents indicates that a
21351 variable has been optimized away. */
21352 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21354 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21358 /* Handle one degenerate form of location expression specially, to
21359 preserve GDB's previous behavior when section offsets are
21360 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
21361 then mark this symbol as LOC_STATIC. */
21363 if (attr_form_is_block (attr
)
21364 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21365 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21366 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21367 && (DW_BLOCK (attr
)->size
21368 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21370 unsigned int dummy
;
21372 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21373 SYMBOL_VALUE_ADDRESS (sym
) =
21374 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
21376 SYMBOL_VALUE_ADDRESS (sym
) =
21377 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
21378 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21379 fixup_symbol_section (sym
, objfile
);
21380 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
21381 SYMBOL_SECTION (sym
));
21385 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21386 expression evaluator, and use LOC_COMPUTED only when necessary
21387 (i.e. when the value of a register or memory location is
21388 referenced, or a thread-local block, etc.). Then again, it might
21389 not be worthwhile. I'm assuming that it isn't unless performance
21390 or memory numbers show me otherwise. */
21392 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21394 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21395 cu
->has_loclist
= true;
21398 /* Given a pointer to a DWARF information entry, figure out if we need
21399 to make a symbol table entry for it, and if so, create a new entry
21400 and return a pointer to it.
21401 If TYPE is NULL, determine symbol type from the die, otherwise
21402 used the passed type.
21403 If SPACE is not NULL, use it to hold the new symbol. If it is
21404 NULL, allocate a new symbol on the objfile's obstack. */
21406 static struct symbol
*
21407 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21408 struct symbol
*space
)
21410 struct dwarf2_per_objfile
*dwarf2_per_objfile
21411 = cu
->per_cu
->dwarf2_per_objfile
;
21412 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21413 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21414 struct symbol
*sym
= NULL
;
21416 struct attribute
*attr
= NULL
;
21417 struct attribute
*attr2
= NULL
;
21418 CORE_ADDR baseaddr
;
21419 struct pending
**list_to_add
= NULL
;
21421 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21423 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21425 name
= dwarf2_name (die
, cu
);
21428 const char *linkagename
;
21429 int suppress_add
= 0;
21434 sym
= allocate_symbol (objfile
);
21435 OBJSTAT (objfile
, n_syms
++);
21437 /* Cache this symbol's name and the name's demangled form (if any). */
21438 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21439 linkagename
= dwarf2_physname (name
, die
, cu
);
21440 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21442 /* Fortran does not have mangling standard and the mangling does differ
21443 between gfortran, iFort etc. */
21444 if (cu
->language
== language_fortran
21445 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21446 symbol_set_demangled_name (&(sym
->ginfo
),
21447 dwarf2_full_name (name
, die
, cu
),
21450 /* Default assumptions.
21451 Use the passed type or decode it from the die. */
21452 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21453 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21455 SYMBOL_TYPE (sym
) = type
;
21457 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21458 attr
= dwarf2_attr (die
,
21459 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21463 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21466 attr
= dwarf2_attr (die
,
21467 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21471 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21472 struct file_entry
*fe
;
21474 if (cu
->line_header
!= NULL
)
21475 fe
= cu
->line_header
->file_name_at (file_index
);
21480 complaint (_("file index out of range"));
21482 symbol_set_symtab (sym
, fe
->symtab
);
21488 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21493 addr
= attr_value_as_address (attr
);
21494 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21495 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
21497 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21498 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21499 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21500 add_symbol_to_list (sym
, cu
->list_in_scope
);
21502 case DW_TAG_subprogram
:
21503 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21505 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21506 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21507 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21508 || cu
->language
== language_ada
)
21510 /* Subprograms marked external are stored as a global symbol.
21511 Ada subprograms, whether marked external or not, are always
21512 stored as a global symbol, because we want to be able to
21513 access them globally. For instance, we want to be able
21514 to break on a nested subprogram without having to
21515 specify the context. */
21516 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21520 list_to_add
= cu
->list_in_scope
;
21523 case DW_TAG_inlined_subroutine
:
21524 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21526 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21527 SYMBOL_INLINED (sym
) = 1;
21528 list_to_add
= cu
->list_in_scope
;
21530 case DW_TAG_template_value_param
:
21532 /* Fall through. */
21533 case DW_TAG_constant
:
21534 case DW_TAG_variable
:
21535 case DW_TAG_member
:
21536 /* Compilation with minimal debug info may result in
21537 variables with missing type entries. Change the
21538 misleading `void' type to something sensible. */
21539 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21540 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21542 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21543 /* In the case of DW_TAG_member, we should only be called for
21544 static const members. */
21545 if (die
->tag
== DW_TAG_member
)
21547 /* dwarf2_add_field uses die_is_declaration,
21548 so we do the same. */
21549 gdb_assert (die_is_declaration (die
, cu
));
21554 dwarf2_const_value (attr
, sym
, cu
);
21555 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21558 if (attr2
&& (DW_UNSND (attr2
) != 0))
21559 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21561 list_to_add
= cu
->list_in_scope
;
21565 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21568 var_decode_location (attr
, sym
, cu
);
21569 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21571 /* Fortran explicitly imports any global symbols to the local
21572 scope by DW_TAG_common_block. */
21573 if (cu
->language
== language_fortran
&& die
->parent
21574 && die
->parent
->tag
== DW_TAG_common_block
)
21577 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21578 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21579 && !dwarf2_per_objfile
->has_section_at_zero
)
21581 /* When a static variable is eliminated by the linker,
21582 the corresponding debug information is not stripped
21583 out, but the variable address is set to null;
21584 do not add such variables into symbol table. */
21586 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21588 /* Workaround gfortran PR debug/40040 - it uses
21589 DW_AT_location for variables in -fPIC libraries which may
21590 get overriden by other libraries/executable and get
21591 a different address. Resolve it by the minimal symbol
21592 which may come from inferior's executable using copy
21593 relocation. Make this workaround only for gfortran as for
21594 other compilers GDB cannot guess the minimal symbol
21595 Fortran mangling kind. */
21596 if (cu
->language
== language_fortran
&& die
->parent
21597 && die
->parent
->tag
== DW_TAG_module
21599 && startswith (cu
->producer
, "GNU Fortran"))
21600 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21602 /* A variable with DW_AT_external is never static,
21603 but it may be block-scoped. */
21605 = ((cu
->list_in_scope
21606 == cu
->get_builder ()->get_file_symbols ())
21607 ? cu
->get_builder ()->get_global_symbols ()
21608 : cu
->list_in_scope
);
21611 list_to_add
= cu
->list_in_scope
;
21615 /* We do not know the address of this symbol.
21616 If it is an external symbol and we have type information
21617 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21618 The address of the variable will then be determined from
21619 the minimal symbol table whenever the variable is
21621 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21623 /* Fortran explicitly imports any global symbols to the local
21624 scope by DW_TAG_common_block. */
21625 if (cu
->language
== language_fortran
&& die
->parent
21626 && die
->parent
->tag
== DW_TAG_common_block
)
21628 /* SYMBOL_CLASS doesn't matter here because
21629 read_common_block is going to reset it. */
21631 list_to_add
= cu
->list_in_scope
;
21633 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21634 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21636 /* A variable with DW_AT_external is never static, but it
21637 may be block-scoped. */
21639 = ((cu
->list_in_scope
21640 == cu
->get_builder ()->get_file_symbols ())
21641 ? cu
->get_builder ()->get_global_symbols ()
21642 : cu
->list_in_scope
);
21644 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21646 else if (!die_is_declaration (die
, cu
))
21648 /* Use the default LOC_OPTIMIZED_OUT class. */
21649 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21651 list_to_add
= cu
->list_in_scope
;
21655 case DW_TAG_formal_parameter
:
21657 /* If we are inside a function, mark this as an argument. If
21658 not, we might be looking at an argument to an inlined function
21659 when we do not have enough information to show inlined frames;
21660 pretend it's a local variable in that case so that the user can
21662 struct context_stack
*curr
21663 = cu
->get_builder ()->get_current_context_stack ();
21664 if (curr
!= nullptr && curr
->name
!= nullptr)
21665 SYMBOL_IS_ARGUMENT (sym
) = 1;
21666 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21669 var_decode_location (attr
, sym
, cu
);
21671 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21674 dwarf2_const_value (attr
, sym
, cu
);
21677 list_to_add
= cu
->list_in_scope
;
21680 case DW_TAG_unspecified_parameters
:
21681 /* From varargs functions; gdb doesn't seem to have any
21682 interest in this information, so just ignore it for now.
21685 case DW_TAG_template_type_param
:
21687 /* Fall through. */
21688 case DW_TAG_class_type
:
21689 case DW_TAG_interface_type
:
21690 case DW_TAG_structure_type
:
21691 case DW_TAG_union_type
:
21692 case DW_TAG_set_type
:
21693 case DW_TAG_enumeration_type
:
21694 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21695 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21698 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21699 really ever be static objects: otherwise, if you try
21700 to, say, break of a class's method and you're in a file
21701 which doesn't mention that class, it won't work unless
21702 the check for all static symbols in lookup_symbol_aux
21703 saves you. See the OtherFileClass tests in
21704 gdb.c++/namespace.exp. */
21708 buildsym_compunit
*builder
= cu
->get_builder ();
21710 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21711 && cu
->language
== language_cplus
21712 ? builder
->get_global_symbols ()
21713 : cu
->list_in_scope
);
21715 /* The semantics of C++ state that "struct foo {
21716 ... }" also defines a typedef for "foo". */
21717 if (cu
->language
== language_cplus
21718 || cu
->language
== language_ada
21719 || cu
->language
== language_d
21720 || cu
->language
== language_rust
)
21722 /* The symbol's name is already allocated along
21723 with this objfile, so we don't need to
21724 duplicate it for the type. */
21725 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21726 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21731 case DW_TAG_typedef
:
21732 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21733 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21734 list_to_add
= cu
->list_in_scope
;
21736 case DW_TAG_base_type
:
21737 case DW_TAG_subrange_type
:
21738 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21739 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21740 list_to_add
= cu
->list_in_scope
;
21742 case DW_TAG_enumerator
:
21743 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21746 dwarf2_const_value (attr
, sym
, cu
);
21749 /* NOTE: carlton/2003-11-10: See comment above in the
21750 DW_TAG_class_type, etc. block. */
21753 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21754 && cu
->language
== language_cplus
21755 ? cu
->get_builder ()->get_global_symbols ()
21756 : cu
->list_in_scope
);
21759 case DW_TAG_imported_declaration
:
21760 case DW_TAG_namespace
:
21761 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21762 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21764 case DW_TAG_module
:
21765 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21766 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21767 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21769 case DW_TAG_common_block
:
21770 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21771 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21772 add_symbol_to_list (sym
, cu
->list_in_scope
);
21775 /* Not a tag we recognize. Hopefully we aren't processing
21776 trash data, but since we must specifically ignore things
21777 we don't recognize, there is nothing else we should do at
21779 complaint (_("unsupported tag: '%s'"),
21780 dwarf_tag_name (die
->tag
));
21786 sym
->hash_next
= objfile
->template_symbols
;
21787 objfile
->template_symbols
= sym
;
21788 list_to_add
= NULL
;
21791 if (list_to_add
!= NULL
)
21792 add_symbol_to_list (sym
, list_to_add
);
21794 /* For the benefit of old versions of GCC, check for anonymous
21795 namespaces based on the demangled name. */
21796 if (!cu
->processing_has_namespace_info
21797 && cu
->language
== language_cplus
)
21798 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21803 /* Given an attr with a DW_FORM_dataN value in host byte order,
21804 zero-extend it as appropriate for the symbol's type. The DWARF
21805 standard (v4) is not entirely clear about the meaning of using
21806 DW_FORM_dataN for a constant with a signed type, where the type is
21807 wider than the data. The conclusion of a discussion on the DWARF
21808 list was that this is unspecified. We choose to always zero-extend
21809 because that is the interpretation long in use by GCC. */
21812 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21813 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21815 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21816 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21817 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21818 LONGEST l
= DW_UNSND (attr
);
21820 if (bits
< sizeof (*value
) * 8)
21822 l
&= ((LONGEST
) 1 << bits
) - 1;
21825 else if (bits
== sizeof (*value
) * 8)
21829 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21830 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21837 /* Read a constant value from an attribute. Either set *VALUE, or if
21838 the value does not fit in *VALUE, set *BYTES - either already
21839 allocated on the objfile obstack, or newly allocated on OBSTACK,
21840 or, set *BATON, if we translated the constant to a location
21844 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21845 const char *name
, struct obstack
*obstack
,
21846 struct dwarf2_cu
*cu
,
21847 LONGEST
*value
, const gdb_byte
**bytes
,
21848 struct dwarf2_locexpr_baton
**baton
)
21850 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21851 struct comp_unit_head
*cu_header
= &cu
->header
;
21852 struct dwarf_block
*blk
;
21853 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21854 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21860 switch (attr
->form
)
21863 case DW_FORM_GNU_addr_index
:
21867 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21868 dwarf2_const_value_length_mismatch_complaint (name
,
21869 cu_header
->addr_size
,
21870 TYPE_LENGTH (type
));
21871 /* Symbols of this form are reasonably rare, so we just
21872 piggyback on the existing location code rather than writing
21873 a new implementation of symbol_computed_ops. */
21874 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21875 (*baton
)->per_cu
= cu
->per_cu
;
21876 gdb_assert ((*baton
)->per_cu
);
21878 (*baton
)->size
= 2 + cu_header
->addr_size
;
21879 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21880 (*baton
)->data
= data
;
21882 data
[0] = DW_OP_addr
;
21883 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21884 byte_order
, DW_ADDR (attr
));
21885 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21888 case DW_FORM_string
:
21890 case DW_FORM_GNU_str_index
:
21891 case DW_FORM_GNU_strp_alt
:
21892 /* DW_STRING is already allocated on the objfile obstack, point
21894 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21896 case DW_FORM_block1
:
21897 case DW_FORM_block2
:
21898 case DW_FORM_block4
:
21899 case DW_FORM_block
:
21900 case DW_FORM_exprloc
:
21901 case DW_FORM_data16
:
21902 blk
= DW_BLOCK (attr
);
21903 if (TYPE_LENGTH (type
) != blk
->size
)
21904 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21905 TYPE_LENGTH (type
));
21906 *bytes
= blk
->data
;
21909 /* The DW_AT_const_value attributes are supposed to carry the
21910 symbol's value "represented as it would be on the target
21911 architecture." By the time we get here, it's already been
21912 converted to host endianness, so we just need to sign- or
21913 zero-extend it as appropriate. */
21914 case DW_FORM_data1
:
21915 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21917 case DW_FORM_data2
:
21918 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21920 case DW_FORM_data4
:
21921 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21923 case DW_FORM_data8
:
21924 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21927 case DW_FORM_sdata
:
21928 case DW_FORM_implicit_const
:
21929 *value
= DW_SND (attr
);
21932 case DW_FORM_udata
:
21933 *value
= DW_UNSND (attr
);
21937 complaint (_("unsupported const value attribute form: '%s'"),
21938 dwarf_form_name (attr
->form
));
21945 /* Copy constant value from an attribute to a symbol. */
21948 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21949 struct dwarf2_cu
*cu
)
21951 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21953 const gdb_byte
*bytes
;
21954 struct dwarf2_locexpr_baton
*baton
;
21956 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21957 SYMBOL_PRINT_NAME (sym
),
21958 &objfile
->objfile_obstack
, cu
,
21959 &value
, &bytes
, &baton
);
21963 SYMBOL_LOCATION_BATON (sym
) = baton
;
21964 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21966 else if (bytes
!= NULL
)
21968 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21969 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21973 SYMBOL_VALUE (sym
) = value
;
21974 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21978 /* Return the type of the die in question using its DW_AT_type attribute. */
21980 static struct type
*
21981 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21983 struct attribute
*type_attr
;
21985 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21988 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21989 /* A missing DW_AT_type represents a void type. */
21990 return objfile_type (objfile
)->builtin_void
;
21993 return lookup_die_type (die
, type_attr
, cu
);
21996 /* True iff CU's producer generates GNAT Ada auxiliary information
21997 that allows to find parallel types through that information instead
21998 of having to do expensive parallel lookups by type name. */
22001 need_gnat_info (struct dwarf2_cu
*cu
)
22003 /* Assume that the Ada compiler was GNAT, which always produces
22004 the auxiliary information. */
22005 return (cu
->language
== language_ada
);
22008 /* Return the auxiliary type of the die in question using its
22009 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22010 attribute is not present. */
22012 static struct type
*
22013 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22015 struct attribute
*type_attr
;
22017 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22021 return lookup_die_type (die
, type_attr
, cu
);
22024 /* If DIE has a descriptive_type attribute, then set the TYPE's
22025 descriptive type accordingly. */
22028 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22029 struct dwarf2_cu
*cu
)
22031 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22033 if (descriptive_type
)
22035 ALLOCATE_GNAT_AUX_TYPE (type
);
22036 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22040 /* Return the containing type of the die in question using its
22041 DW_AT_containing_type attribute. */
22043 static struct type
*
22044 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22046 struct attribute
*type_attr
;
22047 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22049 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22051 error (_("Dwarf Error: Problem turning containing type into gdb type "
22052 "[in module %s]"), objfile_name (objfile
));
22054 return lookup_die_type (die
, type_attr
, cu
);
22057 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22059 static struct type
*
22060 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22062 struct dwarf2_per_objfile
*dwarf2_per_objfile
22063 = cu
->per_cu
->dwarf2_per_objfile
;
22064 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22067 std::string message
22068 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22069 objfile_name (objfile
),
22070 sect_offset_str (cu
->header
.sect_off
),
22071 sect_offset_str (die
->sect_off
));
22072 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
22073 message
.c_str (), message
.length ());
22075 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22078 /* Look up the type of DIE in CU using its type attribute ATTR.
22079 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22080 DW_AT_containing_type.
22081 If there is no type substitute an error marker. */
22083 static struct type
*
22084 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22085 struct dwarf2_cu
*cu
)
22087 struct dwarf2_per_objfile
*dwarf2_per_objfile
22088 = cu
->per_cu
->dwarf2_per_objfile
;
22089 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22090 struct type
*this_type
;
22092 gdb_assert (attr
->name
== DW_AT_type
22093 || attr
->name
== DW_AT_GNAT_descriptive_type
22094 || attr
->name
== DW_AT_containing_type
);
22096 /* First see if we have it cached. */
22098 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22100 struct dwarf2_per_cu_data
*per_cu
;
22101 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22103 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22104 dwarf2_per_objfile
);
22105 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22107 else if (attr_form_is_ref (attr
))
22109 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22111 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22113 else if (attr
->form
== DW_FORM_ref_sig8
)
22115 ULONGEST signature
= DW_SIGNATURE (attr
);
22117 return get_signatured_type (die
, signature
, cu
);
22121 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22122 " at %s [in module %s]"),
22123 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22124 objfile_name (objfile
));
22125 return build_error_marker_type (cu
, die
);
22128 /* If not cached we need to read it in. */
22130 if (this_type
== NULL
)
22132 struct die_info
*type_die
= NULL
;
22133 struct dwarf2_cu
*type_cu
= cu
;
22135 if (attr_form_is_ref (attr
))
22136 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22137 if (type_die
== NULL
)
22138 return build_error_marker_type (cu
, die
);
22139 /* If we find the type now, it's probably because the type came
22140 from an inter-CU reference and the type's CU got expanded before
22142 this_type
= read_type_die (type_die
, type_cu
);
22145 /* If we still don't have a type use an error marker. */
22147 if (this_type
== NULL
)
22148 return build_error_marker_type (cu
, die
);
22153 /* Return the type in DIE, CU.
22154 Returns NULL for invalid types.
22156 This first does a lookup in die_type_hash,
22157 and only reads the die in if necessary.
22159 NOTE: This can be called when reading in partial or full symbols. */
22161 static struct type
*
22162 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22164 struct type
*this_type
;
22166 this_type
= get_die_type (die
, cu
);
22170 return read_type_die_1 (die
, cu
);
22173 /* Read the type in DIE, CU.
22174 Returns NULL for invalid types. */
22176 static struct type
*
22177 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22179 struct type
*this_type
= NULL
;
22183 case DW_TAG_class_type
:
22184 case DW_TAG_interface_type
:
22185 case DW_TAG_structure_type
:
22186 case DW_TAG_union_type
:
22187 this_type
= read_structure_type (die
, cu
);
22189 case DW_TAG_enumeration_type
:
22190 this_type
= read_enumeration_type (die
, cu
);
22192 case DW_TAG_subprogram
:
22193 case DW_TAG_subroutine_type
:
22194 case DW_TAG_inlined_subroutine
:
22195 this_type
= read_subroutine_type (die
, cu
);
22197 case DW_TAG_array_type
:
22198 this_type
= read_array_type (die
, cu
);
22200 case DW_TAG_set_type
:
22201 this_type
= read_set_type (die
, cu
);
22203 case DW_TAG_pointer_type
:
22204 this_type
= read_tag_pointer_type (die
, cu
);
22206 case DW_TAG_ptr_to_member_type
:
22207 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22209 case DW_TAG_reference_type
:
22210 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22212 case DW_TAG_rvalue_reference_type
:
22213 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22215 case DW_TAG_const_type
:
22216 this_type
= read_tag_const_type (die
, cu
);
22218 case DW_TAG_volatile_type
:
22219 this_type
= read_tag_volatile_type (die
, cu
);
22221 case DW_TAG_restrict_type
:
22222 this_type
= read_tag_restrict_type (die
, cu
);
22224 case DW_TAG_string_type
:
22225 this_type
= read_tag_string_type (die
, cu
);
22227 case DW_TAG_typedef
:
22228 this_type
= read_typedef (die
, cu
);
22230 case DW_TAG_subrange_type
:
22231 this_type
= read_subrange_type (die
, cu
);
22233 case DW_TAG_base_type
:
22234 this_type
= read_base_type (die
, cu
);
22236 case DW_TAG_unspecified_type
:
22237 this_type
= read_unspecified_type (die
, cu
);
22239 case DW_TAG_namespace
:
22240 this_type
= read_namespace_type (die
, cu
);
22242 case DW_TAG_module
:
22243 this_type
= read_module_type (die
, cu
);
22245 case DW_TAG_atomic_type
:
22246 this_type
= read_tag_atomic_type (die
, cu
);
22249 complaint (_("unexpected tag in read_type_die: '%s'"),
22250 dwarf_tag_name (die
->tag
));
22257 /* See if we can figure out if the class lives in a namespace. We do
22258 this by looking for a member function; its demangled name will
22259 contain namespace info, if there is any.
22260 Return the computed name or NULL.
22261 Space for the result is allocated on the objfile's obstack.
22262 This is the full-die version of guess_partial_die_structure_name.
22263 In this case we know DIE has no useful parent. */
22266 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22268 struct die_info
*spec_die
;
22269 struct dwarf2_cu
*spec_cu
;
22270 struct die_info
*child
;
22271 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22274 spec_die
= die_specification (die
, &spec_cu
);
22275 if (spec_die
!= NULL
)
22281 for (child
= die
->child
;
22283 child
= child
->sibling
)
22285 if (child
->tag
== DW_TAG_subprogram
)
22287 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22289 if (linkage_name
!= NULL
)
22292 = language_class_name_from_physname (cu
->language_defn
,
22296 if (actual_name
!= NULL
)
22298 const char *die_name
= dwarf2_name (die
, cu
);
22300 if (die_name
!= NULL
22301 && strcmp (die_name
, actual_name
) != 0)
22303 /* Strip off the class name from the full name.
22304 We want the prefix. */
22305 int die_name_len
= strlen (die_name
);
22306 int actual_name_len
= strlen (actual_name
);
22308 /* Test for '::' as a sanity check. */
22309 if (actual_name_len
> die_name_len
+ 2
22310 && actual_name
[actual_name_len
22311 - die_name_len
- 1] == ':')
22312 name
= (char *) obstack_copy0 (
22313 &objfile
->per_bfd
->storage_obstack
,
22314 actual_name
, actual_name_len
- die_name_len
- 2);
22317 xfree (actual_name
);
22326 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22327 prefix part in such case. See
22328 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22330 static const char *
22331 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22333 struct attribute
*attr
;
22336 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22337 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22340 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22343 attr
= dw2_linkage_name_attr (die
, cu
);
22344 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22347 /* dwarf2_name had to be already called. */
22348 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22350 /* Strip the base name, keep any leading namespaces/classes. */
22351 base
= strrchr (DW_STRING (attr
), ':');
22352 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22355 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22356 return (char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22358 &base
[-1] - DW_STRING (attr
));
22361 /* Return the name of the namespace/class that DIE is defined within,
22362 or "" if we can't tell. The caller should not xfree the result.
22364 For example, if we're within the method foo() in the following
22374 then determine_prefix on foo's die will return "N::C". */
22376 static const char *
22377 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22379 struct dwarf2_per_objfile
*dwarf2_per_objfile
22380 = cu
->per_cu
->dwarf2_per_objfile
;
22381 struct die_info
*parent
, *spec_die
;
22382 struct dwarf2_cu
*spec_cu
;
22383 struct type
*parent_type
;
22384 const char *retval
;
22386 if (cu
->language
!= language_cplus
22387 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22388 && cu
->language
!= language_rust
)
22391 retval
= anonymous_struct_prefix (die
, cu
);
22395 /* We have to be careful in the presence of DW_AT_specification.
22396 For example, with GCC 3.4, given the code
22400 // Definition of N::foo.
22404 then we'll have a tree of DIEs like this:
22406 1: DW_TAG_compile_unit
22407 2: DW_TAG_namespace // N
22408 3: DW_TAG_subprogram // declaration of N::foo
22409 4: DW_TAG_subprogram // definition of N::foo
22410 DW_AT_specification // refers to die #3
22412 Thus, when processing die #4, we have to pretend that we're in
22413 the context of its DW_AT_specification, namely the contex of die
22416 spec_die
= die_specification (die
, &spec_cu
);
22417 if (spec_die
== NULL
)
22418 parent
= die
->parent
;
22421 parent
= spec_die
->parent
;
22425 if (parent
== NULL
)
22427 else if (parent
->building_fullname
)
22430 const char *parent_name
;
22432 /* It has been seen on RealView 2.2 built binaries,
22433 DW_TAG_template_type_param types actually _defined_ as
22434 children of the parent class:
22437 template class <class Enum> Class{};
22438 Class<enum E> class_e;
22440 1: DW_TAG_class_type (Class)
22441 2: DW_TAG_enumeration_type (E)
22442 3: DW_TAG_enumerator (enum1:0)
22443 3: DW_TAG_enumerator (enum2:1)
22445 2: DW_TAG_template_type_param
22446 DW_AT_type DW_FORM_ref_udata (E)
22448 Besides being broken debug info, it can put GDB into an
22449 infinite loop. Consider:
22451 When we're building the full name for Class<E>, we'll start
22452 at Class, and go look over its template type parameters,
22453 finding E. We'll then try to build the full name of E, and
22454 reach here. We're now trying to build the full name of E,
22455 and look over the parent DIE for containing scope. In the
22456 broken case, if we followed the parent DIE of E, we'd again
22457 find Class, and once again go look at its template type
22458 arguments, etc., etc. Simply don't consider such parent die
22459 as source-level parent of this die (it can't be, the language
22460 doesn't allow it), and break the loop here. */
22461 name
= dwarf2_name (die
, cu
);
22462 parent_name
= dwarf2_name (parent
, cu
);
22463 complaint (_("template param type '%s' defined within parent '%s'"),
22464 name
? name
: "<unknown>",
22465 parent_name
? parent_name
: "<unknown>");
22469 switch (parent
->tag
)
22471 case DW_TAG_namespace
:
22472 parent_type
= read_type_die (parent
, cu
);
22473 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22474 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22475 Work around this problem here. */
22476 if (cu
->language
== language_cplus
22477 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22479 /* We give a name to even anonymous namespaces. */
22480 return TYPE_NAME (parent_type
);
22481 case DW_TAG_class_type
:
22482 case DW_TAG_interface_type
:
22483 case DW_TAG_structure_type
:
22484 case DW_TAG_union_type
:
22485 case DW_TAG_module
:
22486 parent_type
= read_type_die (parent
, cu
);
22487 if (TYPE_NAME (parent_type
) != NULL
)
22488 return TYPE_NAME (parent_type
);
22490 /* An anonymous structure is only allowed non-static data
22491 members; no typedefs, no member functions, et cetera.
22492 So it does not need a prefix. */
22494 case DW_TAG_compile_unit
:
22495 case DW_TAG_partial_unit
:
22496 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22497 if (cu
->language
== language_cplus
22498 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
22499 && die
->child
!= NULL
22500 && (die
->tag
== DW_TAG_class_type
22501 || die
->tag
== DW_TAG_structure_type
22502 || die
->tag
== DW_TAG_union_type
))
22504 char *name
= guess_full_die_structure_name (die
, cu
);
22509 case DW_TAG_enumeration_type
:
22510 parent_type
= read_type_die (parent
, cu
);
22511 if (TYPE_DECLARED_CLASS (parent_type
))
22513 if (TYPE_NAME (parent_type
) != NULL
)
22514 return TYPE_NAME (parent_type
);
22517 /* Fall through. */
22519 return determine_prefix (parent
, cu
);
22523 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22524 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22525 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22526 an obconcat, otherwise allocate storage for the result. The CU argument is
22527 used to determine the language and hence, the appropriate separator. */
22529 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22532 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22533 int physname
, struct dwarf2_cu
*cu
)
22535 const char *lead
= "";
22538 if (suffix
== NULL
|| suffix
[0] == '\0'
22539 || prefix
== NULL
|| prefix
[0] == '\0')
22541 else if (cu
->language
== language_d
)
22543 /* For D, the 'main' function could be defined in any module, but it
22544 should never be prefixed. */
22545 if (strcmp (suffix
, "D main") == 0)
22553 else if (cu
->language
== language_fortran
&& physname
)
22555 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22556 DW_AT_MIPS_linkage_name is preferred and used instead. */
22564 if (prefix
== NULL
)
22566 if (suffix
== NULL
)
22573 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22575 strcpy (retval
, lead
);
22576 strcat (retval
, prefix
);
22577 strcat (retval
, sep
);
22578 strcat (retval
, suffix
);
22583 /* We have an obstack. */
22584 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22588 /* Return sibling of die, NULL if no sibling. */
22590 static struct die_info
*
22591 sibling_die (struct die_info
*die
)
22593 return die
->sibling
;
22596 /* Get name of a die, return NULL if not found. */
22598 static const char *
22599 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22600 struct obstack
*obstack
)
22602 if (name
&& cu
->language
== language_cplus
)
22604 std::string canon_name
= cp_canonicalize_string (name
);
22606 if (!canon_name
.empty ())
22608 if (canon_name
!= name
)
22609 name
= (const char *) obstack_copy0 (obstack
,
22610 canon_name
.c_str (),
22611 canon_name
.length ());
22618 /* Get name of a die, return NULL if not found.
22619 Anonymous namespaces are converted to their magic string. */
22621 static const char *
22622 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22624 struct attribute
*attr
;
22625 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22627 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22628 if ((!attr
|| !DW_STRING (attr
))
22629 && die
->tag
!= DW_TAG_namespace
22630 && die
->tag
!= DW_TAG_class_type
22631 && die
->tag
!= DW_TAG_interface_type
22632 && die
->tag
!= DW_TAG_structure_type
22633 && die
->tag
!= DW_TAG_union_type
)
22638 case DW_TAG_compile_unit
:
22639 case DW_TAG_partial_unit
:
22640 /* Compilation units have a DW_AT_name that is a filename, not
22641 a source language identifier. */
22642 case DW_TAG_enumeration_type
:
22643 case DW_TAG_enumerator
:
22644 /* These tags always have simple identifiers already; no need
22645 to canonicalize them. */
22646 return DW_STRING (attr
);
22648 case DW_TAG_namespace
:
22649 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22650 return DW_STRING (attr
);
22651 return CP_ANONYMOUS_NAMESPACE_STR
;
22653 case DW_TAG_class_type
:
22654 case DW_TAG_interface_type
:
22655 case DW_TAG_structure_type
:
22656 case DW_TAG_union_type
:
22657 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22658 structures or unions. These were of the form "._%d" in GCC 4.1,
22659 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22660 and GCC 4.4. We work around this problem by ignoring these. */
22661 if (attr
&& DW_STRING (attr
)
22662 && (startswith (DW_STRING (attr
), "._")
22663 || startswith (DW_STRING (attr
), "<anonymous")))
22666 /* GCC might emit a nameless typedef that has a linkage name. See
22667 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22668 if (!attr
|| DW_STRING (attr
) == NULL
)
22670 char *demangled
= NULL
;
22672 attr
= dw2_linkage_name_attr (die
, cu
);
22673 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22676 /* Avoid demangling DW_STRING (attr) the second time on a second
22677 call for the same DIE. */
22678 if (!DW_STRING_IS_CANONICAL (attr
))
22679 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22685 /* FIXME: we already did this for the partial symbol... */
22688 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22689 demangled
, strlen (demangled
)));
22690 DW_STRING_IS_CANONICAL (attr
) = 1;
22693 /* Strip any leading namespaces/classes, keep only the base name.
22694 DW_AT_name for named DIEs does not contain the prefixes. */
22695 base
= strrchr (DW_STRING (attr
), ':');
22696 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22699 return DW_STRING (attr
);
22708 if (!DW_STRING_IS_CANONICAL (attr
))
22711 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22712 &objfile
->per_bfd
->storage_obstack
);
22713 DW_STRING_IS_CANONICAL (attr
) = 1;
22715 return DW_STRING (attr
);
22718 /* Return the die that this die in an extension of, or NULL if there
22719 is none. *EXT_CU is the CU containing DIE on input, and the CU
22720 containing the return value on output. */
22722 static struct die_info
*
22723 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22725 struct attribute
*attr
;
22727 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22731 return follow_die_ref (die
, attr
, ext_cu
);
22734 /* Convert a DIE tag into its string name. */
22736 static const char *
22737 dwarf_tag_name (unsigned tag
)
22739 const char *name
= get_DW_TAG_name (tag
);
22742 return "DW_TAG_<unknown>";
22747 /* Convert a DWARF attribute code into its string name. */
22749 static const char *
22750 dwarf_attr_name (unsigned attr
)
22754 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22755 if (attr
== DW_AT_MIPS_fde
)
22756 return "DW_AT_MIPS_fde";
22758 if (attr
== DW_AT_HP_block_index
)
22759 return "DW_AT_HP_block_index";
22762 name
= get_DW_AT_name (attr
);
22765 return "DW_AT_<unknown>";
22770 /* Convert a DWARF value form code into its string name. */
22772 static const char *
22773 dwarf_form_name (unsigned form
)
22775 const char *name
= get_DW_FORM_name (form
);
22778 return "DW_FORM_<unknown>";
22783 static const char *
22784 dwarf_bool_name (unsigned mybool
)
22792 /* Convert a DWARF type code into its string name. */
22794 static const char *
22795 dwarf_type_encoding_name (unsigned enc
)
22797 const char *name
= get_DW_ATE_name (enc
);
22800 return "DW_ATE_<unknown>";
22806 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22810 print_spaces (indent
, f
);
22811 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22812 dwarf_tag_name (die
->tag
), die
->abbrev
,
22813 sect_offset_str (die
->sect_off
));
22815 if (die
->parent
!= NULL
)
22817 print_spaces (indent
, f
);
22818 fprintf_unfiltered (f
, " parent at offset: %s\n",
22819 sect_offset_str (die
->parent
->sect_off
));
22822 print_spaces (indent
, f
);
22823 fprintf_unfiltered (f
, " has children: %s\n",
22824 dwarf_bool_name (die
->child
!= NULL
));
22826 print_spaces (indent
, f
);
22827 fprintf_unfiltered (f
, " attributes:\n");
22829 for (i
= 0; i
< die
->num_attrs
; ++i
)
22831 print_spaces (indent
, f
);
22832 fprintf_unfiltered (f
, " %s (%s) ",
22833 dwarf_attr_name (die
->attrs
[i
].name
),
22834 dwarf_form_name (die
->attrs
[i
].form
));
22836 switch (die
->attrs
[i
].form
)
22839 case DW_FORM_GNU_addr_index
:
22840 fprintf_unfiltered (f
, "address: ");
22841 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22843 case DW_FORM_block2
:
22844 case DW_FORM_block4
:
22845 case DW_FORM_block
:
22846 case DW_FORM_block1
:
22847 fprintf_unfiltered (f
, "block: size %s",
22848 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22850 case DW_FORM_exprloc
:
22851 fprintf_unfiltered (f
, "expression: size %s",
22852 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22854 case DW_FORM_data16
:
22855 fprintf_unfiltered (f
, "constant of 16 bytes");
22857 case DW_FORM_ref_addr
:
22858 fprintf_unfiltered (f
, "ref address: ");
22859 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22861 case DW_FORM_GNU_ref_alt
:
22862 fprintf_unfiltered (f
, "alt ref address: ");
22863 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22869 case DW_FORM_ref_udata
:
22870 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22871 (long) (DW_UNSND (&die
->attrs
[i
])));
22873 case DW_FORM_data1
:
22874 case DW_FORM_data2
:
22875 case DW_FORM_data4
:
22876 case DW_FORM_data8
:
22877 case DW_FORM_udata
:
22878 case DW_FORM_sdata
:
22879 fprintf_unfiltered (f
, "constant: %s",
22880 pulongest (DW_UNSND (&die
->attrs
[i
])));
22882 case DW_FORM_sec_offset
:
22883 fprintf_unfiltered (f
, "section offset: %s",
22884 pulongest (DW_UNSND (&die
->attrs
[i
])));
22886 case DW_FORM_ref_sig8
:
22887 fprintf_unfiltered (f
, "signature: %s",
22888 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22890 case DW_FORM_string
:
22892 case DW_FORM_line_strp
:
22893 case DW_FORM_GNU_str_index
:
22894 case DW_FORM_GNU_strp_alt
:
22895 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22896 DW_STRING (&die
->attrs
[i
])
22897 ? DW_STRING (&die
->attrs
[i
]) : "",
22898 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22901 if (DW_UNSND (&die
->attrs
[i
]))
22902 fprintf_unfiltered (f
, "flag: TRUE");
22904 fprintf_unfiltered (f
, "flag: FALSE");
22906 case DW_FORM_flag_present
:
22907 fprintf_unfiltered (f
, "flag: TRUE");
22909 case DW_FORM_indirect
:
22910 /* The reader will have reduced the indirect form to
22911 the "base form" so this form should not occur. */
22912 fprintf_unfiltered (f
,
22913 "unexpected attribute form: DW_FORM_indirect");
22915 case DW_FORM_implicit_const
:
22916 fprintf_unfiltered (f
, "constant: %s",
22917 plongest (DW_SND (&die
->attrs
[i
])));
22920 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22921 die
->attrs
[i
].form
);
22924 fprintf_unfiltered (f
, "\n");
22929 dump_die_for_error (struct die_info
*die
)
22931 dump_die_shallow (gdb_stderr
, 0, die
);
22935 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22937 int indent
= level
* 4;
22939 gdb_assert (die
!= NULL
);
22941 if (level
>= max_level
)
22944 dump_die_shallow (f
, indent
, die
);
22946 if (die
->child
!= NULL
)
22948 print_spaces (indent
, f
);
22949 fprintf_unfiltered (f
, " Children:");
22950 if (level
+ 1 < max_level
)
22952 fprintf_unfiltered (f
, "\n");
22953 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22957 fprintf_unfiltered (f
,
22958 " [not printed, max nesting level reached]\n");
22962 if (die
->sibling
!= NULL
&& level
> 0)
22964 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22968 /* This is called from the pdie macro in gdbinit.in.
22969 It's not static so gcc will keep a copy callable from gdb. */
22972 dump_die (struct die_info
*die
, int max_level
)
22974 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22978 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22982 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22983 to_underlying (die
->sect_off
),
22989 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22993 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22995 if (attr_form_is_ref (attr
))
22996 return (sect_offset
) DW_UNSND (attr
);
22998 complaint (_("unsupported die ref attribute form: '%s'"),
22999 dwarf_form_name (attr
->form
));
23003 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23004 * the value held by the attribute is not constant. */
23007 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23009 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23010 return DW_SND (attr
);
23011 else if (attr
->form
== DW_FORM_udata
23012 || attr
->form
== DW_FORM_data1
23013 || attr
->form
== DW_FORM_data2
23014 || attr
->form
== DW_FORM_data4
23015 || attr
->form
== DW_FORM_data8
)
23016 return DW_UNSND (attr
);
23019 /* For DW_FORM_data16 see attr_form_is_constant. */
23020 complaint (_("Attribute value is not a constant (%s)"),
23021 dwarf_form_name (attr
->form
));
23022 return default_value
;
23026 /* Follow reference or signature attribute ATTR of SRC_DIE.
23027 On entry *REF_CU is the CU of SRC_DIE.
23028 On exit *REF_CU is the CU of the result. */
23030 static struct die_info
*
23031 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23032 struct dwarf2_cu
**ref_cu
)
23034 struct die_info
*die
;
23036 if (attr_form_is_ref (attr
))
23037 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23038 else if (attr
->form
== DW_FORM_ref_sig8
)
23039 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23042 dump_die_for_error (src_die
);
23043 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23044 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23050 /* Follow reference OFFSET.
23051 On entry *REF_CU is the CU of the source die referencing OFFSET.
23052 On exit *REF_CU is the CU of the result.
23053 Returns NULL if OFFSET is invalid. */
23055 static struct die_info
*
23056 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23057 struct dwarf2_cu
**ref_cu
)
23059 struct die_info temp_die
;
23060 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23061 struct dwarf2_per_objfile
*dwarf2_per_objfile
23062 = cu
->per_cu
->dwarf2_per_objfile
;
23064 gdb_assert (cu
->per_cu
!= NULL
);
23068 if (cu
->per_cu
->is_debug_types
)
23070 /* .debug_types CUs cannot reference anything outside their CU.
23071 If they need to, they have to reference a signatured type via
23072 DW_FORM_ref_sig8. */
23073 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23076 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23077 || !offset_in_cu_p (&cu
->header
, sect_off
))
23079 struct dwarf2_per_cu_data
*per_cu
;
23081 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23082 dwarf2_per_objfile
);
23084 /* If necessary, add it to the queue and load its DIEs. */
23085 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23086 load_full_comp_unit (per_cu
, false, cu
->language
);
23088 target_cu
= per_cu
->cu
;
23090 else if (cu
->dies
== NULL
)
23092 /* We're loading full DIEs during partial symbol reading. */
23093 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23094 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23097 *ref_cu
= target_cu
;
23098 temp_die
.sect_off
= sect_off
;
23100 if (target_cu
!= cu
)
23101 target_cu
->ancestor
= cu
;
23103 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23105 to_underlying (sect_off
));
23108 /* Follow reference attribute ATTR of SRC_DIE.
23109 On entry *REF_CU is the CU of SRC_DIE.
23110 On exit *REF_CU is the CU of the result. */
23112 static struct die_info
*
23113 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23114 struct dwarf2_cu
**ref_cu
)
23116 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23117 struct dwarf2_cu
*cu
= *ref_cu
;
23118 struct die_info
*die
;
23120 die
= follow_die_offset (sect_off
,
23121 (attr
->form
== DW_FORM_GNU_ref_alt
23122 || cu
->per_cu
->is_dwz
),
23125 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23126 "at %s [in module %s]"),
23127 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23128 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23133 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23134 Returned value is intended for DW_OP_call*. Returned
23135 dwarf2_locexpr_baton->data has lifetime of
23136 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23138 struct dwarf2_locexpr_baton
23139 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23140 struct dwarf2_per_cu_data
*per_cu
,
23141 CORE_ADDR (*get_frame_pc
) (void *baton
),
23142 void *baton
, bool resolve_abstract_p
)
23144 struct dwarf2_cu
*cu
;
23145 struct die_info
*die
;
23146 struct attribute
*attr
;
23147 struct dwarf2_locexpr_baton retval
;
23148 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23149 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23151 if (per_cu
->cu
== NULL
)
23152 load_cu (per_cu
, false);
23156 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23157 Instead just throw an error, not much else we can do. */
23158 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23159 sect_offset_str (sect_off
), objfile_name (objfile
));
23162 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23164 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23165 sect_offset_str (sect_off
), objfile_name (objfile
));
23167 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23168 if (!attr
&& resolve_abstract_p
23169 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
)
23170 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23172 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23174 for (const auto &cand
: dwarf2_per_objfile
->abstract_to_concrete
[die
])
23177 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23180 CORE_ADDR pc_low
, pc_high
;
23181 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23182 if (pc_low
== ((CORE_ADDR
) -1)
23183 || !(pc_low
<= pc
&& pc
< pc_high
))
23187 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23194 /* DWARF: "If there is no such attribute, then there is no effect.".
23195 DATA is ignored if SIZE is 0. */
23197 retval
.data
= NULL
;
23200 else if (attr_form_is_section_offset (attr
))
23202 struct dwarf2_loclist_baton loclist_baton
;
23203 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23206 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23208 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23210 retval
.size
= size
;
23214 if (!attr_form_is_block (attr
))
23215 error (_("Dwarf Error: DIE at %s referenced in module %s "
23216 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23217 sect_offset_str (sect_off
), objfile_name (objfile
));
23219 retval
.data
= DW_BLOCK (attr
)->data
;
23220 retval
.size
= DW_BLOCK (attr
)->size
;
23222 retval
.per_cu
= cu
->per_cu
;
23224 age_cached_comp_units (dwarf2_per_objfile
);
23229 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23232 struct dwarf2_locexpr_baton
23233 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23234 struct dwarf2_per_cu_data
*per_cu
,
23235 CORE_ADDR (*get_frame_pc
) (void *baton
),
23238 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23240 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23243 /* Write a constant of a given type as target-ordered bytes into
23246 static const gdb_byte
*
23247 write_constant_as_bytes (struct obstack
*obstack
,
23248 enum bfd_endian byte_order
,
23255 *len
= TYPE_LENGTH (type
);
23256 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23257 store_unsigned_integer (result
, *len
, byte_order
, value
);
23262 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23263 pointer to the constant bytes and set LEN to the length of the
23264 data. If memory is needed, allocate it on OBSTACK. If the DIE
23265 does not have a DW_AT_const_value, return NULL. */
23268 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23269 struct dwarf2_per_cu_data
*per_cu
,
23270 struct obstack
*obstack
,
23273 struct dwarf2_cu
*cu
;
23274 struct die_info
*die
;
23275 struct attribute
*attr
;
23276 const gdb_byte
*result
= NULL
;
23279 enum bfd_endian byte_order
;
23280 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23282 if (per_cu
->cu
== NULL
)
23283 load_cu (per_cu
, false);
23287 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23288 Instead just throw an error, not much else we can do. */
23289 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23290 sect_offset_str (sect_off
), objfile_name (objfile
));
23293 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23295 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23296 sect_offset_str (sect_off
), objfile_name (objfile
));
23298 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23302 byte_order
= (bfd_big_endian (objfile
->obfd
)
23303 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23305 switch (attr
->form
)
23308 case DW_FORM_GNU_addr_index
:
23312 *len
= cu
->header
.addr_size
;
23313 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23314 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23318 case DW_FORM_string
:
23320 case DW_FORM_GNU_str_index
:
23321 case DW_FORM_GNU_strp_alt
:
23322 /* DW_STRING is already allocated on the objfile obstack, point
23324 result
= (const gdb_byte
*) DW_STRING (attr
);
23325 *len
= strlen (DW_STRING (attr
));
23327 case DW_FORM_block1
:
23328 case DW_FORM_block2
:
23329 case DW_FORM_block4
:
23330 case DW_FORM_block
:
23331 case DW_FORM_exprloc
:
23332 case DW_FORM_data16
:
23333 result
= DW_BLOCK (attr
)->data
;
23334 *len
= DW_BLOCK (attr
)->size
;
23337 /* The DW_AT_const_value attributes are supposed to carry the
23338 symbol's value "represented as it would be on the target
23339 architecture." By the time we get here, it's already been
23340 converted to host endianness, so we just need to sign- or
23341 zero-extend it as appropriate. */
23342 case DW_FORM_data1
:
23343 type
= die_type (die
, cu
);
23344 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23345 if (result
== NULL
)
23346 result
= write_constant_as_bytes (obstack
, byte_order
,
23349 case DW_FORM_data2
:
23350 type
= die_type (die
, cu
);
23351 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23352 if (result
== NULL
)
23353 result
= write_constant_as_bytes (obstack
, byte_order
,
23356 case DW_FORM_data4
:
23357 type
= die_type (die
, cu
);
23358 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23359 if (result
== NULL
)
23360 result
= write_constant_as_bytes (obstack
, byte_order
,
23363 case DW_FORM_data8
:
23364 type
= die_type (die
, cu
);
23365 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23366 if (result
== NULL
)
23367 result
= write_constant_as_bytes (obstack
, byte_order
,
23371 case DW_FORM_sdata
:
23372 case DW_FORM_implicit_const
:
23373 type
= die_type (die
, cu
);
23374 result
= write_constant_as_bytes (obstack
, byte_order
,
23375 type
, DW_SND (attr
), len
);
23378 case DW_FORM_udata
:
23379 type
= die_type (die
, cu
);
23380 result
= write_constant_as_bytes (obstack
, byte_order
,
23381 type
, DW_UNSND (attr
), len
);
23385 complaint (_("unsupported const value attribute form: '%s'"),
23386 dwarf_form_name (attr
->form
));
23393 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23394 valid type for this die is found. */
23397 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23398 struct dwarf2_per_cu_data
*per_cu
)
23400 struct dwarf2_cu
*cu
;
23401 struct die_info
*die
;
23403 if (per_cu
->cu
== NULL
)
23404 load_cu (per_cu
, false);
23409 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23413 return die_type (die
, cu
);
23416 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23420 dwarf2_get_die_type (cu_offset die_offset
,
23421 struct dwarf2_per_cu_data
*per_cu
)
23423 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23424 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23427 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23428 On entry *REF_CU is the CU of SRC_DIE.
23429 On exit *REF_CU is the CU of the result.
23430 Returns NULL if the referenced DIE isn't found. */
23432 static struct die_info
*
23433 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23434 struct dwarf2_cu
**ref_cu
)
23436 struct die_info temp_die
;
23437 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23438 struct die_info
*die
;
23440 /* While it might be nice to assert sig_type->type == NULL here,
23441 we can get here for DW_AT_imported_declaration where we need
23442 the DIE not the type. */
23444 /* If necessary, add it to the queue and load its DIEs. */
23446 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23447 read_signatured_type (sig_type
);
23449 sig_cu
= sig_type
->per_cu
.cu
;
23450 gdb_assert (sig_cu
!= NULL
);
23451 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23452 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23453 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23454 to_underlying (temp_die
.sect_off
));
23457 struct dwarf2_per_objfile
*dwarf2_per_objfile
23458 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23460 /* For .gdb_index version 7 keep track of included TUs.
23461 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23462 if (dwarf2_per_objfile
->index_table
!= NULL
23463 && dwarf2_per_objfile
->index_table
->version
<= 7)
23465 VEC_safe_push (dwarf2_per_cu_ptr
,
23466 (*ref_cu
)->per_cu
->imported_symtabs
,
23472 sig_cu
->ancestor
= cu
;
23480 /* Follow signatured type referenced by ATTR in SRC_DIE.
23481 On entry *REF_CU is the CU of SRC_DIE.
23482 On exit *REF_CU is the CU of the result.
23483 The result is the DIE of the type.
23484 If the referenced type cannot be found an error is thrown. */
23486 static struct die_info
*
23487 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23488 struct dwarf2_cu
**ref_cu
)
23490 ULONGEST signature
= DW_SIGNATURE (attr
);
23491 struct signatured_type
*sig_type
;
23492 struct die_info
*die
;
23494 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23496 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23497 /* sig_type will be NULL if the signatured type is missing from
23499 if (sig_type
== NULL
)
23501 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23502 " from DIE at %s [in module %s]"),
23503 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23504 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23507 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23510 dump_die_for_error (src_die
);
23511 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23512 " from DIE at %s [in module %s]"),
23513 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23514 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23520 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23521 reading in and processing the type unit if necessary. */
23523 static struct type
*
23524 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23525 struct dwarf2_cu
*cu
)
23527 struct dwarf2_per_objfile
*dwarf2_per_objfile
23528 = cu
->per_cu
->dwarf2_per_objfile
;
23529 struct signatured_type
*sig_type
;
23530 struct dwarf2_cu
*type_cu
;
23531 struct die_info
*type_die
;
23534 sig_type
= lookup_signatured_type (cu
, signature
);
23535 /* sig_type will be NULL if the signatured type is missing from
23537 if (sig_type
== NULL
)
23539 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23540 " from DIE at %s [in module %s]"),
23541 hex_string (signature
), sect_offset_str (die
->sect_off
),
23542 objfile_name (dwarf2_per_objfile
->objfile
));
23543 return build_error_marker_type (cu
, die
);
23546 /* If we already know the type we're done. */
23547 if (sig_type
->type
!= NULL
)
23548 return sig_type
->type
;
23551 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23552 if (type_die
!= NULL
)
23554 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23555 is created. This is important, for example, because for c++ classes
23556 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23557 type
= read_type_die (type_die
, type_cu
);
23560 complaint (_("Dwarf Error: Cannot build signatured type %s"
23561 " referenced from DIE at %s [in module %s]"),
23562 hex_string (signature
), sect_offset_str (die
->sect_off
),
23563 objfile_name (dwarf2_per_objfile
->objfile
));
23564 type
= build_error_marker_type (cu
, die
);
23569 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23570 " from DIE at %s [in module %s]"),
23571 hex_string (signature
), sect_offset_str (die
->sect_off
),
23572 objfile_name (dwarf2_per_objfile
->objfile
));
23573 type
= build_error_marker_type (cu
, die
);
23575 sig_type
->type
= type
;
23580 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23581 reading in and processing the type unit if necessary. */
23583 static struct type
*
23584 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23585 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23587 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23588 if (attr_form_is_ref (attr
))
23590 struct dwarf2_cu
*type_cu
= cu
;
23591 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23593 return read_type_die (type_die
, type_cu
);
23595 else if (attr
->form
== DW_FORM_ref_sig8
)
23597 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23601 struct dwarf2_per_objfile
*dwarf2_per_objfile
23602 = cu
->per_cu
->dwarf2_per_objfile
;
23604 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23605 " at %s [in module %s]"),
23606 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23607 objfile_name (dwarf2_per_objfile
->objfile
));
23608 return build_error_marker_type (cu
, die
);
23612 /* Load the DIEs associated with type unit PER_CU into memory. */
23615 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23617 struct signatured_type
*sig_type
;
23619 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23620 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23622 /* We have the per_cu, but we need the signatured_type.
23623 Fortunately this is an easy translation. */
23624 gdb_assert (per_cu
->is_debug_types
);
23625 sig_type
= (struct signatured_type
*) per_cu
;
23627 gdb_assert (per_cu
->cu
== NULL
);
23629 read_signatured_type (sig_type
);
23631 gdb_assert (per_cu
->cu
!= NULL
);
23634 /* die_reader_func for read_signatured_type.
23635 This is identical to load_full_comp_unit_reader,
23636 but is kept separate for now. */
23639 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23640 const gdb_byte
*info_ptr
,
23641 struct die_info
*comp_unit_die
,
23645 struct dwarf2_cu
*cu
= reader
->cu
;
23647 gdb_assert (cu
->die_hash
== NULL
);
23649 htab_create_alloc_ex (cu
->header
.length
/ 12,
23653 &cu
->comp_unit_obstack
,
23654 hashtab_obstack_allocate
,
23655 dummy_obstack_deallocate
);
23658 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23659 &info_ptr
, comp_unit_die
);
23660 cu
->dies
= comp_unit_die
;
23661 /* comp_unit_die is not stored in die_hash, no need. */
23663 /* We try not to read any attributes in this function, because not
23664 all CUs needed for references have been loaded yet, and symbol
23665 table processing isn't initialized. But we have to set the CU language,
23666 or we won't be able to build types correctly.
23667 Similarly, if we do not read the producer, we can not apply
23668 producer-specific interpretation. */
23669 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23672 /* Read in a signatured type and build its CU and DIEs.
23673 If the type is a stub for the real type in a DWO file,
23674 read in the real type from the DWO file as well. */
23677 read_signatured_type (struct signatured_type
*sig_type
)
23679 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23681 gdb_assert (per_cu
->is_debug_types
);
23682 gdb_assert (per_cu
->cu
== NULL
);
23684 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1, false,
23685 read_signatured_type_reader
, NULL
);
23686 sig_type
->per_cu
.tu_read
= 1;
23689 /* Decode simple location descriptions.
23690 Given a pointer to a dwarf block that defines a location, compute
23691 the location and return the value.
23693 NOTE drow/2003-11-18: This function is called in two situations
23694 now: for the address of static or global variables (partial symbols
23695 only) and for offsets into structures which are expected to be
23696 (more or less) constant. The partial symbol case should go away,
23697 and only the constant case should remain. That will let this
23698 function complain more accurately. A few special modes are allowed
23699 without complaint for global variables (for instance, global
23700 register values and thread-local values).
23702 A location description containing no operations indicates that the
23703 object is optimized out. The return value is 0 for that case.
23704 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23705 callers will only want a very basic result and this can become a
23708 Note that stack[0] is unused except as a default error return. */
23711 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23713 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23715 size_t size
= blk
->size
;
23716 const gdb_byte
*data
= blk
->data
;
23717 CORE_ADDR stack
[64];
23719 unsigned int bytes_read
, unsnd
;
23725 stack
[++stacki
] = 0;
23764 stack
[++stacki
] = op
- DW_OP_lit0
;
23799 stack
[++stacki
] = op
- DW_OP_reg0
;
23801 dwarf2_complex_location_expr_complaint ();
23805 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23807 stack
[++stacki
] = unsnd
;
23809 dwarf2_complex_location_expr_complaint ();
23813 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
23818 case DW_OP_const1u
:
23819 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23823 case DW_OP_const1s
:
23824 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23828 case DW_OP_const2u
:
23829 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23833 case DW_OP_const2s
:
23834 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23838 case DW_OP_const4u
:
23839 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23843 case DW_OP_const4s
:
23844 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23848 case DW_OP_const8u
:
23849 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23854 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23860 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23865 stack
[stacki
+ 1] = stack
[stacki
];
23870 stack
[stacki
- 1] += stack
[stacki
];
23874 case DW_OP_plus_uconst
:
23875 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23881 stack
[stacki
- 1] -= stack
[stacki
];
23886 /* If we're not the last op, then we definitely can't encode
23887 this using GDB's address_class enum. This is valid for partial
23888 global symbols, although the variable's address will be bogus
23891 dwarf2_complex_location_expr_complaint ();
23894 case DW_OP_GNU_push_tls_address
:
23895 case DW_OP_form_tls_address
:
23896 /* The top of the stack has the offset from the beginning
23897 of the thread control block at which the variable is located. */
23898 /* Nothing should follow this operator, so the top of stack would
23900 /* This is valid for partial global symbols, but the variable's
23901 address will be bogus in the psymtab. Make it always at least
23902 non-zero to not look as a variable garbage collected by linker
23903 which have DW_OP_addr 0. */
23905 dwarf2_complex_location_expr_complaint ();
23909 case DW_OP_GNU_uninit
:
23912 case DW_OP_GNU_addr_index
:
23913 case DW_OP_GNU_const_index
:
23914 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23921 const char *name
= get_DW_OP_name (op
);
23924 complaint (_("unsupported stack op: '%s'"),
23927 complaint (_("unsupported stack op: '%02x'"),
23931 return (stack
[stacki
]);
23934 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23935 outside of the allocated space. Also enforce minimum>0. */
23936 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23938 complaint (_("location description stack overflow"));
23944 complaint (_("location description stack underflow"));
23948 return (stack
[stacki
]);
23951 /* memory allocation interface */
23953 static struct dwarf_block
*
23954 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23956 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23959 static struct die_info
*
23960 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23962 struct die_info
*die
;
23963 size_t size
= sizeof (struct die_info
);
23966 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23968 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23969 memset (die
, 0, sizeof (struct die_info
));
23974 /* Macro support. */
23976 /* Return file name relative to the compilation directory of file number I in
23977 *LH's file name table. The result is allocated using xmalloc; the caller is
23978 responsible for freeing it. */
23981 file_file_name (int file
, struct line_header
*lh
)
23983 /* Is the file number a valid index into the line header's file name
23984 table? Remember that file numbers start with one, not zero. */
23985 if (1 <= file
&& file
<= lh
->file_names
.size ())
23987 const file_entry
&fe
= lh
->file_names
[file
- 1];
23989 if (!IS_ABSOLUTE_PATH (fe
.name
))
23991 const char *dir
= fe
.include_dir (lh
);
23993 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
23995 return xstrdup (fe
.name
);
23999 /* The compiler produced a bogus file number. We can at least
24000 record the macro definitions made in the file, even if we
24001 won't be able to find the file by name. */
24002 char fake_name
[80];
24004 xsnprintf (fake_name
, sizeof (fake_name
),
24005 "<bad macro file number %d>", file
);
24007 complaint (_("bad file number in macro information (%d)"),
24010 return xstrdup (fake_name
);
24014 /* Return the full name of file number I in *LH's file name table.
24015 Use COMP_DIR as the name of the current directory of the
24016 compilation. The result is allocated using xmalloc; the caller is
24017 responsible for freeing it. */
24019 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24021 /* Is the file number a valid index into the line header's file name
24022 table? Remember that file numbers start with one, not zero. */
24023 if (1 <= file
&& file
<= lh
->file_names
.size ())
24025 char *relative
= file_file_name (file
, lh
);
24027 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24029 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24030 relative
, (char *) NULL
);
24033 return file_file_name (file
, lh
);
24037 static struct macro_source_file
*
24038 macro_start_file (struct dwarf2_cu
*cu
,
24039 int file
, int line
,
24040 struct macro_source_file
*current_file
,
24041 struct line_header
*lh
)
24043 /* File name relative to the compilation directory of this source file. */
24044 char *file_name
= file_file_name (file
, lh
);
24046 if (! current_file
)
24048 /* Note: We don't create a macro table for this compilation unit
24049 at all until we actually get a filename. */
24050 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24052 /* If we have no current file, then this must be the start_file
24053 directive for the compilation unit's main source file. */
24054 current_file
= macro_set_main (macro_table
, file_name
);
24055 macro_define_special (macro_table
);
24058 current_file
= macro_include (current_file
, line
, file_name
);
24062 return current_file
;
24065 static const char *
24066 consume_improper_spaces (const char *p
, const char *body
)
24070 complaint (_("macro definition contains spaces "
24071 "in formal argument list:\n`%s'"),
24083 parse_macro_definition (struct macro_source_file
*file
, int line
,
24088 /* The body string takes one of two forms. For object-like macro
24089 definitions, it should be:
24091 <macro name> " " <definition>
24093 For function-like macro definitions, it should be:
24095 <macro name> "() " <definition>
24097 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24099 Spaces may appear only where explicitly indicated, and in the
24102 The Dwarf 2 spec says that an object-like macro's name is always
24103 followed by a space, but versions of GCC around March 2002 omit
24104 the space when the macro's definition is the empty string.
24106 The Dwarf 2 spec says that there should be no spaces between the
24107 formal arguments in a function-like macro's formal argument list,
24108 but versions of GCC around March 2002 include spaces after the
24112 /* Find the extent of the macro name. The macro name is terminated
24113 by either a space or null character (for an object-like macro) or
24114 an opening paren (for a function-like macro). */
24115 for (p
= body
; *p
; p
++)
24116 if (*p
== ' ' || *p
== '(')
24119 if (*p
== ' ' || *p
== '\0')
24121 /* It's an object-like macro. */
24122 int name_len
= p
- body
;
24123 char *name
= savestring (body
, name_len
);
24124 const char *replacement
;
24127 replacement
= body
+ name_len
+ 1;
24130 dwarf2_macro_malformed_definition_complaint (body
);
24131 replacement
= body
+ name_len
;
24134 macro_define_object (file
, line
, name
, replacement
);
24138 else if (*p
== '(')
24140 /* It's a function-like macro. */
24141 char *name
= savestring (body
, p
- body
);
24144 char **argv
= XNEWVEC (char *, argv_size
);
24148 p
= consume_improper_spaces (p
, body
);
24150 /* Parse the formal argument list. */
24151 while (*p
&& *p
!= ')')
24153 /* Find the extent of the current argument name. */
24154 const char *arg_start
= p
;
24156 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24159 if (! *p
|| p
== arg_start
)
24160 dwarf2_macro_malformed_definition_complaint (body
);
24163 /* Make sure argv has room for the new argument. */
24164 if (argc
>= argv_size
)
24167 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24170 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24173 p
= consume_improper_spaces (p
, body
);
24175 /* Consume the comma, if present. */
24180 p
= consume_improper_spaces (p
, body
);
24189 /* Perfectly formed definition, no complaints. */
24190 macro_define_function (file
, line
, name
,
24191 argc
, (const char **) argv
,
24193 else if (*p
== '\0')
24195 /* Complain, but do define it. */
24196 dwarf2_macro_malformed_definition_complaint (body
);
24197 macro_define_function (file
, line
, name
,
24198 argc
, (const char **) argv
,
24202 /* Just complain. */
24203 dwarf2_macro_malformed_definition_complaint (body
);
24206 /* Just complain. */
24207 dwarf2_macro_malformed_definition_complaint (body
);
24213 for (i
= 0; i
< argc
; i
++)
24219 dwarf2_macro_malformed_definition_complaint (body
);
24222 /* Skip some bytes from BYTES according to the form given in FORM.
24223 Returns the new pointer. */
24225 static const gdb_byte
*
24226 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24227 enum dwarf_form form
,
24228 unsigned int offset_size
,
24229 struct dwarf2_section_info
*section
)
24231 unsigned int bytes_read
;
24235 case DW_FORM_data1
:
24240 case DW_FORM_data2
:
24244 case DW_FORM_data4
:
24248 case DW_FORM_data8
:
24252 case DW_FORM_data16
:
24256 case DW_FORM_string
:
24257 read_direct_string (abfd
, bytes
, &bytes_read
);
24258 bytes
+= bytes_read
;
24261 case DW_FORM_sec_offset
:
24263 case DW_FORM_GNU_strp_alt
:
24264 bytes
+= offset_size
;
24267 case DW_FORM_block
:
24268 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24269 bytes
+= bytes_read
;
24272 case DW_FORM_block1
:
24273 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24275 case DW_FORM_block2
:
24276 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24278 case DW_FORM_block4
:
24279 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24282 case DW_FORM_sdata
:
24283 case DW_FORM_udata
:
24284 case DW_FORM_GNU_addr_index
:
24285 case DW_FORM_GNU_str_index
:
24286 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24289 dwarf2_section_buffer_overflow_complaint (section
);
24294 case DW_FORM_implicit_const
:
24299 complaint (_("invalid form 0x%x in `%s'"),
24300 form
, get_section_name (section
));
24308 /* A helper for dwarf_decode_macros that handles skipping an unknown
24309 opcode. Returns an updated pointer to the macro data buffer; or,
24310 on error, issues a complaint and returns NULL. */
24312 static const gdb_byte
*
24313 skip_unknown_opcode (unsigned int opcode
,
24314 const gdb_byte
**opcode_definitions
,
24315 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24317 unsigned int offset_size
,
24318 struct dwarf2_section_info
*section
)
24320 unsigned int bytes_read
, i
;
24322 const gdb_byte
*defn
;
24324 if (opcode_definitions
[opcode
] == NULL
)
24326 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24331 defn
= opcode_definitions
[opcode
];
24332 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24333 defn
+= bytes_read
;
24335 for (i
= 0; i
< arg
; ++i
)
24337 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24338 (enum dwarf_form
) defn
[i
], offset_size
,
24340 if (mac_ptr
== NULL
)
24342 /* skip_form_bytes already issued the complaint. */
24350 /* A helper function which parses the header of a macro section.
24351 If the macro section is the extended (for now called "GNU") type,
24352 then this updates *OFFSET_SIZE. Returns a pointer to just after
24353 the header, or issues a complaint and returns NULL on error. */
24355 static const gdb_byte
*
24356 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24358 const gdb_byte
*mac_ptr
,
24359 unsigned int *offset_size
,
24360 int section_is_gnu
)
24362 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24364 if (section_is_gnu
)
24366 unsigned int version
, flags
;
24368 version
= read_2_bytes (abfd
, mac_ptr
);
24369 if (version
!= 4 && version
!= 5)
24371 complaint (_("unrecognized version `%d' in .debug_macro section"),
24377 flags
= read_1_byte (abfd
, mac_ptr
);
24379 *offset_size
= (flags
& 1) ? 8 : 4;
24381 if ((flags
& 2) != 0)
24382 /* We don't need the line table offset. */
24383 mac_ptr
+= *offset_size
;
24385 /* Vendor opcode descriptions. */
24386 if ((flags
& 4) != 0)
24388 unsigned int i
, count
;
24390 count
= read_1_byte (abfd
, mac_ptr
);
24392 for (i
= 0; i
< count
; ++i
)
24394 unsigned int opcode
, bytes_read
;
24397 opcode
= read_1_byte (abfd
, mac_ptr
);
24399 opcode_definitions
[opcode
] = mac_ptr
;
24400 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24401 mac_ptr
+= bytes_read
;
24410 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24411 including DW_MACRO_import. */
24414 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24416 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24417 struct macro_source_file
*current_file
,
24418 struct line_header
*lh
,
24419 struct dwarf2_section_info
*section
,
24420 int section_is_gnu
, int section_is_dwz
,
24421 unsigned int offset_size
,
24422 htab_t include_hash
)
24424 struct dwarf2_per_objfile
*dwarf2_per_objfile
24425 = cu
->per_cu
->dwarf2_per_objfile
;
24426 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24427 enum dwarf_macro_record_type macinfo_type
;
24428 int at_commandline
;
24429 const gdb_byte
*opcode_definitions
[256];
24431 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24432 &offset_size
, section_is_gnu
);
24433 if (mac_ptr
== NULL
)
24435 /* We already issued a complaint. */
24439 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24440 GDB is still reading the definitions from command line. First
24441 DW_MACINFO_start_file will need to be ignored as it was already executed
24442 to create CURRENT_FILE for the main source holding also the command line
24443 definitions. On first met DW_MACINFO_start_file this flag is reset to
24444 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24446 at_commandline
= 1;
24450 /* Do we at least have room for a macinfo type byte? */
24451 if (mac_ptr
>= mac_end
)
24453 dwarf2_section_buffer_overflow_complaint (section
);
24457 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24460 /* Note that we rely on the fact that the corresponding GNU and
24461 DWARF constants are the same. */
24463 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24464 switch (macinfo_type
)
24466 /* A zero macinfo type indicates the end of the macro
24471 case DW_MACRO_define
:
24472 case DW_MACRO_undef
:
24473 case DW_MACRO_define_strp
:
24474 case DW_MACRO_undef_strp
:
24475 case DW_MACRO_define_sup
:
24476 case DW_MACRO_undef_sup
:
24478 unsigned int bytes_read
;
24483 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24484 mac_ptr
+= bytes_read
;
24486 if (macinfo_type
== DW_MACRO_define
24487 || macinfo_type
== DW_MACRO_undef
)
24489 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24490 mac_ptr
+= bytes_read
;
24494 LONGEST str_offset
;
24496 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24497 mac_ptr
+= offset_size
;
24499 if (macinfo_type
== DW_MACRO_define_sup
24500 || macinfo_type
== DW_MACRO_undef_sup
24503 struct dwz_file
*dwz
24504 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24506 body
= read_indirect_string_from_dwz (objfile
,
24510 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24514 is_define
= (macinfo_type
== DW_MACRO_define
24515 || macinfo_type
== DW_MACRO_define_strp
24516 || macinfo_type
== DW_MACRO_define_sup
);
24517 if (! current_file
)
24519 /* DWARF violation as no main source is present. */
24520 complaint (_("debug info with no main source gives macro %s "
24522 is_define
? _("definition") : _("undefinition"),
24526 if ((line
== 0 && !at_commandline
)
24527 || (line
!= 0 && at_commandline
))
24528 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
24529 at_commandline
? _("command-line") : _("in-file"),
24530 is_define
? _("definition") : _("undefinition"),
24531 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24534 parse_macro_definition (current_file
, line
, body
);
24537 gdb_assert (macinfo_type
== DW_MACRO_undef
24538 || macinfo_type
== DW_MACRO_undef_strp
24539 || macinfo_type
== DW_MACRO_undef_sup
);
24540 macro_undef (current_file
, line
, body
);
24545 case DW_MACRO_start_file
:
24547 unsigned int bytes_read
;
24550 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24551 mac_ptr
+= bytes_read
;
24552 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24553 mac_ptr
+= bytes_read
;
24555 if ((line
== 0 && !at_commandline
)
24556 || (line
!= 0 && at_commandline
))
24557 complaint (_("debug info gives source %d included "
24558 "from %s at %s line %d"),
24559 file
, at_commandline
? _("command-line") : _("file"),
24560 line
== 0 ? _("zero") : _("non-zero"), line
);
24562 if (at_commandline
)
24564 /* This DW_MACRO_start_file was executed in the
24566 at_commandline
= 0;
24569 current_file
= macro_start_file (cu
, file
, line
, current_file
,
24574 case DW_MACRO_end_file
:
24575 if (! current_file
)
24576 complaint (_("macro debug info has an unmatched "
24577 "`close_file' directive"));
24580 current_file
= current_file
->included_by
;
24581 if (! current_file
)
24583 enum dwarf_macro_record_type next_type
;
24585 /* GCC circa March 2002 doesn't produce the zero
24586 type byte marking the end of the compilation
24587 unit. Complain if it's not there, but exit no
24590 /* Do we at least have room for a macinfo type byte? */
24591 if (mac_ptr
>= mac_end
)
24593 dwarf2_section_buffer_overflow_complaint (section
);
24597 /* We don't increment mac_ptr here, so this is just
24600 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24602 if (next_type
!= 0)
24603 complaint (_("no terminating 0-type entry for "
24604 "macros in `.debug_macinfo' section"));
24611 case DW_MACRO_import
:
24612 case DW_MACRO_import_sup
:
24616 bfd
*include_bfd
= abfd
;
24617 struct dwarf2_section_info
*include_section
= section
;
24618 const gdb_byte
*include_mac_end
= mac_end
;
24619 int is_dwz
= section_is_dwz
;
24620 const gdb_byte
*new_mac_ptr
;
24622 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24623 mac_ptr
+= offset_size
;
24625 if (macinfo_type
== DW_MACRO_import_sup
)
24627 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24629 dwarf2_read_section (objfile
, &dwz
->macro
);
24631 include_section
= &dwz
->macro
;
24632 include_bfd
= get_section_bfd_owner (include_section
);
24633 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24637 new_mac_ptr
= include_section
->buffer
+ offset
;
24638 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24642 /* This has actually happened; see
24643 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24644 complaint (_("recursive DW_MACRO_import in "
24645 ".debug_macro section"));
24649 *slot
= (void *) new_mac_ptr
;
24651 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
24652 include_mac_end
, current_file
, lh
,
24653 section
, section_is_gnu
, is_dwz
,
24654 offset_size
, include_hash
);
24656 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24661 case DW_MACINFO_vendor_ext
:
24662 if (!section_is_gnu
)
24664 unsigned int bytes_read
;
24666 /* This reads the constant, but since we don't recognize
24667 any vendor extensions, we ignore it. */
24668 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24669 mac_ptr
+= bytes_read
;
24670 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24671 mac_ptr
+= bytes_read
;
24673 /* We don't recognize any vendor extensions. */
24679 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24680 mac_ptr
, mac_end
, abfd
, offset_size
,
24682 if (mac_ptr
== NULL
)
24687 } while (macinfo_type
!= 0);
24691 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24692 int section_is_gnu
)
24694 struct dwarf2_per_objfile
*dwarf2_per_objfile
24695 = cu
->per_cu
->dwarf2_per_objfile
;
24696 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24697 struct line_header
*lh
= cu
->line_header
;
24699 const gdb_byte
*mac_ptr
, *mac_end
;
24700 struct macro_source_file
*current_file
= 0;
24701 enum dwarf_macro_record_type macinfo_type
;
24702 unsigned int offset_size
= cu
->header
.offset_size
;
24703 const gdb_byte
*opcode_definitions
[256];
24705 struct dwarf2_section_info
*section
;
24706 const char *section_name
;
24708 if (cu
->dwo_unit
!= NULL
)
24710 if (section_is_gnu
)
24712 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24713 section_name
= ".debug_macro.dwo";
24717 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24718 section_name
= ".debug_macinfo.dwo";
24723 if (section_is_gnu
)
24725 section
= &dwarf2_per_objfile
->macro
;
24726 section_name
= ".debug_macro";
24730 section
= &dwarf2_per_objfile
->macinfo
;
24731 section_name
= ".debug_macinfo";
24735 dwarf2_read_section (objfile
, section
);
24736 if (section
->buffer
== NULL
)
24738 complaint (_("missing %s section"), section_name
);
24741 abfd
= get_section_bfd_owner (section
);
24743 /* First pass: Find the name of the base filename.
24744 This filename is needed in order to process all macros whose definition
24745 (or undefinition) comes from the command line. These macros are defined
24746 before the first DW_MACINFO_start_file entry, and yet still need to be
24747 associated to the base file.
24749 To determine the base file name, we scan the macro definitions until we
24750 reach the first DW_MACINFO_start_file entry. We then initialize
24751 CURRENT_FILE accordingly so that any macro definition found before the
24752 first DW_MACINFO_start_file can still be associated to the base file. */
24754 mac_ptr
= section
->buffer
+ offset
;
24755 mac_end
= section
->buffer
+ section
->size
;
24757 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24758 &offset_size
, section_is_gnu
);
24759 if (mac_ptr
== NULL
)
24761 /* We already issued a complaint. */
24767 /* Do we at least have room for a macinfo type byte? */
24768 if (mac_ptr
>= mac_end
)
24770 /* Complaint is printed during the second pass as GDB will probably
24771 stop the first pass earlier upon finding
24772 DW_MACINFO_start_file. */
24776 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24779 /* Note that we rely on the fact that the corresponding GNU and
24780 DWARF constants are the same. */
24782 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24783 switch (macinfo_type
)
24785 /* A zero macinfo type indicates the end of the macro
24790 case DW_MACRO_define
:
24791 case DW_MACRO_undef
:
24792 /* Only skip the data by MAC_PTR. */
24794 unsigned int bytes_read
;
24796 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24797 mac_ptr
+= bytes_read
;
24798 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24799 mac_ptr
+= bytes_read
;
24803 case DW_MACRO_start_file
:
24805 unsigned int bytes_read
;
24808 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24809 mac_ptr
+= bytes_read
;
24810 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24811 mac_ptr
+= bytes_read
;
24813 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
24817 case DW_MACRO_end_file
:
24818 /* No data to skip by MAC_PTR. */
24821 case DW_MACRO_define_strp
:
24822 case DW_MACRO_undef_strp
:
24823 case DW_MACRO_define_sup
:
24824 case DW_MACRO_undef_sup
:
24826 unsigned int bytes_read
;
24828 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24829 mac_ptr
+= bytes_read
;
24830 mac_ptr
+= offset_size
;
24834 case DW_MACRO_import
:
24835 case DW_MACRO_import_sup
:
24836 /* Note that, according to the spec, a transparent include
24837 chain cannot call DW_MACRO_start_file. So, we can just
24838 skip this opcode. */
24839 mac_ptr
+= offset_size
;
24842 case DW_MACINFO_vendor_ext
:
24843 /* Only skip the data by MAC_PTR. */
24844 if (!section_is_gnu
)
24846 unsigned int bytes_read
;
24848 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24849 mac_ptr
+= bytes_read
;
24850 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24851 mac_ptr
+= bytes_read
;
24856 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24857 mac_ptr
, mac_end
, abfd
, offset_size
,
24859 if (mac_ptr
== NULL
)
24864 } while (macinfo_type
!= 0 && current_file
== NULL
);
24866 /* Second pass: Process all entries.
24868 Use the AT_COMMAND_LINE flag to determine whether we are still processing
24869 command-line macro definitions/undefinitions. This flag is unset when we
24870 reach the first DW_MACINFO_start_file entry. */
24872 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
24874 NULL
, xcalloc
, xfree
));
24875 mac_ptr
= section
->buffer
+ offset
;
24876 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
24877 *slot
= (void *) mac_ptr
;
24878 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
24879 current_file
, lh
, section
,
24880 section_is_gnu
, 0, offset_size
,
24881 include_hash
.get ());
24884 /* Check if the attribute's form is a DW_FORM_block*
24885 if so return true else false. */
24888 attr_form_is_block (const struct attribute
*attr
)
24890 return (attr
== NULL
? 0 :
24891 attr
->form
== DW_FORM_block1
24892 || attr
->form
== DW_FORM_block2
24893 || attr
->form
== DW_FORM_block4
24894 || attr
->form
== DW_FORM_block
24895 || attr
->form
== DW_FORM_exprloc
);
24898 /* Return non-zero if ATTR's value is a section offset --- classes
24899 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
24900 You may use DW_UNSND (attr) to retrieve such offsets.
24902 Section 7.5.4, "Attribute Encodings", explains that no attribute
24903 may have a value that belongs to more than one of these classes; it
24904 would be ambiguous if we did, because we use the same forms for all
24908 attr_form_is_section_offset (const struct attribute
*attr
)
24910 return (attr
->form
== DW_FORM_data4
24911 || attr
->form
== DW_FORM_data8
24912 || attr
->form
== DW_FORM_sec_offset
);
24915 /* Return non-zero if ATTR's value falls in the 'constant' class, or
24916 zero otherwise. When this function returns true, you can apply
24917 dwarf2_get_attr_constant_value to it.
24919 However, note that for some attributes you must check
24920 attr_form_is_section_offset before using this test. DW_FORM_data4
24921 and DW_FORM_data8 are members of both the constant class, and of
24922 the classes that contain offsets into other debug sections
24923 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
24924 that, if an attribute's can be either a constant or one of the
24925 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
24926 taken as section offsets, not constants.
24928 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
24929 cannot handle that. */
24932 attr_form_is_constant (const struct attribute
*attr
)
24934 switch (attr
->form
)
24936 case DW_FORM_sdata
:
24937 case DW_FORM_udata
:
24938 case DW_FORM_data1
:
24939 case DW_FORM_data2
:
24940 case DW_FORM_data4
:
24941 case DW_FORM_data8
:
24942 case DW_FORM_implicit_const
:
24950 /* DW_ADDR is always stored already as sect_offset; despite for the forms
24951 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
24954 attr_form_is_ref (const struct attribute
*attr
)
24956 switch (attr
->form
)
24958 case DW_FORM_ref_addr
:
24963 case DW_FORM_ref_udata
:
24964 case DW_FORM_GNU_ref_alt
:
24971 /* Return the .debug_loc section to use for CU.
24972 For DWO files use .debug_loc.dwo. */
24974 static struct dwarf2_section_info
*
24975 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24977 struct dwarf2_per_objfile
*dwarf2_per_objfile
24978 = cu
->per_cu
->dwarf2_per_objfile
;
24982 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24984 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24986 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
24987 : &dwarf2_per_objfile
->loc
);
24990 /* A helper function that fills in a dwarf2_loclist_baton. */
24993 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24994 struct dwarf2_loclist_baton
*baton
,
24995 const struct attribute
*attr
)
24997 struct dwarf2_per_objfile
*dwarf2_per_objfile
24998 = cu
->per_cu
->dwarf2_per_objfile
;
24999 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25001 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25003 baton
->per_cu
= cu
->per_cu
;
25004 gdb_assert (baton
->per_cu
);
25005 /* We don't know how long the location list is, but make sure we
25006 don't run off the edge of the section. */
25007 baton
->size
= section
->size
- DW_UNSND (attr
);
25008 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25009 baton
->base_address
= cu
->base_address
;
25010 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25014 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25015 struct dwarf2_cu
*cu
, int is_block
)
25017 struct dwarf2_per_objfile
*dwarf2_per_objfile
25018 = cu
->per_cu
->dwarf2_per_objfile
;
25019 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25020 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25022 if (attr_form_is_section_offset (attr
)
25023 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25024 the section. If so, fall through to the complaint in the
25026 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25028 struct dwarf2_loclist_baton
*baton
;
25030 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25032 fill_in_loclist_baton (cu
, baton
, attr
);
25034 if (cu
->base_known
== 0)
25035 complaint (_("Location list used without "
25036 "specifying the CU base address."));
25038 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25039 ? dwarf2_loclist_block_index
25040 : dwarf2_loclist_index
);
25041 SYMBOL_LOCATION_BATON (sym
) = baton
;
25045 struct dwarf2_locexpr_baton
*baton
;
25047 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25048 baton
->per_cu
= cu
->per_cu
;
25049 gdb_assert (baton
->per_cu
);
25051 if (attr_form_is_block (attr
))
25053 /* Note that we're just copying the block's data pointer
25054 here, not the actual data. We're still pointing into the
25055 info_buffer for SYM's objfile; right now we never release
25056 that buffer, but when we do clean up properly this may
25058 baton
->size
= DW_BLOCK (attr
)->size
;
25059 baton
->data
= DW_BLOCK (attr
)->data
;
25063 dwarf2_invalid_attrib_class_complaint ("location description",
25064 SYMBOL_NATURAL_NAME (sym
));
25068 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25069 ? dwarf2_locexpr_block_index
25070 : dwarf2_locexpr_index
);
25071 SYMBOL_LOCATION_BATON (sym
) = baton
;
25075 /* Return the OBJFILE associated with the compilation unit CU. If CU
25076 came from a separate debuginfo file, then the master objfile is
25080 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25082 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25084 /* Return the master objfile, so that we can report and look up the
25085 correct file containing this variable. */
25086 if (objfile
->separate_debug_objfile_backlink
)
25087 objfile
= objfile
->separate_debug_objfile_backlink
;
25092 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25093 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25094 CU_HEADERP first. */
25096 static const struct comp_unit_head
*
25097 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25098 struct dwarf2_per_cu_data
*per_cu
)
25100 const gdb_byte
*info_ptr
;
25103 return &per_cu
->cu
->header
;
25105 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25107 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25108 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25109 rcuh_kind::COMPILE
);
25114 /* Return the address size given in the compilation unit header for CU. */
25117 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25119 struct comp_unit_head cu_header_local
;
25120 const struct comp_unit_head
*cu_headerp
;
25122 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25124 return cu_headerp
->addr_size
;
25127 /* Return the offset size given in the compilation unit header for CU. */
25130 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25132 struct comp_unit_head cu_header_local
;
25133 const struct comp_unit_head
*cu_headerp
;
25135 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25137 return cu_headerp
->offset_size
;
25140 /* See its dwarf2loc.h declaration. */
25143 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25145 struct comp_unit_head cu_header_local
;
25146 const struct comp_unit_head
*cu_headerp
;
25148 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25150 if (cu_headerp
->version
== 2)
25151 return cu_headerp
->addr_size
;
25153 return cu_headerp
->offset_size
;
25156 /* Return the text offset of the CU. The returned offset comes from
25157 this CU's objfile. If this objfile came from a separate debuginfo
25158 file, then the offset may be different from the corresponding
25159 offset in the parent objfile. */
25162 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25164 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25166 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25169 /* Return DWARF version number of PER_CU. */
25172 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25174 return per_cu
->dwarf_version
;
25177 /* Locate the .debug_info compilation unit from CU's objfile which contains
25178 the DIE at OFFSET. Raises an error on failure. */
25180 static struct dwarf2_per_cu_data
*
25181 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25182 unsigned int offset_in_dwz
,
25183 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25185 struct dwarf2_per_cu_data
*this_cu
;
25189 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25192 struct dwarf2_per_cu_data
*mid_cu
;
25193 int mid
= low
+ (high
- low
) / 2;
25195 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25196 if (mid_cu
->is_dwz
> offset_in_dwz
25197 || (mid_cu
->is_dwz
== offset_in_dwz
25198 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25203 gdb_assert (low
== high
);
25204 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25205 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25207 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25208 error (_("Dwarf Error: could not find partial DIE containing "
25209 "offset %s [in module %s]"),
25210 sect_offset_str (sect_off
),
25211 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25213 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25215 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25219 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25220 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25221 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25222 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25227 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25229 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25230 : per_cu (per_cu_
),
25232 has_loclist (false),
25233 checked_producer (false),
25234 producer_is_gxx_lt_4_6 (false),
25235 producer_is_gcc_lt_4_3 (false),
25236 producer_is_icc (false),
25237 producer_is_icc_lt_14 (false),
25238 producer_is_codewarrior (false),
25239 processing_has_namespace_info (false)
25244 /* Destroy a dwarf2_cu. */
25246 dwarf2_cu::~dwarf2_cu ()
25251 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25254 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25255 enum language pretend_language
)
25257 struct attribute
*attr
;
25259 /* Set the language we're debugging. */
25260 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25262 set_cu_language (DW_UNSND (attr
), cu
);
25265 cu
->language
= pretend_language
;
25266 cu
->language_defn
= language_def (cu
->language
);
25269 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25272 /* Increase the age counter on each cached compilation unit, and free
25273 any that are too old. */
25276 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25278 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25280 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25281 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25282 while (per_cu
!= NULL
)
25284 per_cu
->cu
->last_used
++;
25285 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25286 dwarf2_mark (per_cu
->cu
);
25287 per_cu
= per_cu
->cu
->read_in_chain
;
25290 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25291 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25292 while (per_cu
!= NULL
)
25294 struct dwarf2_per_cu_data
*next_cu
;
25296 next_cu
= per_cu
->cu
->read_in_chain
;
25298 if (!per_cu
->cu
->mark
)
25301 *last_chain
= next_cu
;
25304 last_chain
= &per_cu
->cu
->read_in_chain
;
25310 /* Remove a single compilation unit from the cache. */
25313 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25315 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25316 struct dwarf2_per_objfile
*dwarf2_per_objfile
25317 = target_per_cu
->dwarf2_per_objfile
;
25319 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25320 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25321 while (per_cu
!= NULL
)
25323 struct dwarf2_per_cu_data
*next_cu
;
25325 next_cu
= per_cu
->cu
->read_in_chain
;
25327 if (per_cu
== target_per_cu
)
25331 *last_chain
= next_cu
;
25335 last_chain
= &per_cu
->cu
->read_in_chain
;
25341 /* Cleanup function for the dwarf2_per_objfile data. */
25344 dwarf2_free_objfile (struct objfile
*objfile
, void *datum
)
25346 struct dwarf2_per_objfile
*dwarf2_per_objfile
25347 = static_cast<struct dwarf2_per_objfile
*> (datum
);
25349 delete dwarf2_per_objfile
;
25352 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25353 We store these in a hash table separate from the DIEs, and preserve them
25354 when the DIEs are flushed out of cache.
25356 The CU "per_cu" pointer is needed because offset alone is not enough to
25357 uniquely identify the type. A file may have multiple .debug_types sections,
25358 or the type may come from a DWO file. Furthermore, while it's more logical
25359 to use per_cu->section+offset, with Fission the section with the data is in
25360 the DWO file but we don't know that section at the point we need it.
25361 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25362 because we can enter the lookup routine, get_die_type_at_offset, from
25363 outside this file, and thus won't necessarily have PER_CU->cu.
25364 Fortunately, PER_CU is stable for the life of the objfile. */
25366 struct dwarf2_per_cu_offset_and_type
25368 const struct dwarf2_per_cu_data
*per_cu
;
25369 sect_offset sect_off
;
25373 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25376 per_cu_offset_and_type_hash (const void *item
)
25378 const struct dwarf2_per_cu_offset_and_type
*ofs
25379 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25381 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25384 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25387 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25389 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25390 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25391 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25392 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25394 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25395 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25398 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25399 table if necessary. For convenience, return TYPE.
25401 The DIEs reading must have careful ordering to:
25402 * Not cause infite loops trying to read in DIEs as a prerequisite for
25403 reading current DIE.
25404 * Not trying to dereference contents of still incompletely read in types
25405 while reading in other DIEs.
25406 * Enable referencing still incompletely read in types just by a pointer to
25407 the type without accessing its fields.
25409 Therefore caller should follow these rules:
25410 * Try to fetch any prerequisite types we may need to build this DIE type
25411 before building the type and calling set_die_type.
25412 * After building type call set_die_type for current DIE as soon as
25413 possible before fetching more types to complete the current type.
25414 * Make the type as complete as possible before fetching more types. */
25416 static struct type
*
25417 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25419 struct dwarf2_per_objfile
*dwarf2_per_objfile
25420 = cu
->per_cu
->dwarf2_per_objfile
;
25421 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25422 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25423 struct attribute
*attr
;
25424 struct dynamic_prop prop
;
25426 /* For Ada types, make sure that the gnat-specific data is always
25427 initialized (if not already set). There are a few types where
25428 we should not be doing so, because the type-specific area is
25429 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25430 where the type-specific area is used to store the floatformat).
25431 But this is not a problem, because the gnat-specific information
25432 is actually not needed for these types. */
25433 if (need_gnat_info (cu
)
25434 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25435 && TYPE_CODE (type
) != TYPE_CODE_FLT
25436 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25437 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25438 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25439 && !HAVE_GNAT_AUX_INFO (type
))
25440 INIT_GNAT_SPECIFIC (type
);
25442 /* Read DW_AT_allocated and set in type. */
25443 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25444 if (attr_form_is_block (attr
))
25446 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25447 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25449 else if (attr
!= NULL
)
25451 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25452 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25453 sect_offset_str (die
->sect_off
));
25456 /* Read DW_AT_associated and set in type. */
25457 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25458 if (attr_form_is_block (attr
))
25460 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25461 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25463 else if (attr
!= NULL
)
25465 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25466 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25467 sect_offset_str (die
->sect_off
));
25470 /* Read DW_AT_data_location and set in type. */
25471 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25472 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25473 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25475 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25477 dwarf2_per_objfile
->die_type_hash
=
25478 htab_create_alloc_ex (127,
25479 per_cu_offset_and_type_hash
,
25480 per_cu_offset_and_type_eq
,
25482 &objfile
->objfile_obstack
,
25483 hashtab_obstack_allocate
,
25484 dummy_obstack_deallocate
);
25487 ofs
.per_cu
= cu
->per_cu
;
25488 ofs
.sect_off
= die
->sect_off
;
25490 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25491 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25493 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25494 sect_offset_str (die
->sect_off
));
25495 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25496 struct dwarf2_per_cu_offset_and_type
);
25501 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25502 or return NULL if the die does not have a saved type. */
25504 static struct type
*
25505 get_die_type_at_offset (sect_offset sect_off
,
25506 struct dwarf2_per_cu_data
*per_cu
)
25508 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25509 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25511 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25514 ofs
.per_cu
= per_cu
;
25515 ofs
.sect_off
= sect_off
;
25516 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25517 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25524 /* Look up the type for DIE in CU in die_type_hash,
25525 or return NULL if DIE does not have a saved type. */
25527 static struct type
*
25528 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25530 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25533 /* Add a dependence relationship from CU to REF_PER_CU. */
25536 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25537 struct dwarf2_per_cu_data
*ref_per_cu
)
25541 if (cu
->dependencies
== NULL
)
25543 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25544 NULL
, &cu
->comp_unit_obstack
,
25545 hashtab_obstack_allocate
,
25546 dummy_obstack_deallocate
);
25548 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25550 *slot
= ref_per_cu
;
25553 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25554 Set the mark field in every compilation unit in the
25555 cache that we must keep because we are keeping CU. */
25558 dwarf2_mark_helper (void **slot
, void *data
)
25560 struct dwarf2_per_cu_data
*per_cu
;
25562 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25564 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25565 reading of the chain. As such dependencies remain valid it is not much
25566 useful to track and undo them during QUIT cleanups. */
25567 if (per_cu
->cu
== NULL
)
25570 if (per_cu
->cu
->mark
)
25572 per_cu
->cu
->mark
= true;
25574 if (per_cu
->cu
->dependencies
!= NULL
)
25575 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25580 /* Set the mark field in CU and in every other compilation unit in the
25581 cache that we must keep because we are keeping CU. */
25584 dwarf2_mark (struct dwarf2_cu
*cu
)
25589 if (cu
->dependencies
!= NULL
)
25590 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25594 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25598 per_cu
->cu
->mark
= false;
25599 per_cu
= per_cu
->cu
->read_in_chain
;
25603 /* Trivial hash function for partial_die_info: the hash value of a DIE
25604 is its offset in .debug_info for this objfile. */
25607 partial_die_hash (const void *item
)
25609 const struct partial_die_info
*part_die
25610 = (const struct partial_die_info
*) item
;
25612 return to_underlying (part_die
->sect_off
);
25615 /* Trivial comparison function for partial_die_info structures: two DIEs
25616 are equal if they have the same offset. */
25619 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25621 const struct partial_die_info
*part_die_lhs
25622 = (const struct partial_die_info
*) item_lhs
;
25623 const struct partial_die_info
*part_die_rhs
25624 = (const struct partial_die_info
*) item_rhs
;
25626 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25629 struct cmd_list_element
*set_dwarf_cmdlist
;
25630 struct cmd_list_element
*show_dwarf_cmdlist
;
25633 set_dwarf_cmd (const char *args
, int from_tty
)
25635 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25640 show_dwarf_cmd (const char *args
, int from_tty
)
25642 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25645 int dwarf_always_disassemble
;
25648 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
25649 struct cmd_list_element
*c
, const char *value
)
25651 fprintf_filtered (file
,
25652 _("Whether to always disassemble "
25653 "DWARF expressions is %s.\n"),
25658 show_check_physname (struct ui_file
*file
, int from_tty
,
25659 struct cmd_list_element
*c
, const char *value
)
25661 fprintf_filtered (file
,
25662 _("Whether to check \"physname\" is %s.\n"),
25667 _initialize_dwarf2_read (void)
25669 dwarf2_objfile_data_key
25670 = register_objfile_data_with_cleanup (nullptr, dwarf2_free_objfile
);
25672 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
25673 Set DWARF specific variables.\n\
25674 Configure DWARF variables such as the cache size"),
25675 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25676 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25678 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
25679 Show DWARF specific variables\n\
25680 Show DWARF variables such as the cache size"),
25681 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25682 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25684 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25685 &dwarf_max_cache_age
, _("\
25686 Set the upper bound on the age of cached DWARF compilation units."), _("\
25687 Show the upper bound on the age of cached DWARF compilation units."), _("\
25688 A higher limit means that cached compilation units will be stored\n\
25689 in memory longer, and more total memory will be used. Zero disables\n\
25690 caching, which can slow down startup."),
25692 show_dwarf_max_cache_age
,
25693 &set_dwarf_cmdlist
,
25694 &show_dwarf_cmdlist
);
25696 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
25697 &dwarf_always_disassemble
, _("\
25698 Set whether `info address' always disassembles DWARF expressions."), _("\
25699 Show whether `info address' always disassembles DWARF expressions."), _("\
25700 When enabled, DWARF expressions are always printed in an assembly-like\n\
25701 syntax. When disabled, expressions will be printed in a more\n\
25702 conversational style, when possible."),
25704 show_dwarf_always_disassemble
,
25705 &set_dwarf_cmdlist
,
25706 &show_dwarf_cmdlist
);
25708 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25709 Set debugging of the DWARF reader."), _("\
25710 Show debugging of the DWARF reader."), _("\
25711 When enabled (non-zero), debugging messages are printed during DWARF\n\
25712 reading and symtab expansion. A value of 1 (one) provides basic\n\
25713 information. A value greater than 1 provides more verbose information."),
25716 &setdebuglist
, &showdebuglist
);
25718 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25719 Set debugging of the DWARF DIE reader."), _("\
25720 Show debugging of the DWARF DIE reader."), _("\
25721 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25722 The value is the maximum depth to print."),
25725 &setdebuglist
, &showdebuglist
);
25727 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25728 Set debugging of the dwarf line reader."), _("\
25729 Show debugging of the dwarf line reader."), _("\
25730 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25731 A value of 1 (one) provides basic information.\n\
25732 A value greater than 1 provides more verbose information."),
25735 &setdebuglist
, &showdebuglist
);
25737 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25738 Set cross-checking of \"physname\" code against demangler."), _("\
25739 Show cross-checking of \"physname\" code against demangler."), _("\
25740 When enabled, GDB's internal \"physname\" code is checked against\n\
25742 NULL
, show_check_physname
,
25743 &setdebuglist
, &showdebuglist
);
25745 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25746 no_class
, &use_deprecated_index_sections
, _("\
25747 Set whether to use deprecated gdb_index sections."), _("\
25748 Show whether to use deprecated gdb_index sections."), _("\
25749 When enabled, deprecated .gdb_index sections are used anyway.\n\
25750 Normally they are ignored either because of a missing feature or\n\
25751 performance issue.\n\
25752 Warning: This option must be enabled before gdb reads the file."),
25755 &setlist
, &showlist
);
25757 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25758 &dwarf2_locexpr_funcs
);
25759 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25760 &dwarf2_loclist_funcs
);
25762 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25763 &dwarf2_block_frame_base_locexpr_funcs
);
25764 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25765 &dwarf2_block_frame_base_loclist_funcs
);
25768 selftests::register_test ("dw2_expand_symtabs_matching",
25769 selftests::dw2_expand_symtabs_matching::run_test
);